Locked How to connect a new form to a button?

  • Saturday, September 09, 2006 4:26 AM
     
     

    Hi everyone, I was wondering how i can make a button connect to a form so when I click on it it takes me to that form but the form cannot be opened repeatedly.

All Replies

  • Saturday, September 09, 2006 6:20 AM
     
     

    code in the button click. (this is written in vb convert it to c#)

    Dim objForms As Form

    dim flag as boolean = false

    For Each objForms In frmMDI.MdiChildren

    If Not objForms.Tag Is Nothing Then

    If Convert.ToString(objForms.Tag).ToUpper = "XYZ" Then

    objForms.Show()

    objForms.Focus()

    flag = true

    End If

    End If

    Next

     

    if  falg = false then

    dim frm1 as Form1

    frm1.Tag = "XYZ"

    frm1.show()

    end if

     

  • Saturday, September 09, 2006 8:25 AM
     
     

    Can anyone kindly please do me a favour, please help me convert the above code to C#. Cos i am a mechanical engineering student with only basic C# background.

    Many Thanks in advance.

  • Saturday, September 09, 2006 3:44 PM
     
     Answered
    Hi!
    Just drop a button on the 1st form, add a second form to your solution and in the button click put:


    private void button1_Click(object sender, EventArgs e)
            {
               Form2 f2 = new Form2();
               f2.ShowDialog(this);
            }


  • Sunday, September 10, 2006 6:50 AM
     
     
    Thanks alot lbc06 ur code works!!!