473,791 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MDI Children Dialog Forms?

Hello everyone,

We are developing a MDI application and what we would require is the
following:

1. To open a MDI child form as Form1
2. To open another MDI child form as Form2 that would act as a dialog
form for the Form2
3. Form2 must not prevent any other MDI forms from opening or otherwise
prevent application from working properly
4. Form2 must only prevent Form1 (or any of the controls on it) from
getting focus (as a normal Dialog would for an application)

Nifty trick. We've seen it in the Microsoft Navision but haven't got a clue
how to actually do it. Any help appreciated.

BR,

GAZ
Nov 23 '05 #1
3 2755
Gordan A Ziza wrote:
Hello everyone,

We are developing a MDI application and what we would require is the
following:

1. To open a MDI child form as Form1
2. To open another MDI child form as Form2 that would act as a dialog
form for the Form2
3. Form2 must not prevent any other MDI forms from opening or otherwise
prevent application from working properly
4. Form2 must only prevent Form1 (or any of the controls on it) from
getting focus (as a normal Dialog would for an application)

Nifty trick. We've seen it in the Microsoft Navision but haven't got a clue
how to actually do it. Any help appreciated.


I've implemented similar forms. I don't have VS in front of me, but my approach
to your problem would be along the lines of....

* Put a private Form2 declaration in the Form1 class, ie give each instance of
Form1 its own Form2.

* Add two public methods to Form2, one to display the form (let's call it
Display) and one to hide it (call it PutAway), and expose a public boolean
property, IsActivated. Along with any other setup code, Display should set
IsActivated to True and call Me.Show (not Me.ShowDialog.) PutAway should set
IsActivated to False and call Me.Hide. In either method, you might want to
reset the controls and variables to a default state. IsActivated should default
to False, either implicitly in declaration or manually in Form2's constructor.

* Add an event handler to Form2 that catches the Closing event (in .NET 2.0,
the FormClosing event.) Have the handler cancel the close (which would dispose
of the instance Form1 is holding) and instead call Me.Hide.

* Declare a private Control variable in the Form2 class.

* Add an event handler to Form2 that stores the control on Form2 that is losing
the focus in the private Control variable. Use AddHandler to point the
LostFocus event of every control on Form2 that can receive focus to this
handler. The end result is that when any focusable control on Form2 loses
focus, the form makes a note of it.

* Add a public function to Form2, ReEnter, that will reenter the form and
return focus to the private Control variable. If you are the paranoid type, you
can have ReEnter default to Display if the form is not active, or do nothing
and return.

* Add an event handler to Form1 that catches the form's GetFocus event. If it's
associated Form2.IsActivat ed is True, then call Form2's ReEnter method.
That should do it. I suggest the Display, PutAway and IsActivated stuff because
..NET garbage collection is pretty flakey; testing the variable to see if it is
Nothing or something is unreliable. Taking manual control is kludgy but it does
give predictable results.

The end result: You can have multiple Form1s, each with its own associated
Form2. If a Form1 has a Form2 active, any effort to set the focus to the Form1
will instead be set to the correct Form2.
--
Gregory Gadow
Nov 23 '05 #2
Hi Gordan,

For this issue, I have added a reply in
microsoft.publi c.dotnet.framew ork.windowsform s newsgroup, please check it
there, I will follow up with you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 23 '05 #3
Thanks a lot. Works like a charm. Quite simple when you look at it.

Thanks once again.

GAZ
"Gregory Gadow" <te******@serv. net> wrote in message
news:43******** *******@serv.ne t...
Gordan A Ziza wrote:
Hello everyone,

We are developing a MDI application and what we would require is the
following:

1. To open a MDI child form as Form1
2. To open another MDI child form as Form2 that would act as a dialog
form for the Form2
3. Form2 must not prevent any other MDI forms from opening or
otherwise
prevent application from working properly
4. Form2 must only prevent Form1 (or any of the controls on it) from
getting focus (as a normal Dialog would for an application)

Nifty trick. We've seen it in the Microsoft Navision but haven't got a
clue
how to actually do it. Any help appreciated.


I've implemented similar forms. I don't have VS in front of me, but my
approach
to your problem would be along the lines of....

* Put a private Form2 declaration in the Form1 class, ie give each
instance of
Form1 its own Form2.

* Add two public methods to Form2, one to display the form (let's call it
Display) and one to hide it (call it PutAway), and expose a public boolean
property, IsActivated. Along with any other setup code, Display should set
IsActivated to True and call Me.Show (not Me.ShowDialog.) PutAway should
set
IsActivated to False and call Me.Hide. In either method, you might want to
reset the controls and variables to a default state. IsActivated should
default
to False, either implicitly in declaration or manually in Form2's
constructor.

* Add an event handler to Form2 that catches the Closing event (in .NET
2.0,
the FormClosing event.) Have the handler cancel the close (which would
dispose
of the instance Form1 is holding) and instead call Me.Hide.

* Declare a private Control variable in the Form2 class.

* Add an event handler to Form2 that stores the control on Form2 that is
losing
the focus in the private Control variable. Use AddHandler to point the
LostFocus event of every control on Form2 that can receive focus to this
handler. The end result is that when any focusable control on Form2 loses
focus, the form makes a note of it.

* Add a public function to Form2, ReEnter, that will reenter the form and
return focus to the private Control variable. If you are the paranoid
type, you
can have ReEnter default to Display if the form is not active, or do
nothing
and return.

* Add an event handler to Form1 that catches the form's GetFocus event. If
it's
associated Form2.IsActivat ed is True, then call Form2's ReEnter method.
That should do it. I suggest the Display, PutAway and IsActivated stuff
because
.NET garbage collection is pretty flakey; testing the variable to see if
it is
Nothing or something is unreliable. Taking manual control is kludgy but it
does
give predictable results.

The end result: You can have multiple Form1s, each with its own associated
Form2. If a Form1 has a Form2 active, any effort to set the focus to the
Form1
will instead be set to the correct Form2.
--
Gregory Gadow

Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3192
by: Andrew | last post by:
I get a Null Reference Exception if I close a modeless form (that is, a form displayed using Show()) when a selection is made from a ComboxBox. If the form is modal (displayed using ShowDialog()) or the selection is made from, say, a ListBox, no exception is thrown. I have included a simple example below. The error message refers to Unsafe Native Methods, but the code is 100% managed. What is going on ? I am using C#.NET 2003, Standard...
3
8152
by: Andrew | last post by:
I get a Null Reference Exception if I close a non-modal dialog (that is, a form opened with Show()) when a selection is made from a ComboBox. The error message refers to Unsafe Native Methods, but the code is 100% managed. The exception is not thrown if the dialog was modal (opened with ShowDialog()) or if the selection is made from, say, a ListBox. I have included a simple example below. I am using C#.NET 2003, Standard Edition.
6
4056
by: Steve Long | last post by:
Help, I'm running VS.NET 2003 and when I try to start my application, I get the "unhandled exception" dialog instead of the IDE highlighting the offending line of code. The problem appears to be instantiating a particular class in my project but the dialog doesn't tell me what code in the class is causing the problem (and it a large class). How can I get the IDE to take me to the offending line of code? If I put this line in my...
12
2517
by: lgbjr | last post by:
Hi All, I have a VB.NET MDI application with several MDI Child forms. Each of the MDI Child forms has a significant amount of code. What I think I would like to do is create a DLL for each child form, so that if I need to make changes to a particular form, I can just update the DLL for that form and have the user download just the new DLL. From the main menu of the MDI parent, a user selects a particular task, which generally involves...
1
2172
by: CDrue | last post by:
Hello, Is it possible to create inside MDIForms additional child forms which also have form children? For my application it is necessary to create a hierarchy of forms, e.g. MainMDIForm Child 1 Child 2
11
5297
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok / dangerous? How can I force shutdown code within the dialog's Form.FormClosed event run? Zytan
11
2382
by: VK | last post by:
In the continuation of the discussion at "Making Site Opaque -- This Strategy Feasible?" and my comment at http://groups.google.com/group/comp.lang.javascript/msg/b515a4408680e8e2 I have realized that despite suggestions to use DHTML-based modal dialogs are very common? there is not a single fully functional reliable copyright-free cross-browser alternative to say MsgBox (VBScript) or showModalDialog (IE). This way such suggestions up to...
6
4500
by: Scott Gravenhorst | last post by:
Windows XP SP3 My application is set to open a SaveFile dialog when an exit is requested. When I click the app's close button, the save dialog opens, but when I click to change the folder, the exception occurs pointing to FileSaveDialog1.ShowDialog(). The exception also indicates some problem with system.drawing.dll. The exception text is: "Attempted to read or write protected memory. This is often an
9
5496
by: Gord | last post by:
In VB6, a custom dialog can be easily created by adding a new form, adding whatever controls you like, sizing it as you like, adding code and then just loading/unloading it whenever you like. Using Access 07, a form is a little different beast and it would appear a custom dialog cannot be created in the same way. How does one go about creating a custom dialog? Note that I am not well experienced in programming but I have a couple of...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.