Results 1 to 6 of 6

Thread: For starters....

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    For starters....

    Ok first question... on my journey to learning C#:

    How do you diplay a new form?

    For example adding the following code to a button in VB would display the new form... What is the code for C#?

    Dim MyNewForm as New Form2
    MyNewForm.ShowDialog()


    Whats the C# equivilent?

    Thanks,

    Anjari

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. Form2 MyNewForm=new Form2();
    2. MyNewForm.ShowDialog();

  3. #3
    Addicted Member MasterBlaster's Avatar
    Join Date
    Jul 2002
    Location
    Seattle
    Posts
    196
    Form form1 = new Form();
    form1.ShowDialog();

    Doh! Here I'll add some other junk since I was to slow on the draw.

    Code:
    public void CreateMyForm()
    {
       // Create a new instance of the form.
       Form form1 = new Form();
       // Create two buttons to use as the accept and cancel buttons.
       Button button1 = new Button ();
       Button button2 = new Button ();
      
       // Set the text of button1 to "OK".
       button1.Text = "OK";
       // Set the position of the button on the form.
       button1.Location = new Point (10, 10);
       // Set the text of button2 to "Cancel".
       button2.Text = "Cancel";
       // Set the position of the button based on the location of button1.
       button2.Location
          = new Point (button1.Left, button1.Height + button1.Top + 10);
       // Set the caption bar text of the form.   
       form1.Text = "My Dialog Box";
       // Display a help button on the form.
       form1.HelpButton = true;
    
       // Define the border style of the form to a dialog box.
       form1.FormBorderStyle = FormBorderStyle.FixedDialog;
       // Set the MaximizeBox to false to remove the maximize box.
       form1.MaximizeBox = false;
       // Set the MinimizeBox to false to remove the minimize box.
       form1.MinimizeBox = false;
       // Set the accept button of the form to button1.
       form1.AcceptButton = button1;
       // Set the cancel button of the form to button2.
       form1.CancelButton = button2;
       // Set the start position of the form to the center of the screen.
       form1.StartPosition = FormStartPosition.CenterScreen;
       
       // Add button1 to the form.
       form1.Controls.Add(button1);
       // Add button2 to the form.
       form1.Controls.Add(button2);
       
       // Display the form as a modal dialog box.
       form1.ShowDialog();
    }

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Thanks...

    Thanks for your quick response but in the same aspect... how do I close the form?

    Example: VB.net

    me.close


    this is done how in C#?

    also one thing I loved about vb.net is it would add any closing statements if i skipped to the next line.. but so far i have noticed that C# hasnt for example the ();

    am I doing something wrong or should i get used to adding that at the end of everthing? ();

    thanks,

    Anjari

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    C# is much more picky about what you type, for instance you may have noticed that it is case sensitive, this can be a good or bad thing it depends who you ask.

    The C# version of Me is this.

    this.Close();

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    VB closes your parentheses and such when you hit enter? Well, that isn't possible in C# as in C# statements and expressions can span several lines without any special character like _ in VB.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width