| | |
Quick question in Visual C#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2009
Posts: 1
Reputation:
Solved Threads: 0
Hi, a noob programmer just starting in C# with Visual Studio here....
I came across this while coding in Visual C# and I couldn't figure out anything about it so a little explanation would be greatly appreciated....
In Microsoft's Visual C#...when using Windows Forms for GUI.....
You guys know how there's a Design view and a Code view?,
and let's say you create a button1 on the Design view, and if you double click that on the Design view, Visual C# automatically generates an event handler linked to that button on the Code view like....
private void button1_Click(object sender, EventArgs e){
}
this might be a dumb question but I tried copying that code above and just pasted it into the Code view INSTEAD of letting it generate from the doubl-clicking and when I ran the program, the button didn't work.........Why is that???
The button's function only works if I generate the code by double-clicking it....
I'm guessing when you double click the button there's more to it than just the code automatically being generated?
Any explanation would be great.
Thank you guys.
I came across this while coding in Visual C# and I couldn't figure out anything about it so a little explanation would be greatly appreciated....
In Microsoft's Visual C#...when using Windows Forms for GUI.....
You guys know how there's a Design view and a Code view?,
and let's say you create a button1 on the Design view, and if you double click that on the Design view, Visual C# automatically generates an event handler linked to that button on the Code view like....
private void button1_Click(object sender, EventArgs e){
}
this might be a dumb question but I tried copying that code above and just pasted it into the Code view INSTEAD of letting it generate from the doubl-clicking and when I ran the program, the button didn't work.........Why is that???
The button's function only works if I generate the code by double-clicking it....
I'm guessing when you double click the button there's more to it than just the code automatically being generated?
Any explanation would be great.
Thank you guys.
There's some other code generated that refers to the button1_Click method -- look around for it, it's probably folded up somewhere. I can guarantee that simply adding that method is unsufficient to put an event handler in place.
Edit:
Right click the method when it's auto-generated, and click "Find All References" -- that'll show you where the method is getting used.
Edit:
Right click the method when it's auto-generated, and click "Find All References" -- that'll show you where the method is getting used.
Last edited by Rashakil Fol; Mar 9th, 2009 at 9:45 pm.
All my posts may be redistributed under the GNU Free Documentation License.
•
•
Join Date: Jul 2008
Posts: 47
Reputation:
Solved Threads: 0
C# Syntax (Toggle Plain Text)
this.button1.Click += new System.EventHandler(this.button1_Click);
this will do the trick for you
•
•
Join Date: Apr 2008
Posts: 45
Reputation:
Solved Threads: 10
If you've ever expanded the file for a form in the list view in your solution explorer pane, you should see two files below the main Form source file. There should be a [form_name].Designer.cs (or whatever language). Inside that file is where it handles setting all of the properties for your controls. This is also where the event handlers get wired up as mentioned in the other posts.
![]() |
Similar Threads
- quick question about vectors (C++)
- quick question (MS SQL)
- Quick Question: Is J# the same thing as Java? (Java)
- Code for Call the program in Visual Basic (Visual Basic 4 / 5 / 6)
- A quick question (Game Development)
- Urgent Word VBA Assistance (Windows NT / 2000 / XP)
- quick question (C#)
Other Threads in the C# Forum
- Previous Thread: hi : removing the zeroes
- Next Thread: Regexp whitespace problem
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format formatting forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot marshalbyrefobject math mouseclick mysql networking object operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






