473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how does this still work??

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
Nov 17 '05 #1
5 2339
I think thats fine
-------
Regards ,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/
My Interview Blog
http://spaces.msn.com/members/dotnetinterviews/

Nov 17 '05 #2
Hi Barry,

Your concern is commendable. You will never become a good programmer if you
can't understand code that is written for you by a designer. Visual Studio
is an awesome tool set, and contains a great variety of devices to help you
write code. The danger is that people who use it will let it become a crutch
for them, and when the time comes that they have to do something it does NOT
do for them, they will be dead in the water.

Visual Studio includes a set of Templates, which are basically files of
pre-written code. When you create a new project of a certain type, the
template for that project,which contains code that is common to that type of
project, is copied for your project. This saves you the trouble of having to
type in the basic using statements, class definitions, etc. It gives you a
ready-made starting point.

Visual Studio also includes a large set of visual Designers. The Designer,
for example, for a Windows Form, reads the code, and displays a graphic
representation of the graphic user interface that the code will create at
run-time. The Properties window is simply a set of the properties of the
selected class instance in the Designer, and it uses Reflection to determine
what properties are available to pre-set for that instance. When you type in
a property in the Properties window, VS.Net writes the code for you in the
class definition. This is also a real time-saver, as it saves you the time
and trouble of writing out the property definition yourself, and prevents
typing errors to a great extent, one of the most common causes of bugs in
the software.

Add to that Intellisense, auto-indenting, and a host of other productivity
tools, and you have a great toolkit that automates a lot of what would be
hand-typing, and looking up class references in the SDK all day long. So,
it's a good thing to have.

However, again, a tool is not a substitute for knowledge and understanding.
And, in fact, you can use this toolset to learn how to program with C# as a
bonus. Here's how:

When the Designer writes code for you, look at the code it writes. Stufy how
it is written. Why, for example, did the Template include the following?

Static void Main ( )
{
Application.Run(new MyForm( )); // nor this
}

Every program has an entry point, a point where execution begins. In a C#
program, this is the method called Main. It is the entry point because of
its name. The compiler looks for a method called Main, and sets it as the
entry point for the application.

Or, how about this?

//txtEnter
this.txtEnter.Location = new System.Drawing.Point(16,32);
this.txtEnter.Size = new System.Drawing.Size(264,20);

Well, in the designer, you placed a textbox on the form. You may have sized
it, or left the default Designer size, but it did have a size. A visual
Control in a form is drawn at a location on the form. The location is
determined by an XY coordinate relative to the upper left-hand corner of the
Control it is immediately inside (in this case, the form itself). This is
how the OS knows how and where to draw the Control. The Point structure was
created specifically for identifying an XY corrdinate, or location, in
2-dimensional space. Similarly, the Size structure was created to identify
the dimensions (width and height) of a rectangle in 2-dimensional space. In
the acse of a textbox, the inside is simply scaled to fit inside that space
at that point.

By studying the code that the Designer writes for you, you can learn how
these things are programmed, and learn to program them for yourself in the
future, if need be. As an experiment, try changing the dimensions in the
code, and switch to the Designer view to see what the result it. It should
be fun.

Bottom line, your first experiment was a success! Keep going, and try to
take on a little at a time. It should be fun. The science of programming is
an elephant, but even an elephant can be eaten, one byte at a time!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
"tindog" <ti****@tpg.com.au> wrote in message
news:43******@dnews.tpgi.com.au...
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

Nov 17 '05 #3
"tindog" <ti****@tpg.com.au> wrote in message
news:43******@dnews.tpgi.com.au...
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


Hi Barry,

glad you got it all working. As you probably noticed there is alot of code
generated for you by the winforms designer. And this amount of code
generation can get in the way of understanding what is going on (although
its fantastic once you got the hang of it).

To be frank, I'd always start with Console applications as, although not
very visually appealing, are very clean so you can understand what is going
on more easily. e.g.

class App
{
static void Main()
{
System.Console.WriteLine("Hello, World");
}
}

This is hello world in a console application - as you can see, much simpler
than a Winforms application.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Nov 17 '05 #4
Again thank you all so very much for your encouraging words and advice. I'm
sure with persistance I will get the hang of C# unless it is changed again
by its designers. I must admit that I have done a few exciting things in my
life but learning c# and seeing what it is capable of, boundaries seem
limitless and to have people from this newsgroup behind me is refreshing and
does not make me feel like I am sinking. At the moment I am dog Paddling so
at least I'm getting somewhere ( one day I might be able to swim).

Cheers
Barry
"Richard Blewett [DevelopMentor]" <richard at nospam dotnetconsult dot co
dot uk> wrote in message news:Oo**************@tk2msftngp13.phx.gbl...
"tindog" <ti****@tpg.com.au> wrote in message
news:43******@dnews.tpgi.com.au...
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


Hi Barry,

glad you got it all working. As you probably noticed there is alot of code
generated for you by the winforms designer. And this amount of code
generation can get in the way of understanding what is going on (although
its fantastic once you got the hang of it).

To be frank, I'd always start with Console applications as, although not
very visually appealing, are very clean so you can understand what is
going on more easily. e.g.

class App
{
static void Main()
{
System.Console.WriteLine("Hello, World");
}
}

This is hello world in a console application - as you can see, much
simpler than a Winforms application.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Nov 17 '05 #5
Could not agree more with Richard.

Apart from starting out with console apps, witch i totally agree is a
great starting point (and in some cases a great ending point as well -
- - another story) - check out codeproject.com - and avoid the
complicated entries - theres a lot to pick up - and as you gain
knowledge and experience there's a lot more there - personally i found
it great to get in sync with c# - and whats much more importent - the
framework. Good programming
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

162
by: Isaac Grover | last post by:
Hi everyone, Just out of curiosity I recently pointed one of my hand-typed pages at the W3 Validator, and my hand-typed code was just ripped to shreds. Then I pointed some major sites...
2
by: Steven T. Hatton | last post by:
I'm still not completely sure what's going on with C++ I/O regarding the extractors and inserters. The following document seems a bit inconsistent:...
5
by: rogsonl | last post by:
My computer was moved last week, and the company changed the network groups we work on. As a result, one of the main benefits from Whidbey (database connectivity) no longer works. Situation: 1....
11
by: minnesotti | last post by:
Hi there, I subscribed to a photographic pictures-hosting website which is heavy on JavaScript. My preferred latest browser Mozilla Firefox does not work with it -- no pictures are displayed and...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
5
by: mkaushik | last post by:
Hi everyone, Im just starting out with C++, and am curious to know how "delete <pointer>", knows about the number of memory locations to free. I read somewhere that delete frees up space...
5
by: antonyliu2002 | last post by:
Hi, It looks like so many people are having problems with the javascript submit in firefox. I searched around, but haven't found a solution yet. Mostly, people were saying, try this or try...
9
by: Stan B | last post by:
I create a popup window by calling window.showModalDialog Popup window has Ok button with this code attached: === string Script = "<script language=JavaScript>" + "{" + "window.close();" +...
19
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.