Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 22nd, 2007, 11:22 PM   #1
357mag
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 148
Rep Power: 4 357mag is on a distinguished road
Understanding the default code

Looking ahead into a simple Windows project that would just have a button on a form, and then when the button is clicked I would display a message or something. When I double-click the button the following code is presented in the editor window:

namespace Nice_Girl
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}

Can someone explain what some of that stuff means? I know what a namespace is so I'm okay with that, but the rest of it nope. I've looked on the web but can't seem to find any clear cut answers that aren't way over my head.
357mag is offline   Reply With Quote
Old May 22nd, 2007, 11:29 PM   #2
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 579
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
csharp Syntax (Toggle Plain Text)
  1. namespace Nice_Girl //this is your project name.
  2. {
  3. public partial class Form1 : Form // this is the class for your form.
  4. {
  5. public Form1()
  6. {
  7. InitializeComponent(); // this is what starts your form
  8. }
  9.  
  10. private void button1_Click(object sender, EventArgs e)
  11. {
  12. //anything in here is done when you click the button.
  13. }
  14. }
  15. }

does that help?
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old May 23rd, 2007, 12:04 AM   #3
357mag
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 148
Rep Power: 4 357mag is on a distinguished road
A little. The "partial" keyword means something about your class definition being able to be split into multiple physical files? That's what one site said about them anyway.

Why is it written Form1 : Form

and not

Form1?

Then moving on, is Public Form1() known as what is called a constructor? Although I really don't know what a constructor is or what purpose it serves.

Then I guess InitializeComponent() must be some kind of method.

Finally, what is the object sender, EventArgs e mean? I assume that must be some kind of parameter list, but if you could elaborate a little.
357mag is offline   Reply With Quote
Old May 23rd, 2007, 12:20 AM   #4
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 579
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
ok first, i dont know what "partial" means.

second, the ": Form" after Form1 makes it realize that this is a form being compiled. If i'm wrong, someone please correct me.

All a constructor is, is a method that creates a new instance of an object.

Yes InitializeComponent() is a method, that is built in.

and sorry, but I have no idea what object senger, EventArgs e means.
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old May 23rd, 2007, 12:21 AM   #5
jaeusm
Programmer
 
jaeusm's Avatar
 
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3 jaeusm is on a distinguished road
Quote:
I've looked on the web but can't seem to find any clear cut answers that aren't way over my head.
I think it may be in your best interest to purchase an introductory C# programming book. Many people like Jesse Liberty's "Programming C#" book. It will start you out at ground level and work up.
jaeusm is offline   Reply With Quote
Old May 23rd, 2007, 12:31 AM   #6
357mag
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 148
Rep Power: 4 357mag is on a distinguished road
Actually I have the C# Primer Plus book by Klaus Michelsen. But in that book he just deals with the core language.
357mag is offline   Reply With Quote
Old May 23rd, 2007, 12:34 AM   #7
357mag
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 148
Rep Power: 4 357mag is on a distinguished road
I read about the partial classes on www.devx.com/dotnet/Article/22603/1954?pf=true.
357mag is offline   Reply With Quote
Old May 23rd, 2007, 12:48 AM   #8
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
Quote:
namespace Nice_Girl //this is your project name.
It's more than that, I think your project name can even be different than the namespace. I'm not very good at explaining it (perhaps one of the other members can do it). Namespaces allow for even more organization. You can even embed namespaces within each other. there are some other things it enables you to do, but I can't explain them. I never really use them too tell you the truth.

Quote:
private void button1_Click(object sender, EventArgs e)
The whole thing is an event/method. (I'm not great on terminology)
When button one gets clicked, the code in the brackets gets triggered. The object sender, EventArgs e are the arguments. In this case, the event takes on 2 arguments. It takes sender (which is an object), and e, which is a EventArgs. Everything in the whole system namespace (from what I remember) can be represented as an object (correct me if I'm wrong?). Eventargs e provides ( as described) extraarguments, for the event. Not very decriptive on my part I know. You have to explore it yourself. It all comes down to the hierarchal tree. Use the following code to see what object gets returned when you use this code under the button click event:

MessageBox.Show(sender.ToString());

Another note on arguments. it's no different from the following code:

public void test(string MyString1, string Mystring2){}

the above code is a function that does not return a value, but takes 2 strings as arguments.

Anyways, I hope that helped.
Booooze is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
EXECryptor software protection Jean5 C++ 35 Oct 10th, 2006 7:10 PM
Write Great Code Vol 1: Understanding the Machine darthsabbath Book Reviews 0 May 22nd, 2006 2:06 AM
How to post a question nnxion C++ 10 Jun 3rd, 2005 11:53 AM
How to post a question nnxion C++ 0 Jun 3rd, 2005 8:55 AM
How to post a question nnxion C 0 Jun 3rd, 2005 8:55 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:39 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC