Hi,
I have 2 winforms namely form1 and form2.In form1 I have 2 textboxes and a button which on clicking opens a new form(form2)
under the button_click method of form1 I have written the following code
Form2 f2=new Form2();
f2.Show();
this is working fine.
In form2 I have menu items namely logoff and exit and a button called exit. Now when this form2 is open when I click the minimize button the form1 still appears but I want to hide/close that form1 as soon as the new form(form2)is opened, and also when I click exit button or exit menu item both forms should be closed and when I click lofoff menu item it should bring back the form1. How to achieve this
Vimal KandasamyPosted Apr 14, 2009, 4:16 AM
why you needs in form...
its very difficult to handle key events in form because most of time focus will be in any of controls in form not on form...
for key events of any controls, you can use key press, key down events for that
Ex:
{{}}
Vimal KandasamyPosted Apr 22, 2009, 3:04 AM
Are u using keyDown Event?.Have you set it in control's properties?
{{
Here KeyCode belongs to KeyEventArgs class// your code
}
Its belongs to System.Windows.Forms Package.
There is no need for any other package.
I debug it.no error for me.Works well.
sachi vasishtaPosted Apr 22, 2009, 1:14 AM
vimal I tried with the key press event(by pressing the enter key a new form opens)code you sent but when I debug there was error with keycode in
if(e.Keycode==Enter)
saying namespace not included I tried with some namespaces but couldnot get rid of that error
sachi vasishtaPosted Apr 15, 2009, 8:14 AM
hi,
I have 3 forms. In form1 I have a textbox and a button. On button click the form1 should close and a new form(form2)should open and in form2 I have a textbox and a button immediate after the textbox1.That textbox1 in form2 shows the value that is passed through the form1's textbox.It can be achieved by the overloaded constructor. But if I click on the button in the form2 it should take into the datagridview containing form(form3) and in that there are few tuples. (id,name,addrs,sex,zip,city,etc) Now if I select a particular row(mouse single click) then it should pick the name attribute and go back to the form2 and display the name in the textbox1 of form2. How to get this??
sachi vasishtaPosted Apr 14, 2009, 4:27 AM
Thanks
sachi vasishtaPosted Apr 14, 2009, 3:50 AM
Vimal In a form(form1) containing two textboxes and a button I know how to get into the new form
private void button1_click(object sender,EventArgs e)
{
string uname=textbox1.text.tostring();
string passwd=textbox2.text.tostring();
if(uname=="sany"&&passwd=="sany")
{
form2 f=new form2();
f2.show();
}
But what to do if I want to open the same form(form2) not by clicking the ok button but by hitting the enter key in form1.
Vimal KandasamyPosted Apr 13, 2009, 2:46 AM
Still you have problem in that ah?...
in Form1 under button event
you can use
Form1.ActiveForm.Hide();
Form2 f = new Form2();
f.Show();
Or use
Form2 f = new Form2();
f.ShowDialog();
this will show both forms but prevent user to access form1...
and In from2
in exit...
use
Application.Exit();
to close both forms and terminate application
in logoff
use
this.Dispose();
Form1 f = new Form1();
f.Show();
If u use ShowDialog() in form1 then in form2 this.Dispose() is enough...
mahesh kumarPosted Apr 13, 2009, 2:37 AM
hai my name is mahesh
the answer for this question in exit button you have to write code as this.close();
to hide the form1 when u open the form2 u have to write code as
form2 f2=new form2();
f2.showdialog(); in the form1 open button
if it is successfull or un successfull reply to me.
Jan MontanoPosted Apr 13, 2009, 2:34 AM
Create a new Form2 constructor which accepts a Form1 data type.
on form2's close event. also close form1 -form1.Close() if I'm not mistaken.
Form1 form1;
public Form2(Form1 form1)
{
this.form1 = form1;
}
Form2 f2=new Form2(Form1 form1);
f2.Show();
//minimize form 1