Click here to Skip to main content
16,007,885 members
Home / Discussions / C#
   

C#

 
GeneralRe: .NET IDE c# Pin
Anonymous11-Dec-03 2:33
Anonymous11-Dec-03 2:33 
GeneralRe: .NET IDE c# Pin
Charlie Williams11-Dec-03 16:11
Charlie Williams11-Dec-03 16:11 
GeneralRe: .NET IDE c# Pin
Philip Fitzsimons11-Dec-03 2:33
Philip Fitzsimons11-Dec-03 2:33 
GeneralRe: .NET IDE c# Pin
Hovel11-Dec-03 2:37
Hovel11-Dec-03 2:37 
GeneralRichTextBox: Get the current text-cursor-position (pixel) Pin
kalwar11-Dec-03 0:34
kalwar11-Dec-03 0:34 
GeneralRe: RichTextBox: Get the current text-cursor-position (pixel) Pin
Heath Stewart11-Dec-03 4:08
protectorHeath Stewart11-Dec-03 4:08 
Questionbutten_click event trigging a method in a different class? Pin
thomasa10-Dec-03 22:51
thomasa10-Dec-03 22:51 
AnswerRe: butten_click event trigging a method in a different class? Pin
Heath Stewart11-Dec-03 3:49
protectorHeath Stewart11-Dec-03 3:49 
You could add an event to the Panel class, then have the Panel handle all the Button.Click events, which fires the event you added. Done right, the form containing the panel could access the button (the first parameter in any EventHandler-derived delegate is the object that raised the event). You could even make your own delegate (instead of using the EventHandler delegate) if you don't want to worry about casting:
public delegate void ButtonEventHandler(Button sender, EventArgs e);
public class MyPanel : Panel
{
  public MyPanel()
  {
    // Initialize controls.
    button1.Click += new EventHandler(this.button_Click);
    button2.Click += new EventHandler(this.button_Click);
    // ...
  }
 
  public event ButtonEventHandler ButtonClick;
 
  private void button_Click(object sender, EventArgs e)
  {
    if (this.ButtonClick != null)
      this.ButtonClick(sender as Button, e);
  }
}
Then, any button click event is handled by the panel, which then fires it's own event. Note (as I mentioned above), you oculd just stick with the EventHandler delegate for your event, but then your containing Form will have to type-cast the sender each time (making sure that it is a button, of course). Even in the code above, though, your Form should make sure sender isn't null (always better to be safe than sorry).

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
Generaldisplay word file on form Pin
hazzem elrefai10-Dec-03 22:33
hazzem elrefai10-Dec-03 22:33 
GeneralRe: display word file on form Pin
Stephane Rodriguez.10-Dec-03 23:05
Stephane Rodriguez.10-Dec-03 23:05 
GeneralRe: display word file on form Pin
hazzem elrefai10-Dec-03 23:55
hazzem elrefai10-Dec-03 23:55 
GeneralRe: display word file on form Pin
Stephane Rodriguez.11-Dec-03 0:39
Stephane Rodriguez.11-Dec-03 0:39 
GeneralRe: display word file on form Pin
hazzem elrefai11-Dec-03 1:03
hazzem elrefai11-Dec-03 1:03 
GeneralRe: display word file on form Pin
Vocjeny11-Dec-03 1:58
Vocjeny11-Dec-03 1:58 
GeneralRe: display word file on form Pin
Heath Stewart11-Dec-03 3:37
protectorHeath Stewart11-Dec-03 3:37 
GeneralRe: display word file on form Pin
Guillermo Rivero11-Dec-03 4:22
Guillermo Rivero11-Dec-03 4:22 
GeneralRe: display word file on form Pin
Guillermo Rivero11-Dec-03 4:28
Guillermo Rivero11-Dec-03 4:28 
GeneralRe: display word file on form Pin
hazzem elrefai12-Dec-03 10:29
hazzem elrefai12-Dec-03 10:29 
GeneralRe: display word file on form Pin
hazzem elrefai12-Dec-03 13:57
hazzem elrefai12-Dec-03 13:57 
GeneralRe: display word file on form Pin
Guillermo Rivero13-Dec-03 11:22
Guillermo Rivero13-Dec-03 11:22 
GeneralRe: display word file on form Pin
hazzem elrefai13-Dec-03 12:55
hazzem elrefai13-Dec-03 12:55 
Generalnamespace curiosity Pin
Member 76049710-Dec-03 21:39
Member 76049710-Dec-03 21:39 
GeneralRe: namespace curiosity Pin
Heath Stewart11-Dec-03 3:27
protectorHeath Stewart11-Dec-03 3:27 
General"database wizard" Pin
brain2cpu10-Dec-03 21:39
professionalbrain2cpu10-Dec-03 21:39 
GeneralRe: "database wizard" Pin
Heath Stewart11-Dec-03 3:24
protectorHeath Stewart11-Dec-03 3:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.