|
I have a form that calls a dialogbox, Type, of the class dlgType. In the dialog box I have three radio buttons to select an equipment type, and a private variable - Selected - to contain the latest radio button selection. When the user clicks OK, the button handler assigns the value of Selected to a property called Choice. That's when the goofiness happens. Up to that point, Selected contains the correct value. But upon assigning Choice its value, the set function associated with Choice is called over and over again, causing a stack overflow error. I've watched it happen by stepping through the debug process (can I buy a replacement F11 key? I'm wearing this one out.) from the beginning of the code. The error definitely begins when the OK button is clicked and the set function is called. Can anyone suggest why this is happenning? And, by the way, I've tried it without the this prefix on Choice, too; same result. Here's the dialog code:
namespace SubMaint<br />
{<br />
public partial class dlgType : Form<br />
{<br />
public dlgType()<br />
{<br />
InitializeComponent();<br />
<br />
}<br />
private int Selected = 0;<br />
public int Choice<br />
{<br />
get {return Choice;}<br />
set {Choice = value;}<br />
<br />
}<br />
<br />
<br />
private void rbTransformer_CheckedChanged(object sender, EventArgs e)<br />
{<br />
if (rbTransformer.Checked == true)<br />
{<br />
Selected = 1;<br />
}<br />
}<br />
<br />
private void rbRegulator_CheckedChanged(object sender, EventArgs e)<br />
{<br />
if (rbRegulator.Checked == true)<br />
{<br />
Selected = 2;<br />
}<br />
}<br />
<br />
private void rbRecloser_CheckedChanged(object sender, EventArgs e)<br />
{<br />
if (rbRecloser.Checked == true)<br />
{<br />
Selected = 3;<br />
}<br />
<br />
}<br />
<br />
private void btnOK_Click(object sender, EventArgs e)<br />
{<br />
if (Selected > 0)<br />
this.Choice = Selected;<br />
<br />
}<br />
}<br />
}
Any assistance will probably save me some hair...
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Your problem is here:
public int Choice
{
get {return Choice;}
set {Choice = value;}
} In the set block, you are taking the assigned value, and setting to Choice, which calls the same bit of code again. A property isn't a way of storing data, it is a way of accessing data that is stored privately in the object. You need to add a backing storage variable for the data. Like this:
private int _choice;
public int Choice
{
get
{
return _choice;
}
set
{
_choice = value;
}
}
Here the private variable _choice is used to store the data. The public property Choice is used to get & set that data.
(If you are using VS2008, there is a kind of shortcut property. You can just write this:
public int Choice
{
get;
set;
}
and it will automatically manage the backing variable for the data storage itself. You still need a backing variable, but in this case it is basically a visual studio trick, when it compiles the code it will just create the backing variable for you. Personally, I don't like this though, I prefer to declare it all in full, I think it's clearer.)
Simon
|
|
|
|
|
That did the trick... Thanks!
Now to figure out how to get the value back to the form before the dialog closes...
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
No prob.
(You don't have to. Just use the property to get it after the dialog has been closed:
dlgType dialog = new dlgType();
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
MessageBox.Show(dialog.Choice);
}
)
Good luck.
Simon
|
|
|
|
|
That's essentially what I'm doing, but I'm getting an odd display. I think it's a casting problem; I'm returning an int, and using a message box to display the selected value for testing purposes. I thought I could cast the int with either (char)int or (string)int, but apparently that doesn't work. The display has a cute little square box where the digit ought to be. When I get home tonight I'm planning to play with Convert.ToString() instead, though I can't see why it should work when the more basic methods don't work. It's not really essential, though, as the message box won't be part of the program. So long as the int is being returned correctly, I'm happy.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Just call .ToString() on the int object. That should do the job.
Simon
|
|
|
|
|
That worked very nicely - Thanks, again!
Of course, being an idiot I forgot the () at first and got the strangest error... Ah, well, it gave me time to suck down a starter beer and get my head out of work mode and into play mode.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
i saw that project here in codeproject, but i was in other computer and i forget the project name
and i realy like to see/explore that, its very interesting
that project have that image: http://screencast.com/t/S8Ygu5kw3
of course image looks like an windows Form app with default windows vista forms look
if someone can help...
thanks
|
|
|
|
|
We are all users of this site, we have as much chance of finding that article as you do.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
i already try search but i cannot found it
i try realy hard search for that but no results
if anyone can still helpme, i belive more guys was saw that project here
|
|
|
|
|
Dear All,
Iam new to c# window application and also for COM.I have a COM component
which is developed in Visual Basic.Now i want to use this component into
my c# window application.How can i register and use.The COM is in the form
of EXE not in the form of DLL.Please help me out on this.
Thanks & Regards
Veeresh
i want to join this group
|
|
|
|
|
DO NOT CROSSPOST the same question in multiple forums. You spammed about half the forums on the site...
|
|
|
|
|
Dave Kreskowiak wrote: same question in multiple forums
Good God The OP obviously is clueless.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I have a form that launches a dialog when the Add button is clicked. The dialog contains three radio buttons. The dialog has a local variable called "Choice" that is correctly set when the user clicks a radio button; I've verified that by displaying a MessageBox showing the value of Choice after each click. The parent form has a variable called EquipType that is intended to receive the value of Choice from the dialog when the user clicks OK. What I can't find is a way of getting that value back to the parent form. This must be too simple to justify an article or an entry in MSDN, as I've searched both extensively. Can someone show an old idiot how this simple process works?
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
2 ways
Create a property (Choice) on the dialog and instead of closing the dialog from the parent just hide it, have the parent then extract the choice from the dialog property.
You can also use a delegate do the cross referencing but I don't use it. There are some articles here somewhere. I beleive the delegate method is the more "elegant" way to do it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: instead of closing the dialog from the parent just hide it
Why not closing it? Whether you close it or just hide it, you can access the property on the form in both scenarios:
MyDialog dialog = new MyDialog();
dialog.ShowModal();
var someVariable = dialog.Choice;
-^-^-^-^-^-^-^-
no risk no funk
|
|
|
|
|
Badly worded, I should have said - instead of closing the dialog you should hide it and close if from the parent form after extracting the information.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: nstead of closing the dialog you should hide it and close if from the parent form after extracting the information.
NNONONONONONONnoonononononooooooo!
If you close it, the OBJECT that is the dialog STILL EXISTS as you (the mainform) still has a reference to it - so you can access any public methods or properties of the dialog object from the main form - even though the dialog box is no longer visible and has been closed.
ShowDialog() shows the form and waits until it is closed - so hiding it from the parent doesn't make sense - and hiding it from within the dialog itself is a waste of time, as you have to close it to return to the parent form - that's sort of the definition of a dialog!
IOW closed does NOT equal disposed.
Life is like a pubic hair on the toilet seat...
...sometimes, you just get pissed off.
.\\axxx
(That's an 'M')
|
|
|
|
|
hi friends i want to know how to create session in windowApplication and also how to maintain single language in session(English,Arabic(it's a multilingual Application))
help me.
Advance Thanx,
Arun.R
modified on Monday, November 17, 2008 1:16 AM
|
|
|
|
|
If you're talking about a Session, like you see in an ASP.NET application, there's no such thing. Perhaps if you described what you're really trying to accomplish with this, we can help.
|
|
|
|
|
hi friends,
Now i am creating multilingual .net window apllication its in two languages English and Arabic,It's in English no problem all the controls in left side it's in Arabic all the controls i want right side eg.[English] label control leftside ,text box right side [Arabic] textbox leftside labels right side in single form.and also i want to type anything in text box all the text will comes in right to left indent.and i want to know how to use localization technique in session.and also i want to know how all messages and interactions with user should be integrated with bilingual support (error messages, information messages, etc.).please help me friends.
Arun
|
|
|
|
|
For positioning controls you can change the location property for each to swap sides of the form on which they appear. For simplicity, I'd just make two different forms, one for each language, but I'm still a dummy at this. It can probably be done just as easily at run time. To make the text run right-to-left, you can change the Right To Left property of the label and textbox, according to the label on the box here. I can't test that, since I don't know any other languages, but the containing form has properties to select the language and to enable localization. When I try Right To Left = True, all it does is align my English text with the right edge of the label. But I suspect that if I set the Form property Language to Arabic, and Localization to True, the result would be exactly what you seek. Give it a try.
I'd try it for you, but 1) it took me all day to make this dialog box look right and I don't want to mess with it, and 2) I wouldn't know by looking at it whether Arabic was RTL or LTR.
Good luck!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Thanx a Lot Mr.Roger Wright
|
|
|
|
|
Hi,
i want to display a WinHelp (.hlp) file within windows forms. If anyone know please help me.
Advance Thanks
S.Selvaraj
|
|
|
|
|
WinHelp (.hlp) is deprecated with no future support planned in Windows, nor is there any support for it in the .NET Framework BCL. I highly suggest using .CHM instead (compiled HTML) instead. Google results for "vb.net help file[^]".
|
|
|
|