|
Hi,
I am writing an application that solves sudoku puzzles (you can learn sudoku at www.websudoku.com if you dont already know it). Although it works, there are a couple of things I would like to do and dont know how to.
1. I have 81 text boxes for each cell in the 9x9 puzzle. SharpDevelop (www.icsharpcode.com) generated constructer code for each one (2000 lines!) Is there any way, since the code is mostly identical for all of them, I can define them all at once, in a loop? It would save a lot of space, and make the code neater.
this.cell32.BackColor = System.Drawing.Color.PaleGreen;<br />
this.cell32.DetectUrls = false;<br />
this.cell32.Font = new System.Drawing.Font("Courier New", 6.65F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));<br />
this.cell32.Location = new System.Drawing.Point(44, 128);<br />
this.cell32.MaxLength = 1;<br />
this.cell32.Name = "cell32";<br />
this.cell32.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;<br />
this.cell32.Size = new System.Drawing.Size(40, 40);<br />
this.cell32.TabIndex = 29;<br />
this.cell32.Text = " 1 2 3\n 4 5 6\n 7 8 9";<br />
this.cell32.WordWrap = false;<br />
this.cell32.Leave += new System.EventHandler(this.CellLeave);<br />
this.cell32.TextChanged += new System.EventHandler(this.CellTextChanged);<br />
this.cell32.Enter += new System.EventHandler(this.CellEnter);
Obviously, the cells' Names are different, as are their Locations, and their TabIndexs
2. This is probably a stupid question. Every time I run the program, the command line appears. This does not need to happen, right? Why does it, and how can I make it not happen? I've made other apps which dont do it.
You can get the app and the source (if youre really that interested) at...
http://wilmington-web.net/sudoku/
Thanks for all your (prompt) help.
I have gone to find myself. If I come back before I return, please keep me here.
|
|
|
|
|
couldn't you do something like (just pseudocode)
int i = 1;
foreach(control in this.controls)
{
if(ctl.GetType() == "textbox")
{
ctl.Name = "cell"+i.ToString();
ctl.TabIndex = i;
i++;
}
}
BugReporter[^]
BlackDice
|
|
|
|
|
#coder05 wrote: I can define them all at once, in a loop?
Yes, you can create and add textboxes just like any .NET object. You can write it like
class SudokuForm : Form
{
TextBox[] textBoxArray = new TextBox[81];
public SudokuForm()
{
for (int i = 0; i<textBoxArray.Length; ++i)
{
textBoxArray[i] = new TextBox;
textBoxArray[i].Name = "cell" + i.ToString();
textBoxArray[i].Location = ...
}
}
}
The toughest part is calculating the location. If each textbox's size is fixed, you can simply use the loop index to calculate the offset from the top left corner of the form to determine the location.
#coder05 wrote: Every time I run the program, the command line appears.
Looks like your project is setup to generate a command line app. I've never used SharpDevelop, but from this[^] page (fourth picture from the top), try looking for a winexe option(or something similar) in the "Compile Target" combobox.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks (I was stupid but next time ill be able to do it) a lot
Amazingly fast help here!
I really appreciate it.
bigiorno
|
|
|
|
|
Hi all,
Just registered today for CodeProject.
I do have a question:
Today at school, a fellow student learned me how to add things to the toolbox, like Windows Media Player.
Put that to my form.
But, I also want a Quicktime player to add to my form.
I searched in the COM compounds, and found "Quicktime Object", I do put it in my form, but what next?
WMP showed standard an play stop etc button (in the window itself, thus not the form), but Quicktime doesn't have that.
So what do I need to do to run an Quicktime file?
And I also want a message to appear when successfully saved (a file) on the system.
Like: (filename)successfully stored at (location (yes I know to do that by typing: @ .... )) , but ONLY after and if the file is saved.
So an short summary of my questions:
* How do I play files with the Quicktime plugin?
* How do I make a message appear when a file is saved successfully?
Well hope to get an answer soon :->.
Greetz
ChevyVanDude G30
|
|
|
|
|
...goes to me.
I accidentally Shift/Del eted my form's .resx file. Is there any way to recreate it or am I doomed to rebuild my intricate form my hand?
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
- Delete the
.resx file from the Solution Explorer.
- Close and re-open the project.
- View the form in the Designer.
- Add a control to the form - this regens the
.resx file.
- Rebuild the project.
- Remember to perform bootstrap caffeination before writing code.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Usually, VS.net is smart enough to recognize that the class is of type form/control and it regenerates the RESX file. In the past, I've been able to import the form (just the .CS file only) by adding it to the project. You may want to exclude the file and reinclude it. Press Shift+F7 (and not Shift+delete ) on the CS file to switch to designer!
- Malhar
|
|
|
|
|
Yes, it seems to regen the file when you attempt to modify the form.
I equated the .resx to VC++'s .res file (i.e. cached resources) and deleted it because I wanted to modify several button .bmp s and didn't want to have to reselect them as my toolbar buttons' images. I (foolishly) assumed rebuilding the project would regen the file.
Thanks,
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
I still fail to see the point of a resx file except for embeded resources (but direct embedding is better anyways) and for i18n. Normally they just contain a bunch of needless overhead.
|
|
|
|
|
hi all
How can i access soap protocal over the internet
Let say i am using web service
I want someone to help me
I need pdfs and code sample or site
-- modified at 11:45 Monday 20th February, 2006
|
|
|
|
|
Hello everyone:
I need to use a collection technique but I am not sure which one will be best for my situation.
I have relational data that I need to store; I have a table that has Keys and another table has values, each KEY may contain mulitple values. Both KEY and VALUE are string, can you suggest me which (NameValueCollection or HashTable) I should use?
Thanks a lot.
|
|
|
|
|
The tables that you are talking about, are they database tables?
In what way can the key contain multiple values?
---
b { font-weight: normal; }
|
|
|
|
|
I'm a newbie so take my advice with a grain of salt, but it seems like NameValueCollection was designed with exactly that in mind. The alternative would be a HashTable with arrays of strings for the values, but NameValueCollection takes care of some of the dirty work there -- although it does get a little messy when you only want to access one of the many values stored under a key.
That will be $0.02 please. Cash or charge?
|
|
|
|
|
They are both the same.
For the value bit you simple need to use another Hashtable or ArrayList. Seems tricky at 1st due to the extra casting, but once u write a few of them its like writing a for loop :p
|
|
|
|
|
Ok,
Here's a design question that has me stumped. Let's say I have a windows forms application that is sitting on top of a business layer, that sits on top of a database. Now, let's say that a particular object may be accessed by multiple views in the system at the same time. Instead of creating a new instance of the object for each view (which means that they will get out of sync), I'd like to have a single instance of the object be used in both places. This is easily done because my business object controller class (that actually instantiates the objects) can keep a lookup table that tracks instantiated objects and indexes them by their unique id (the one from the database). However, this breaks down over time, as the business object controller class never releases the reference to the object (which may be quite large in some cases). Basically, what I need is some sort of reference counting scheme that will actually work.
I suspect that something like this is probably already built into the framework, but I haven't found it yet. Any ideas? Or am I approaching the design from the wrong angle...?
Thanks,
Will Gant
|
|
|
|
|
gantww wrote: Instead of creating a new instance of the object for each view (which means that they will get out of sync)
Why can't they get out of sync? Are you planning to keep the views in sync at all times? So for example, when view 1 changes, view 2, 3, etc. will immediately know about it and refresh themselves. Is that the plan?
I just want to get an idea of how imperative it is for you to keep everything syncronized. Often times we end up spending a lot of time solving a problem that we later realize didn't really need solving.
Regards,
Alvaro
... now you see that evil will always triumph, because good is dumb. - Dark Helmet
|
|
|
|
|
It is imperative to keep everything synchronized, but it may be possible in many cases for me to get away with simple refreshes when the focus changes. However, there are some cases when there may be sidebars or toolbars out that are accessing the same information. They may not get focus, but they still need to be updated to keep the user interface current. If I can make sure both views are actually pointing to the same object, keeping them in sync can easily be done via simple events.
I guess the real issue is figuring out some way to manage the lifecycle of the objects. It would be pretty easy to keep a running list of objects that I have instantiated (since I'm using a factory pattern) and simply return a reference to them if a similar request is made. I could possibly keep the reference to the view that requested them as well. When the object being referenced by the view changes (or the view is disposed), it could inform the class factory that it no longer needs the object. If the object isn't being referenced elsewhere, then it can be released.
The other option would be for the business object itself to allow the registration of objects that are "interested" in it. The object would fire events when a view was added or removed. The individual views wouldn't care about these events, but the class factory for the object would use them to determine whether or not to release the reference to the object. I don't particularly care for this idea, since it puts some lifecycle management logic into the object itself, while the rest of it remains in the controller/factory class.
Any thoughts?
|
|
|
|
|
I'd go with your first idea, which I would implement something like this:
1. Create an interface, such as:
interface IMyObjectUser
{
event EventHandler Disposing;
} 2. I'd have all my users (Views, in your case) implement this interface to raise the Disposing event whenever they call Dispose.
3. I'd pass an IMyObjectUser object to the constructor of your object (or the factory, in your case). In there, I would subscribe to the Disposing event and then store the object inside an ArrayList.
4. Inside the Disposing handler I would locate the object (View) inside the ArrayList and remove it from the list. If the list's Count reaches 0, I would know that no one else is referencing my object and proceed accordingly.
Regards,
Alvaro
... now you see that evil will always triumph, because good is dumb. - Dark Helmet
|
|
|
|
|
Cool. That seems to work well in my proof-of-concept app. Now I just have to move the idea into the real one.
Thanks,
Will
|
|
|
|
|
hi all !
i want to when i press "Esc" key , myForm is closed . how can it possible ?
thanks !
s_mostafa_h
|
|
|
|
|
Subscribe to the Form.KeyUp event (Judah is watching me ):
this.KeyUp += new KeyEventHandler(this.OnKeyUp);
and add this code:
private void OnKeyUp(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Escape)
Close();
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: Judah is watching me
With an eagle's eye!
|
|
|
|
|
Hunh?!? Me also read thread. Me come from Delphi background. Pound rock all day. Am tired. What am 'subscribe to the Form.KeyUp event'? How subscribe?
IOW, I've got a Form1 and an AboutBox1 form in my learning project. The AboutBox1 form has a very visible Close button. In Delphi I'd just stick this line of code in the Close button's Click event:
Self.Close;
What's all this subscribe nonsense?
Derek
|
|
|
|
|
If your form has a Close or Cancel button, you can simply set the form's CancelButton property to that control. You can do it via the Designer.
Regards,
Alvaro
... now you see that evil will always triumph, because good is dumb. - Dark Helmet
|
|
|
|