![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#2 |
|
Expert Programmer
|
csharp Syntax (Toggle Plain Text)
does that help?
__________________
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#4 |
|
Expert Programmer
|
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.
__________________
|
|
|
|
|
|
#5 | |
|
Programmer
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
Actually I have the C# Primer Plus book by Klaus Michelsen. But in that book he just deals with the core language.
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
I read about the partial classes on www.devx.com/dotnet/Article/22603/1954?pf=true.
|
|
|
|
|
|
#8 | ||
|
Expert Programmer
|
Quote:
Quote:
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. |
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |