Click here to Skip to main content
15,915,603 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi, i have a big problem, i work on a smart device application. i had 3 forms.

i have 3 forms

the form1 do this action
C#
{
            Form2 f = new Form2();
            f.ShowDialog();


the form2 do this action
C#
Form3 f = new Form3();
          f.ShowDialog();


now the form3 hase 2 button.
i want the first button to didplay me the form1
and the seconde button to display the form2

for the seconde button it easy i do just this
C#
this.close()


but for the first button i don't know how to do to bring me to the form1
please help

i use visual studio 2008 smart device compact framwork C#

What I have tried:

Hi, i have a big problem, i work on a smart device application. ihad forms.

i have 3 forms

the form1 do this action
C#
{
            Form2 f = new Form2();
            f.ShowDialog();


the form2 do this action
C#
Form3 f = new Form3();
          f.ShowDialog();


now the form3 hase 2 button.
i want the first button to didplay me the form1
and the seconde button to display the form2

for the seconde button it easy i do just this
C#
this.close()


but for the first button i don't know how to do to bring me to the form1
please help

i use visual studio 2008 smart device compact framwork C#
Posted
Updated 18-Jun-16 7:40am
v2
Comments
BillWoodruff 19-Jun-16 0:01am    
You are developing using the WinForms standard app library ? Not some mobile version of the FrameWork ?

If you describe what your goal is here more clearly, I can offer you some practical advice to complement Sergey's analysis of what is wrong with what you are doing now.

Never have a WinForm element shown with 'ShowDialog either create, or close, other Forms. I also advise against using 'MessageBox.Show() in a Form shown modally.

1 solution

Doing so would be serious UI abuse. Don't do it. Even if you successfully implemented such behavior, most users would hate it, because people never expect such tricks. Imagine what happens if they want to preserve some data entered in the form you want to close; and you will unexpectedly close it, losing the states of controls. And this is not the only reason for not using your application anymore.

Some background: even though there is a formal parent-child relationship between instances of System.Windows.Forms.Control, this relationship, by default, is rendered defunct for forms which inherit related properties. You could change it, but it would make no practical sense. There is relationship between main form and other forms, and very useful ownership relationship.

Your issue is related to a very different aspect: modal behavior of the forms shown via Form.ShowDialog; it has nothing to do with the parent-child relationship. The whole idea of this behavior is: you cannot access any other part of UI while such form is in the modal state. You should never try to break this behavior by some kinds of tricks. Moreover, it's possible, but really undesirable to stack more than one modal forms, one on top of another. Many Microsoft dialogs still do such things, especially in Control Panel, but following this poor model behavior is a bad idea. Better show no more than one modal form at a time, and limit the number of such forms. Remember that perfect UI would have no modal states at all; but it's just a bit harder to implement in some cases.

If you explain your ultimate purpose, it's possible that you can get further advice.

—SA
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900