T
tindog
I seem to be caught in a bit of a conundrum with C#. First of all getting
books on VS 2003.net then VS 2005 comes out and further a book I have bought
to just learn just the language C# (in 21 days). I now have ordered, as
suggested to me by a few members of the newsgroup to get a Primer type book
how ever until then I will use what I have. BUT looking at the C# language
my first exercise which happens to be a windows form looks quite scary. I
got this to work "but why do I put in a tiny bit of the code in and it
works. I'll explain what I did. What I used was a win app form in VS2005.
The object is to write in the text box press enter button and what have
printed goes to the label. Rewrite text in text box and press enter and what
entered also goes into label box but on top of previous message.
This is source code with my comments, I understand this is written so can be
compiled in a basic compiler via command line.
Hello through windows form:
Using System;
Using System.Windows.Forms; // don't have to do anything her already written
plus a // // few more systems etc.. on VS 2005
namespace HelloWin
{
public class MyForm : Form // vs2005 public partial class Form1 : Form
{
private TextBox txtEnter; // These can be altered in properties box no
probs here
private Label lblDisplay;
private Button btnOk;
public MyForm( ) // public Form1( ) .suppose this can be altered in code
anyway no //probs here
{
this.txtEnter = new TextBox( ); // did not enter this in vs2005
this.lblDisplay = new Label( ); // nor this
this.btnOk = newButton (); // nor this
this.Text = "My HelloWin App!"; // entered in properties box for form and
became title //at top of form
//txtEnter
this.txtEnter.Location = new System.Drawing.Point(16,32); // entered in prop
box for text //box
this.txtEnter.Size = new System.Drawing.Size(264,20); // entered in prop box
// lblDisplay
this.lblDisplay.Location = new System.Drawing.Point(16,72); // prop box for
label
this.lblDisplay.Size = new System.Drawing.Size(264,128); // can control from
vs2003 //but not vs2005 always defaults to 31,31 but somehow stretches as
wanted to.
// btnOk
this.btnOk.Location = new System.Drawing.Point(88,224); // control from prop
box
this.btnOk.Text = "OK"; // control from property box
this.btnOk.Click += new System.EventHandler(this.btnOk_Click); // did not
have to enter this
// myform
this.Controls.AddRange(new Control [ ] {
this.txtEnter, this.lblDisplay, this.btnOk}); // nor this
}
Static void Main ( ) //nor this
{
Application.Run(new MyForm( )); // nor this
}
Private void btnOk_Click(object sender, System.EventArgs e) // automatically
inserted
{
lblDisplay.Text = txtEnter.Text + "\n" + lblDisplay.Text; // only code I had
to enter and it worked (Why)???
}
}
}
Whew glad that's over.. What I did was that okay ??? or was there syntax I
should have put in??? (even though it did work)..
Barry
books on VS 2003.net then VS 2005 comes out and further a book I have bought
to just learn just the language C# (in 21 days). I now have ordered, as
suggested to me by a few members of the newsgroup to get a Primer type book
how ever until then I will use what I have. BUT looking at the C# language
my first exercise which happens to be a windows form looks quite scary. I
got this to work "but why do I put in a tiny bit of the code in and it
works. I'll explain what I did. What I used was a win app form in VS2005.
The object is to write in the text box press enter button and what have
printed goes to the label. Rewrite text in text box and press enter and what
entered also goes into label box but on top of previous message.
This is source code with my comments, I understand this is written so can be
compiled in a basic compiler via command line.
Hello through windows form:
Using System;
Using System.Windows.Forms; // don't have to do anything her already written
plus a // // few more systems etc.. on VS 2005
namespace HelloWin
{
public class MyForm : Form // vs2005 public partial class Form1 : Form
{
private TextBox txtEnter; // These can be altered in properties box no
probs here
private Label lblDisplay;
private Button btnOk;
public MyForm( ) // public Form1( ) .suppose this can be altered in code
anyway no //probs here
{
this.txtEnter = new TextBox( ); // did not enter this in vs2005
this.lblDisplay = new Label( ); // nor this
this.btnOk = newButton (); // nor this
this.Text = "My HelloWin App!"; // entered in properties box for form and
became title //at top of form
//txtEnter
this.txtEnter.Location = new System.Drawing.Point(16,32); // entered in prop
box for text //box
this.txtEnter.Size = new System.Drawing.Size(264,20); // entered in prop box
// lblDisplay
this.lblDisplay.Location = new System.Drawing.Point(16,72); // prop box for
label
this.lblDisplay.Size = new System.Drawing.Size(264,128); // can control from
vs2003 //but not vs2005 always defaults to 31,31 but somehow stretches as
wanted to.
// btnOk
this.btnOk.Location = new System.Drawing.Point(88,224); // control from prop
box
this.btnOk.Text = "OK"; // control from property box
this.btnOk.Click += new System.EventHandler(this.btnOk_Click); // did not
have to enter this
// myform
this.Controls.AddRange(new Control [ ] {
this.txtEnter, this.lblDisplay, this.btnOk}); // nor this
}
Static void Main ( ) //nor this
{
Application.Run(new MyForm( )); // nor this
}
Private void btnOk_Click(object sender, System.EventArgs e) // automatically
inserted
{
lblDisplay.Text = txtEnter.Text + "\n" + lblDisplay.Text; // only code I had
to enter and it worked (Why)???
}
}
}
Whew glad that's over.. What I did was that okay ??? or was there syntax I
should have put in??? (even though it did work)..
Barry