473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

loading forms

Hallo,

I have 3 forms : main, form1 and form2

I can open form1 and form2 from main by clicking a button in main.
I can open form2 form form1 by clicking a button in form1.
I can open form1 from form2 by clicking a button in form2.

However, when I open form1 and form2 from main, and then open form1 from
form2, then I get 2 form1's. This is logical because I made new objects.
But how can I prevent this? Which code should I use for loading forms,
and if they already exist, just focussing on that form?

code in the buttons:

Private Sub button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles button.Click
Dim f As form1 'the form to open
f=new form1()
f.Show()
End Sub

Thanks,
Snuyt

Nov 20 '05 #1
4 991
Hi,

You need to create a forms collection.
http://msdn.microsoft.com/library/de...et05132003.asp

Ken
---------------------
"Snuyt" <sn**********@skynet.be> wrote in message
news:40*********************@news.skynet.be...
Hallo,

I have 3 forms : main, form1 and form2

I can open form1 and form2 from main by clicking a button in main.
I can open form2 form form1 by clicking a button in form1.
I can open form1 from form2 by clicking a button in form2.

However, when I open form1 and form2 from main, and then open form1 from
form2, then I get 2 form1's. This is logical because I made new objects.
But how can I prevent this? Which code should I use for loading forms,
and if they already exist, just focussing on that form?

code in the buttons:

Private Sub button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles button.Click
Dim f As form1 'the form to open
f=new form1()
f.Show()
End Sub

Thanks,
Snuyt

Nov 20 '05 #2
Cor
Hi Snuyt,

I made once this sample as an other approach than normaly is taken,

Maybe you can use it?

Cor

\\\form1
Private WithEvents frm3 As New Form3
Private WithEvents frm2 As New Form2
Private Sub frm2_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm2.VisibleChanged
If frm2.inputfield <> "" Then
Me.Show()
Me.Label1.Text = frm2.inputfield
frm2.Dispose()
End If
End Sub
Private Sub frm3_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm3.VisibleChanged
If frm3.inputfield <> "" Then
Me.Show()
Me.Label1.Text = frm3.inputfield
frm3.Dispose()
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
frm3.Show()
frm3.TopLevel = True
frm2.Show()
frm2.TopLevel = True
End Sub
///
\\\form2 and 3 the same
Public inputfield As String
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

inputfield = "sometext"
Me.Hide()
End Sub
///
Nov 20 '05 #3
Ken Tucker [MVP] wrote:
Hi,

You need to create a forms collection.
http://msdn.microsoft.com/library/de...et05132003.asp

Ken

Thanks, that was perfect !

Now I only have one problem: If the form is closed, then it is also
disposed. So if I try to reshow that object, I get an error. How do I
make, that instead of closing (and disposing) the form, it is simply
hidden. (closing the form = clicking the closing cross in the
rightuppercorner of the form).

Snuyt
---------------------
"Snuyt" <sn**********@skynet.be> wrote in message
news:40*********************@news.skynet.be...
Hallo,

I have 3 forms : main, form1 and form2

I can open form1 and form2 from main by clicking a button in main.
I can open form2 form form1 by clicking a button in form1.
I can open form1 from form2 by clicking a button in form2.

However, when I open form1 and form2 from main, and then open form1 from
form2, then I get 2 form1's. This is logical because I made new objects.
But how can I prevent this? Which code should I use for loading forms,
and if they already exist, just focussing on that form?

code in the buttons:

Private Sub button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles button.Click
Dim f As form1 'the form to open
f=new form1()
f.Show()
End Sub

Thanks,
Snuyt



Nov 20 '05 #4
Snuyt wrote:
Ken Tucker [MVP] wrote:
Hi,

You need to create a forms collection.
http://msdn.microsoft.com/library/de...et05132003.asp
Ken
Thanks, that was perfect !

Now I only have one problem: If the form is closed, then it is also
disposed. So if I try to reshow that object, I get an error. How do I
make, that instead of closing (and disposing) the form, it is simply
hidden. (closing the form = clicking the closing cross in the
rightuppercorner of the form).

Snuyt


Ok, I've found it, just in the windows generated code, changing the code
for disposing did the job.

thanks,

Snuyt

---------------------
"Snuyt" <sn**********@skynet.be> wrote in message
news:40*********************@news.skynet.be...
Hallo,

I have 3 forms : main, form1 and form2

I can open form1 and form2 from main by clicking a button in main.
I can open form2 form form1 by clicking a button in form1.
I can open form1 from form2 by clicking a button in form2.

However, when I open form1 and form2 from main, and then open form1 from
form2, then I get 2 form1's. This is logical because I made new objects.
But how can I prevent this? Which code should I use for loading forms,
and if they already exist, just focussing on that form?

code in the buttons:

Private Sub button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles button.Click
Dim f As form1 'the form to open
f=new form1()
f.Show()
End Sub

Thanks,
Snuyt



Nov 20 '05 #5

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

Similar topics

4
by: Matthew | last post by:
I am not the most talented programmer to grace the earth by a long shot. But I've got a gripe I need to air about the .NET implementaion of Visual Basic. I can live with alot of the major changes...
1
by: Joe | last post by:
Hi Does anyone know of any issues about loading config files for windows forms applications? I have an application that utilizes a config file that holds my database connection string as well...
1
by: Bill K | last post by:
I am developing a winforms project in vb.net. I have several forms that have a number of controls, grids, etc. When I load these as MDI child forms, they load slowly AND they paint/repaint on the...
4
by: Bill Stock | last post by:
The few times in the past that I've loaded unbound data, I've tended to cheat and use temp tables (not really unbound) or use code for small datasets. I'm currently involved in a project that...
0
by: RK | last post by:
Hello I am using Microsoft Development Environment 2003 Version 7.1.3088 & Framework 1.1.4322 and developing Windows Forms using Visual C#. It was working fine for quite a month. Currently...
2
by: Patrick Olurotimi Ige | last post by:
Is it possible to execute a query or do some validation before loading a page.. I have a survey page and i want to validate users before loading the page. I have done it in the page_load. But...
2
by: Rob | last post by:
I was working on a project and everything was going fine, then all of a sudden the form set as my startup object stopped loading. I tried setting some others as the startup object, and some of my...
1
by: RAJ | last post by:
Hi, I am working on a source code written earlier in VB.net.While loading some forms(already created with some controls on it), I am getting the following error:...
3
by: B. Cavour | last post by:
Ok, I'm a C# newbie. W/o making any changes to forms themselves, I used to be able to click on a form and it would open. Now for some forms I'm getting an error saying "An error occurred while...
6
by: A.Weinman | last post by:
Hello all, I have an application that has multiple forms, only 3 of which matter for this issue. There is a main form that starts invisible and does nothing more than start other forms and link...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.