|
-
Jan 3rd, 2003, 11:56 AM
#1
Thread Starter
Hyperactive Member
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
-
Jan 3rd, 2003, 12:30 PM
#2
VB Code:
Form2 MyNewForm=new Form2();
MyNewForm.ShowDialog();
-
Jan 3rd, 2003, 12:32 PM
#3
Addicted Member
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();
}
-
Jan 3rd, 2003, 01:09 PM
#4
Thread Starter
Hyperactive Member
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
-
Jan 3rd, 2003, 01:24 PM
#5
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();
-
Jan 4th, 2003, 04:00 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|