471,350 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

open a form

Dear all,

I am new to VB.C# .I have 2 forms i want to call form2 on command
button click placed on form1.

how can i do that .

from
Doller

Jan 10 '06 #1
19 1429
Try this:
in OnClick event of the button put this code:
form2 f2 = new form2();
try
{
f2.ShowDialog();
}
finally
{
f2.Dispose();
}

--
Vit Zayko
Jan 10 '06 #2
Hello doller,
I am sorry but i couldn't understand which lang. u are using.
C# or VB?

IF you want to call form2, write the code above at the button_click event.
C#
Form2 frm2 = new Form2();
frm2.Show();

VB.Net
Dim frm2 as new Form2()
frm2.Show()
Regardings...
Bahadir ARSLAN
www.maxiasp.net
Dear all,

I am new to VB.C# .I have 2 forms i want to call form2 on command
button click placed on form1.

how can i do that .

from
Doller

Jan 10 '06 #3
m

Guys, how can i close me app(From) by button_click?

Application Exit - but how?

P.S. on C#.
Jan 10 '06 #4
Hello @discussions.microsoft.com,
Guys, how can i close me app(From) by button_click?

Application Exit - but how?

P.S. on C#.


If it's the form the button is on, just write:

Close();

If you want to click a button on one form to close a different form, you
need a reference to the form object.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Jan 10 '06 #5
m
Thx, i try it.
all great things simple ;)

Jan 10 '06 #6
Hi,
I am using C# .But the code is not working

from
DOller

Jan 10 '06 #7
m
i have one more stupid question:

here
http://msdn.microsoft.com/library/de...satruntime.asp

wrote
[qoute]
In a method within your form's class, add code that specifies the event
handler to handle the event. For example, the following code specifies
the event handler button1_Click handles the Click event of a Button
control:
// C#
button1.Click += new EventHandler(button1_Click);

[/qoute]

For what this string^ "button1.Click += new
EventHandler(button1_Click);"
thanks for your help

Jan 10 '06 #8
Hello doller,
Hi,
I am using C# .But the code is not working
from
DOller


If the code compiles it should always be working. It might not do what you
want though.

As for your particular problem, it would be better if you gave us a hint
as to what particular piece of code you're trying to use, what context it
is used in, what it should accomplish and what the symptoms are that tells
you that it isn't working.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Jan 10 '06 #9
Hello maiden,
i have one more stupid question:
<snip> For what this string^ "button1.Click += new
EventHandler(button1_Click);"
thanks for your help


This line of code adds one more event handler to the Click event. The event
handler is of type EventHandler, and the method it refers to is the button1_Click
method of the object that this line of code is executing in.

In other words, when you click on the button, the Click event handler(s)
will be fired, which will in turn call the button1_Click method and execute
whatever code you have written there.

In all fairness, you should get a book that teaches you these issues.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Jan 10 '06 #10
This simply wires up an event - i.e. it says

"When the Click event of button1 is fired, execute the code in the method
button1_Click"

Otherwise, you would click on the button all day long, but nothing special
would happen.

In some languages (e.g. VB6), wiring up events is simply a case of writing a
method called (for example} {object}_{event}, but in C# you have to tell it
explicitely.

Don't worry about remembering the complex syntax; if you use VS2005, as soon
as you type += (next to an event), it suggests the next bit of code for you;
in fact, in .NET 2 even this is overkill, as you could just type:

button1.Click += button1_Click;

Of course, you have to have a function called button1_Click that meets the
required signature for the event... (which is done automatically if you
allow VS2005 to write the method stub for you)

Marc
"m@iden" <ma*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
i have one more stupid question:

here
http://msdn.microsoft.com/library/de...satruntime.asp

wrote
[qoute]
In a method within your form's class, add code that specifies the event
handler to handle the event. For example, the following code specifies
the event handler button1_Click handles the Click event of a Button
control:
// C#
button1.Click += new EventHandler(button1_Click);

[/qoute]

For what this string^ "button1.Click += new
EventHandler(button1_Click);"
thanks for your help

Jan 10 '06 #11
m
ok. thanks for ansers

last my try:
---------------------------------------------------------------------------------------------------
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
}
--------------------------------------------------------------------------------------------------
by click i open Form2, how can i close this form by Button.

Jan 10 '06 #12
Which "Button"? A button on the original form, or the new form? On the new
form it is easy (just call Close() in the Click event handler); if the
button is on the old form, then you need to hold an instance; one way would
be to move the frm2 declaration, as below; note I have invented button2 as
the button to close the popup.

Note: I haven't tested (or even compiled) the code:

private Form2 frm2; // place-holder for the popup

private void button1_Click(object sender, EventArgs e) {
CloseForm(); // ensure only ever one popup alive (we will recreate)
frm2 = new Form2();
frm2.Show();
}
private void button2_Click(object sender, EventArgs e) {
CloseForm(); // close the popup if there is one
}
private void CloseForm() {
if(frm2!=null) {
frm2.Close();
frm2.Dispose();
frm2 = null;
}
}

Marc

"m@iden" <ma*********@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
ok. thanks for ansers

last my try:
---------------------------------------------------------------------------------------------------
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
}
--------------------------------------------------------------------------------------------------
by click i open Form2, how can i close this form by Button.

Jan 10 '06 #13
m
i have 2 froms: From1 & From2

Form1 have 2 buttons - 1st button open Form2, second button must close
opened Form2.
i opened Form2 by click button :
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
}
how can i close this FORM2?
thx

Jan 10 '06 #14
erm... re-read my last post... I gave you the code...

Marc

"m@iden" <ma*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
i have 2 froms: From1 & From2

Form1 have 2 buttons - 1st button open Form2, second button must close
opened Form2.
i opened Form2 by click button :
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
}
how can i close this FORM2?
thx

Jan 10 '06 #15
m
plese compile/try your code then post here.

Thanks

Jan 10 '06 #16
erm... no: that would be your bit...

"m@iden" <ma*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
plese compile/try your code then post here.

Thanks

Jan 10 '06 #17
m
thanks for help, right answer i post later

Jan 10 '06 #18
this.DialogResult = DialogResult.ok;

"Marc Gravell" wrote:
erm... no: that would be your bit...

"m@iden" <ma*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
plese compile/try your code then post here.

Thanks


Jan 10 '06 #19
m
ok, now sit down & lear how to answer for my question:
================================================== ==================
public Form2 frm2;

public Form1()

{
frm2 = Form2()}
........

public void button1_Click(object sender, EventArgs e)


{

frm2.Show();


}

public void button2_Click(object sender, EventArgs e)
{

frm2.Hide();

}

================================================== ===============

Jan 10 '06 #20

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Konstantin | last post: by
1 post views Thread by petersk | last post: by
2 posts views Thread by Konstantin | last post: by
19 posts views Thread by =?Utf-8?B?R3JlZw==?= | last post: by

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.