Click here to Skip to main content
15,892,746 members
Home / Discussions / C#
   

C#

 
GeneralRe: WinForms keeps closing my dialogs !!! Pin
Christian Graus5-Jun-05 12:51
protectorChristian Graus5-Jun-05 12:51 
GeneralRe: WinForms keeps closing my dialogs !!! Pin
DavidNohejl5-Jun-05 13:46
DavidNohejl5-Jun-05 13:46 
GeneralRe: WinForms keeps closing my dialogs !!! Pin
Judah Gabriel Himango5-Jun-05 13:43
sponsorJudah Gabriel Himango5-Jun-05 13:43 
GeneralRe: WinForms keeps closing my dialogs !!! Pin
Christian Graus5-Jun-05 13:46
protectorChristian Graus5-Jun-05 13:46 
GeneralRe: WinForms keeps closing my dialogs !!! Pin
DavidNohejl5-Jun-05 13:47
DavidNohejl5-Jun-05 13:47 
GeneralRe: WinForms keeps closing my dialogs !!! Pin
Scott Serl5-Jun-05 14:49
Scott Serl5-Jun-05 14:49 
GeneralRe: WinForms keeps closing my dialogs !!! Pin
Christian Graus5-Jun-05 15:16
protectorChristian Graus5-Jun-05 15:16 
GeneralRe: WinForms keeps closing my dialogs !!! Pin
Ashok Dhamija5-Jun-05 18:34
Ashok Dhamija5-Jun-05 18:34 
Please see documentation for Button.DialogResult property in MSDN. It is mentioned that:

If the value of this property is set to anything other than DialogResult.None, and if the parent form was displayed through the ShowDialog method, clicking the button closes the parent form without your having to hook up any events. The form's DialogResult property is then set to the DialogResult of the button when the button is clicked.

Therefore, it is clear that for the button labeled “OK” in your dialog box, while the Text property could be set to “OK” string, but if the “DialogResult” property of this button is also set to “OK”, then clicking this button will automatically close the parent dialog box without your having to hook up any events.

So, the solution to your problem is that you must NOT set the DialogResult property of the OK button (say btnOK) to “OK”, while the Text property of this button might still continue to be “OK” to keep it visible as such to the user. You may set the DialogResult property of this button to “None”. Now, in the click handler of the said OK button, you can do your processing as desired. But please remember to close the form yourself in the code as per your scheme.

I may also mention that as per the documentation, the AcceptButton/CancelButton properties are irrelevant for this purpose because they are useful to allow "Enter" or "Escape" keys instead of the mouse-clicks on OK and Cancel buttons respectively. What is of relevance here is that DialogResult property which can have a possible of 8 values (i.e., Abort, Cancel, Ignore, No, None, OK, Retry, Yes).

I have tested this in my test application by setting and removing the DialogResult property of the OK in this manner, and it ran alright. Hope it solves your problem as well.
GeneralRe: WinForms keeps closing my dialogs !!! Pin
Christian Graus5-Jun-05 18:38
protectorChristian Graus5-Jun-05 18:38 
GeneralAdd Refrences in runTime Pin
Web cam5-Jun-05 9:58
Web cam5-Jun-05 9:58 
GeneralRe: Add Refrences in runTime Pin
Carsten Zeumer5-Jun-05 11:40
Carsten Zeumer5-Jun-05 11:40 
GeneralRe: Add Refrences in runTime Pin
DavidNohejl5-Jun-05 12:04
DavidNohejl5-Jun-05 12:04 
QuestionCOORDINATES NOT CENTERED? Pin
...---...5-Jun-05 7:00
...---...5-Jun-05 7:00 
AnswerRe: COORDINATES NOT CENTERED? Pin
S. Senthil Kumar5-Jun-05 7:21
S. Senthil Kumar5-Jun-05 7:21 
GeneralRe: COORDINATES NOT CENTERED? Pin
Anonymous5-Jun-05 9:07
Anonymous5-Jun-05 9:07 
AnswerRe: COORDINATES NOT CENTERED? Pin
Carsten Zeumer5-Jun-05 8:09
Carsten Zeumer5-Jun-05 8:09 
Generalnew removable storage media Pin
heikogerdd5-Jun-05 6:13
heikogerdd5-Jun-05 6:13 
GeneralRe: new removable storage media Pin
Anonymous5-Jun-05 15:51
Anonymous5-Jun-05 15:51 
Generalsave drop down box items in a text file Pin
Farhad Eft5-Jun-05 5:41
Farhad Eft5-Jun-05 5:41 
GeneralRe: save drop down box items in a text file Pin
Carsten Zeumer5-Jun-05 5:47
Carsten Zeumer5-Jun-05 5:47 
GeneralRe: save drop down box items in a text file Pin
S. Senthil Kumar5-Jun-05 6:24
S. Senthil Kumar5-Jun-05 6:24 
GeneralRe: save drop down box items in a text file Pin
Carsten Zeumer5-Jun-05 6:43
Carsten Zeumer5-Jun-05 6:43 
GeneralRe: save drop down box items in a text file Pin
S. Senthil Kumar5-Jun-05 6:55
S. Senthil Kumar5-Jun-05 6:55 
GeneralRe: save drop down box items in a text file Pin
Carsten Zeumer5-Jun-05 8:02
Carsten Zeumer5-Jun-05 8:02 
Generalif a certain item exist in a drop down box Pin
Farhad Eft5-Jun-05 5:29
Farhad Eft5-Jun-05 5:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.