|
-
Jan 4th, 2003, 05:04 PM
#1
Thread Starter
Hyperactive Member
Draw a button and do something when its clicked
hey i just created a button via code and how do i set it up to respond when clicked?
-
Jan 4th, 2003, 06:47 PM
#2
yay gay
Code:
Button button1 = new Button();
button1.Click += new System.Windows.Forms.Button();
this.Controls.Add(button1);
later...
Code:
private void button1_Click(object sender, System.EventArgs e)
{
}
\m/  \m/
-
Jan 5th, 2003, 02:25 AM
#3
PowerPoster
PT,
Check your event handler hookup...You need to wire it up via a delegate.
-
Jan 5th, 2003, 08:19 AM
#4
Should be
Code:
Button button1 = new Button();
button1.Click += new EventHandler(this, button1_Click);
this.Controls.Add(button1);
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 5th, 2003, 11:42 AM
#5
Frenzied Member
Actually its this 
Code:
Button button1 = new Button();
button1.Click += new EventHandler(this.button1_Click);
this.Controls.Add(button1);
Dont gain the world and lose your soul
-
Jan 5th, 2003, 11:52 AM
#6
Isn't the this added automatically?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 5th, 2003, 01:17 PM
#7
Frenzied Member
Yeah, you made a mistake with the comma afte this. It should be this.button1_click
Dont gain the world and lose your soul
-
Jan 5th, 2003, 01:31 PM
#8
yay gay
ops forgot that when i made copy past of some parts of the code...when putting all toguether i deleted the delegate i think..lol
\m/  \m/
-
Jan 5th, 2003, 02:54 PM
#9
Indeed. I thought you must pass the owner object seperatly.
Would this work?
Button button1 = new Button();
button1.Click += new EventHandler(button1_Click);
Controls.Add(button1);
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 5th, 2003, 07:07 PM
#10
-
Jan 5th, 2003, 08:27 PM
#11
Not explicitly referencing this. I wonder why people always write
this.Controls.Add...
etc.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 5th, 2003, 10:31 PM
#12
yay gay
hehe because in the IDE a combobox appears and u only have to write the first letters then
\m/  \m/
-
Jan 5th, 2003, 10:32 PM
#13
yay gay
and sometimes u dont remember well the names of the vars/methods
\m/  \m/
-
Jan 6th, 2003, 07:37 AM
#14
In this case instead of writing 'this.' simply hit Ctrl+Space. Brings up the same box.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|