473,480 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

public shared Child Forms - one Instance of.

I searched google and I think I have solved the issue.

Again, if someone could quickly skim over my example and lemmi know if it is
the "correct" way of doing things.
It works, but again - is it the right way - or have I not thought of
something down the road.

So from what I can understand...If i want ever one instance of a form, - and
that form can be called from any child form,
any showmodal form, basically from anywhere in the whole project,
I must declare it as a public shared form, and then access it this way
throught the whole project.

If someone can give me a tip or 2 that I missed or am missing or will run
into.

Otherwise all works great so far. :-) ( "so far" is the key word )

Looking at this now, I guess I should be putting a "form.dispose() " or
something somehwere anytime any of these forms are closed so I dont have a
zillion forms in memory ?

Thanks,

Miro

==== code example

Say you have a Parent Form frmMainForm , that calls a Modal Window,
Or the Parent form Calls a Child form ( with mdiparent = (me) ' where "me"
is the parent window )
and every form you only want to ever open 1 instance of.

So what I do now is that I create a
Public Shared fBla as frmFormBla()
for all my forms that I want to only create 1 instance of. I create these
public forms in the frmMainForm code.

Then to Call a form I do this:

If Not IsNothing(fBla) Then
' and if it hasn't been disposed yet
If Not fBla.IsDisposed Then
fBla.BringToFront()
Else
' else it has already been disposed, so you can
' instantiate a new form and show it
fBla = New frmHome()
fBla.MdiParent = Me
fBla.WindowState = FormWindowState.Maximized
fBla.Show()
End If
Else
' else the form = nothing, so you can safely
' instantiate a new form and show it
fBla = New frmHome()
fBla.MdiParent = Me
fBla.WindowState = FormWindowState.Maximized
fBla.Show()
End If

now lets say...fBla has a button that is to open another form that is to be
a child window of the Main Form - and I only ever want it to ever have one
instance of it opend.

at this point I have to go thru and Public Share that new form.
Public Shared fNew as frmNew

then to call it from fBla in the command button i do this:
-Keep in mind this would be again simillar to the code above so only one
instance of it is ever shown. So i would be checking the disposed and
stuff. -simplified it down for email sake.

frmMainForm.fNew = New frmNew

frmMainForm.fNew.MdiParent = frmMainForm
frmMainForm.fNew.WindowState = FormWindowState.Maximized
frmMainForm.fNew.Show()
==== end



Oct 11 '06 #1
0 1153

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

Similar topics

3
2724
by: Steve | last post by:
Visual Studio 2003 .NET / C# I have a treeview object on a form which acts as the main menu controller for my application. the treeview is always in sight, and the form it is on acts as the...
3
1498
by: thdevdex | last post by:
I'm new to the web forms world (ASP.Net) but not vb and am converting a vb6 windows app to the web. If I create public subroutines at a module level, is this a problem in a server based app? Will...
10
3660
by: darrel | last post by:
I'm still trying to sort out in my head the differences between public and shared when referring to declaring properties or variables. This is my understanding: shared - akin to a 'global'...
4
45072
by: Chris | last post by:
Hello, I'm just getting started with VB and am new to the group, so please excuse what may seem to be a rudimentary question. I've been writing basic programs and have noticed that the...
5
8420
by: Neil Steventon | last post by:
Hi, I am new to VB.net , well the objects concept anyway and was wondering if there were any good articles / turorials on when and why you would use certain declarations such as Private test...
7
3081
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
27
2674
by: thomasp | last post by:
Variables that I would like to make available to all forms and modules in my program, where should I declare them? At the momment I just created a module and have them all declared public there. ...
8
1997
by: Al | last post by:
I'd like to create Class Library in VB 2005, which has a property accessible by external programs. I decided to include 1 Class with 1 property in this project. I placed this code in Class:...
5
2226
by: Earl | last post by:
I need to call a method on an owned child form, and am wondering if the best way of doing this is to capture the Closing event of the form that passes control back to the form where I have the...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7045
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,...
0
7087
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...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6944
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...
1
4782
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...
0
4483
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...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
182
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...

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.