PC Review


Reply
Thread Tools Rate Thread

C# form events

 
 
Arne Garvander
Guest
Posts: n/a
 
      22nd Sep 2008
How do I set an event handler in C#?
The code below does not seem to fire.
private void Form1_Load(object sender, System.EventArgs e)
{
int i = 1;
}

--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      22nd Sep 2008
Arne Garvander <(E-Mail Removed)> wrote:
> How do I set an event handler in C#?
> The code below does not seem to fire.
> private void Form1_Load(object sender, System.EventArgs e)
> {
> int i = 1;
> }


You need to subscribe to the event, e.g.

Load += Form1_Load;

(in the constructor, for example). In the designer, you can click on
the lightning bolt to make it hook up the events for you.

--
Jon Skeet - <(E-Mail Removed)>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
 
Reply With Quote
 
Jibesh
Guest
Posts: n/a
 
      3rd Oct 2008
event subscription code looks like the this.

//Constructor
Form1()
{
this.Load += new System.EventHandler(this.Form1_Load);
}
private void Form1_Load(object sender, System.EventArgs e)
{
int i = 1;
}

"Arne Garvander" <(E-Mail Removed)> wrote in message
news:9873576A-C5D6-4345-BA9D-(E-Mail Removed)...
> How do I set an event handler in C#?
> The code below does not seem to fire.
> private void Form1_Load(object sender, System.EventArgs e)
> {
> int i = 1;
> }
>
> --
> Arne Garvander
> (I program VB.Net for fun and C# to get paid.)



 
Reply With Quote
 
kimiraikkonen
Guest
Posts: n/a
 
      19th Oct 2008
On Sep 22, 7:36*pm, Arne Garvander
<ArneGarvan...@discussions.microsoft.com> wrote:
> How do I set an event handler in C#?
> The code below does not seem to fire.
> private void Form1_Load(object sender, System.EventArgs e)
> {
> * * int i = 1;
>
> }
>
> --
> Arne Garvander
> (I program VB.Net for fun and C# to get paid.)


To register event dynamically:
this.Load new System.Eventhandler(this.Form1_Load);

and subscibing the form's load event handler can simply be done by
double-clicking on your form and it'll be generated by VS for you.

However, you'll notice that, it's stored in Form1.Designer.cs file as
you may want to check out at anytime.

HTH,

Onur Güzel
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form sync via custom events independent of order of form opening =?Utf-8?B?Sm9obiBG?= Microsoft Access Form Coding 1 5th Dec 2006 09:38 AM
Form Open canceled -- but other form's events are executed. Michel S. Microsoft Access 9 15th Aug 2006 05:59 AM
how to cancel events for controls on a form when the form is closi =?Utf-8?B?ZGNobWFu?= Microsoft C# .NET 2 12th Jun 2006 05:06 AM
Form code events are not fired when editing an item based on the form Pau Larsen Microsoft Outlook Form Programming 3 9th Sep 2004 12:05 PM
Catch Outlook Form and Form Control Events in C++ Nauman Khan Microsoft Outlook Program Addins 2 16th Aug 2004 09:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:37 AM.