473,385 Members | 1,492 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,385 software developers and data experts.

REALLY simple question im sure

just trying to grasp the insane differences between vb6 and vs2005...

2 buttons on a form. 1 button creates a new instance of a second form, and
shows the form. why cant i access this form from the second button?
Jul 18 '07 #1
6 1186
"S Moran" <s@moran.comwrote in message
news:O1**************@TK2MSFTNGP06.phx.gbl...
just trying to grasp the insane differences between vb6 and vs2005...

2 buttons on a form. 1 button creates a new instance of a second form, and
shows the form. why cant i access this form from the second button?
You can. Where are you having problems? Is the variable that references
the second form in a scope that the second button can access?
Jul 18 '07 #2
thats where my confusion is...
if i say: Form secondform = new Form2();
inside of the click event for button1, then button2 cant access the form,
correct?

and if i declare it outside of the buttons click event at the class level,
then both buttons can access it.

my questions are... couldnt i say: public Form secondform = new Form2();
in the click event of button1?

or does the buttons click event need to be made public instead of private?

just trying to grasp it all....


"John Vottero" <JV******@mvpsi.comwrote in message
news:12**********************************@microsof t.com...
"S Moran" <s@moran.comwrote in message
news:O1**************@TK2MSFTNGP06.phx.gbl...
>just trying to grasp the insane differences between vb6 and vs2005...

2 buttons on a form. 1 button creates a new instance of a second form,
and shows the form. why cant i access this form from the second button?

You can. Where are you having problems? Is the variable that references
the second form in a scope that the second button can access?

Jul 18 '07 #3
Hallo!
my questions are... couldnt i say: public Form secondform = new Form2();
in the click event of button1?

or does the buttons click event need to be made public instead of private?
you cannot declare a public field inside a clickevent.
You need to do it this way (better: this is one way, doing it):

public Form secondform; //simple declare the public field outside of any
other members, but inside the class of course
private void button1_Click(object sender, EventArgs e)
{
secondform = new form2();
}
private void button2_Click(object sender, EventArgs e)
{
secondform.show // or whatever
}

greets
Daniel
Jul 18 '07 #4
thank you... now...

if i declare a new form in the class, and button one does "form2.show" and
button2 does "form2.close", clicking form1.show again causes an error
because the form doesnt exist anymore. how can i deal with this?

"Daniel Marohn" <ca*****@community.nospamwrote in message
news:Oq**************@TK2MSFTNGP02.phx.gbl...
Hallo!
>my questions are... couldnt i say: public Form secondform = new Form2();
in the click event of button1?

or does the buttons click event need to be made public instead of
private?

you cannot declare a public field inside a clickevent.
You need to do it this way (better: this is one way, doing it):

public Form secondform; //simple declare the public field outside of any
other members, but inside the class of course
private void button1_Click(object sender, EventArgs e)
{
secondform = new form2();
}
private void button2_Click(object sender, EventArgs e)
{
secondform.show // or whatever
}

greets
Daniel
Jul 18 '07 #5
Hi !
if i declare a new form in the class, and button one does "form2.show" and
button2 does "form2.close", clicking form1.show again causes an error
because the form doesnt exist anymore. how can i deal with this?
you need to know: a form has a lifecircle. creating, showing, closing,
destucting.

after closing a form, you cannot open it again. You would need to create a
new one by 'form2=new secondform();' inside the clickevent. But I guess,
closing the form was not your real intention. You can set
form2.visible=false; instead closing the form. In this case you will be able
to reshow the form.

greets
Daniel
Jul 18 '07 #6
S Moran wrote:
if i declare a new form in the class, and button one does
"form2.show" and button2 does "form2.close", clicking form1.show
again causes an error because the form doesnt exist anymore. how can
i deal with this?
Two suggestions:

1. Get Button2 to hide the form rather than close it. You can hide and
re-show a form as many times as you like. It will of course be the same form
instance each time, so all values that were present in the form when you
hide it will still be there when you re-show it.

2. Alternatively, in Button2, after you close the form, set its reference to
Nothing. Then in Button1 you can check for this and create a new form if
required:
\\\
Public secondForm As Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If secondForm Is Nothing Then
secondForm = New Form2
End If

secondForm.Show()

End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

If secondForm IsNot Nothing Then
secondForm.Close()
secondForm = Nothing
End If

End Sub
///

HTH,

--

(O)enone
Jul 19 '07 #7

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

Similar topics

1
by: Peter Young | last post by:
I'm seeing a problem with IE running on OS-X. When the user logs in to the website (ASP/IIS5), a Session is established properly, but somewhere along the line, a new Session is created and...
2
by: James | last post by:
Are there any style elements that work on select elements on Apple/IE? I want colored text, colored background, or just about anything colored in a select drop-down but can't seem to make it work...
15
by: Jeannie | last post by:
Hello group! I'm in Europe, traveling with my laptop, and I don't any compilers other than Borland C++ 5.5. available. I also don't have any manuals or help files available. Sadly, more...
4
by: Peter Larsson | last post by:
Hello everybody, I'm developing a system for a company that has production at two different locations. The production is stored in an Access database at each location, and I need to find a way...
8
by: markus | last post by:
Hi, As I been programming in C I have discovered more and more tools that really helps to speed up the development process when writing programs. Examples of such tools are cscope, cbrowser,...
8
by: Ted Miller | last post by:
Hi folks, I'm looking at moving a large base of C++ code to .Net under tight time constraints. The code runs in mission-critical environments, and I am extremely concerned about the loader lock...
3
by: Roy Osherove | last post by:
Hi folks. I have an ASP.Net application that runs a .Net dll that uses WMI and ADSI(both managed) to connect to a given IIS root and search through it. When not using the ASP.Net client, but...
131
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.