Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone explain me what this code means

Status
Not open for further replies.

ehx6

IS-IT--Management
May 20, 2004
150
US
hi, is this the way to create events and
can you provide me how to create event for the following:
1. a click button .. once licked, it call another method
2. text box once have focus, will call another method
3. a checkbox once selected will call anohter method.

I guess all of them are the same?
not sure.

Page.Init += new System.EventHandler(Page_Init);
ehx
 
1.
private System.Windows.Forms.Button button1;

this.button1.Click += new System.EventHandler(this.button1_Click);

private void button1_click(object sender, System.EventArgs e)
{
//call other...
}

Or am I misunderstanding u?
 
Hello again,
What I am trying to do is to create an input form programmatically. for instance, I want to create an input form by providing the form element in a table with its datatype
id |FieldName |FieldDatatype||FieldSize
1 |id | int |
2 |fname | Varchar | 30
3. |salary |decimal |

So I need to iterate through the table and create an input form. However, I want to also create an even and its event handler in the form to call its event handler and also if I want to create more event, I want to be able to do so

The whole idea is to automate creating the forms by providing a table which contains form elements.
I hope you got the idea and you can help.
thanks again

Ehx
 
Do what AndyPandyswe says, only change the event name from [tt]button1_Click[/tt] to [tt]SomeButton_Click[/tt] in order to remind yourself that all buttons are going to end up there.

After assigning all button events to that event handler, all click events for those buttons will arrive at that handler. Once an event arrives there, you can look at the sender parameter that gets passed to you to tell which button got clicked.

The same technique works for listboxes, textboxes, etc.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks for your input, I have tried what you sugguested so I put the button declaration in the class definition, and followed it declaring an event to it. however, i am not sure if this is right.

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button Btn1; // this worked
Btn.Click += new System.EventHandler (Btn1_Click);//Error

I guess, I am not sure where to put the event declaration.
thanks for your help
Ehx


private void Btn1_Click(object sender,Syetem.EventArgs e)
{MessageBox.Show ("Created the button programmatically");
}

}// End of Class
 
Ok, I was able to write the code with no error when I compiled, however,I cannot see any button in the form when I run the app. here is my code:
I put this code in page load,
But when I run the applicatin, I see an empty form?
Howcome it does not show the button . please helpl
ehx


System.Windows.Forms.Button Btn1;
Btn1 = new System.Windows.Forms.Button();
Btn1.Location = new System.Drawing.Point(20, 20);
Btn1.Name = "Btn1";
Btn1.Text= " MyBottn";
Btn1.TabIndex = 0;
Btn1.Click+= new System.EventHandler(Btn1_Click);
Btn1.Show();
 
You should take ChipH advice. Also, have you looked at using the events for each control? It is very simple to use the "Lightning Icon" for each control to build the events and then point them to the method you plan on using. There has to be some online help on this, so nobody here has to write a tutorial (better yet, maybe there is a tutorial on this, on tek-tips)! Just do a google on building .net event handlers.

Rocco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top