open a form

  • Thread starter Thread starter doller
  • Start date Start date
D

doller

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
 
Try this:
in OnClick event of the button put this code:
form2 f2 = new form2();
try
{
f2.ShowDialog();
}
finally
{
f2.Dispose();
}
 
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
 
Guys, how can i close me app(From) by button_click?

Application Exit - but how?

P.S. on C#.
 
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.
 
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.
 
i have one more stupid question:

here
http://msdn.microsoft.com/library/d.../html/vbtskcreatingeventhandlersatruntime.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
 
Hello maiden,
i have one more stupid question:
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.
 
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
 
ok. thanks for ansers

last my try:
---------------------------------------------------------------------------------------------------
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
}
 
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
 
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
 
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();

}

=================================================================
 
Back
Top