Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralCOM interop reference problem Pin
vladll4-Feb-04 23:33
vladll4-Feb-04 23:33 
GeneralRe: COM interop reference problem Pin
Heath Stewart5-Feb-04 4:52
protectorHeath Stewart5-Feb-04 4:52 
GeneralRe: COM interop reference problem Pin
vladll5-Feb-04 5:38
vladll5-Feb-04 5:38 
GeneralRe: COM interop reference problem Pin
Heath Stewart5-Feb-04 6:58
protectorHeath Stewart5-Feb-04 6:58 
GeneralRe: COM interop reference problem Pin
vladll5-Feb-04 7:06
vladll5-Feb-04 7:06 
GeneralRe: COM interop reference problem Pin
Heath Stewart5-Feb-04 8:58
protectorHeath Stewart5-Feb-04 8:58 
GeneralSelecting buttons Pin
Megastoffel4-Feb-04 23:30
Megastoffel4-Feb-04 23:30 
GeneralRe: Selecting buttons Pin
Member 2611885-Feb-04 0:11
Member 2611885-Feb-04 0:11 
What about using two global variables (or an array, even better), and a counter. Then, when one button is clicked, the reference to the instance is saved in the first position, and when another button is clicked, it is saved in the second. Like this:
public class MyClass
{
  // Initialize a new array with a length of two (thus index 0 and 1):
  private Button[] _buttons = new Button[2];
  private int _counter = 0;
  
  // Handle the events of your buttons.
  public MyClass()
  {
    MyButton1.Click += new EventHandler(Button_Click);
    MyButton2.Click += new EventHandler(Button_Click);
    MyButton3.Click += new EventHandler(Button_Click);
    // Etc...
  }
  
  private void Button_Click(object sender, EventArgs e)
  {
    // Assign your button to the array,
    _buttons[_counter] = (Button)sender;
    // and increase the counter by 1.
    _counter++;
  }
}


Instead of manually assigning the events to your buttons in the class' constructor, you may want to use the Form-designer to do that. Just copy-and-paste the name of the method that handles the event in the field next to 'Click' on the 'Events' tab of the propertygrid of your buttons.

Don't forget to reset the counter (_counter = 0) when you're finished, or add a check to see whether _counter > _buttons.Length - 1, then:
if (_counter > _buttons.Length - 1) _counter = 0;

GeneralRe: Selecting buttons Pin
Megastoffel5-Feb-04 7:38
Megastoffel5-Feb-04 7:38 
GeneralPrintPreviewDialog Pin
Reinier van de Wetering4-Feb-04 22:25
Reinier van de Wetering4-Feb-04 22:25 
Generalconversion to pdf Pin
mohdshiraz4-Feb-04 19:11
mohdshiraz4-Feb-04 19:11 
GeneralRe: conversion to pdf Pin
John Kuhn4-Feb-04 19:37
John Kuhn4-Feb-04 19:37 
GeneralRe: conversion to pdf Pin
mohdshiraz4-Feb-04 19:46
mohdshiraz4-Feb-04 19:46 
GeneralRe: conversion to pdf Pin
John Kuhn4-Feb-04 19:56
John Kuhn4-Feb-04 19:56 
GeneralRe: conversion to pdf Pin
Gerald Leslie Jones4-Feb-04 20:05
Gerald Leslie Jones4-Feb-04 20:05 
GeneralRe: conversion to pdf Pin
Heath Stewart5-Feb-04 4:45
protectorHeath Stewart5-Feb-04 4:45 
GeneralRe: conversion to pdf Pin
mohdshiraz5-Feb-04 0:43
mohdshiraz5-Feb-04 0:43 
GeneralWhat's Wrong Pin
Inam4-Feb-04 17:58
Inam4-Feb-04 17:58 
Generalno instantiate Pin
rod termaat4-Feb-04 17:24
rod termaat4-Feb-04 17:24 
GeneralRe: no instantiate Pin
Tom Clement4-Feb-04 17:39
professionalTom Clement4-Feb-04 17:39 
GeneralRe: no instantiate Pin
Not Active4-Feb-04 18:09
mentorNot Active4-Feb-04 18:09 
GeneralRe: no instantiate Pin
boogs5-Feb-04 2:48
boogs5-Feb-04 2:48 
GeneralRe: no instantiate Pin
Heath Stewart5-Feb-04 4:42
protectorHeath Stewart5-Feb-04 4:42 
QuestionRichTextBox has a bug? Pin
Zembaliti4-Feb-04 14:56
Zembaliti4-Feb-04 14:56 
AnswerRe: RichTextBox has a bug? Pin
Nick Parker4-Feb-04 16:50
protectorNick Parker4-Feb-04 16:50 

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.