Click here to Skip to main content
15,894,343 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# variables with variabel part Pin
Josh Smith2-May-06 10:18
Josh Smith2-May-06 10:18 
GeneralRe: C# variables with variabel part Pin
JelleM2-May-06 10:23
JelleM2-May-06 10:23 
GeneralRe: C# variables with variabel part Pin
Ravi Bhavnani2-May-06 12:47
professionalRavi Bhavnani2-May-06 12:47 
GeneralRe: C# variables with variabel part Pin
JelleM3-May-06 5:05
JelleM3-May-06 5:05 
GeneralRe: C# variables with variabel part Pin
Larantz3-May-06 10:42
Larantz3-May-06 10:42 
GeneralRe: C# variables with variabel part Pin
JelleM3-May-06 10:55
JelleM3-May-06 10:55 
GeneralRe: C# variables with variabel part Pin
Larantz4-May-06 7:55
Larantz4-May-06 7:55 
GeneralRe: C# variables with variabel part Pin
Larantz4-May-06 9:54
Larantz4-May-06 9:54 
I tried the code now to be sure that it doesn't fail.
I couldn't get the buttons to show without a panel.
So, add a panel in Design View. Set Dock to 'Top'.

Then in Code View, inside the loop, add
"'panelname'.Controls.Add(myButtonList[i]);"
and they will show.

private void InitializeButtonArray()
{
   //I turned the forloop to reduce 'i' instead of increasing it
   //since the buttons got listed in reverse.

   for(int i = totaal-1; i >= 0; i--)
   {         
      myButtonList[i] = new Button();
      myButtonList[i].Location = new System.Drawing.Point(i*10, 10);
      myButtonList[i].Dock = System.Windows.Forms.DockStyle.Left;
      myButtonList[i].Name = "Button" + (i + 1);
      myButtonList[i].TabIndex = i;
      myButtonList[i].Text = "" + (i + 1);

      //Try different buttonsizes that fits your form.
      myButtonList[i].Width = 25;

      //I named my panel 'panelHeader'
      this.panelHeader.Controls.Add(myButtonList[i]);
      myButtonList[i].Click += new System.EventHandler(this.myButtonList_Click);
   }
}


You also need a working button_click event handler method.

private void myButtonList_Click(object sender, System.EventArgs e)
{
   switch(((Button)sender).Name)
   {
      case "Button1":
         MessageBox.Show((Button)sender).Name //just to do something
         break;

      case "Button2":
         //do something else;
         break;

      //etc etc though this is kinda hairy since you dont know how many
      //buttons you'll have.
      default:
         //...
         break;
   }
}


This code added 20 buttons on my form that all called the button_click event handler method, and I could identify the caller and perform actions.

-Larantz-
QuestionHovering Mouse Pin
IceWater422-May-06 8:24
IceWater422-May-06 8:24 
AnswerRe: Hovering Mouse Pin
Pablo Hernandez Valdes2-May-06 8:40
Pablo Hernandez Valdes2-May-06 8:40 
GeneralRe: Hovering Mouse Pin
IceWater422-May-06 12:24
IceWater422-May-06 12:24 
Questionhow to SetParameterValue to crystal sub-report using c# Pin
shabonaa2-May-06 8:01
shabonaa2-May-06 8:01 
QuestionBacking up my source Pin
Tom Wright2-May-06 7:16
Tom Wright2-May-06 7:16 
QuestionReports using Business Object in C# Pin
Neel072-May-06 6:54
Neel072-May-06 6:54 
AnswerRe: Reports using Business Object in C# Pin
shabonaa2-May-06 8:46
shabonaa2-May-06 8:46 
QuestionForm flicks when resize on Timer_Tick Pin
freshonlineMax2-May-06 6:49
freshonlineMax2-May-06 6:49 
AnswerRe: Form flicks when resize on Timer_Tick Pin
CWIZO2-May-06 8:42
CWIZO2-May-06 8:42 
QuestionObject Reference Error while accessing a treenode from a context menu event Pin
Jonathen Scalet2-May-06 5:57
Jonathen Scalet2-May-06 5:57 
AnswerRe: Object Reference Error while accessing a treenode from a context menu event Pin
Judah Gabriel Himango2-May-06 6:03
sponsorJudah Gabriel Himango2-May-06 6:03 
GeneralRe: Object Reference Error while accessing a treenode from a context menu event Pin
J0nScalet2-May-06 6:14
J0nScalet2-May-06 6:14 
GeneralRe: Object Reference Error while accessing a treenode from a context menu event Pin
Judah Gabriel Himango2-May-06 6:33
sponsorJudah Gabriel Himango2-May-06 6:33 
Questionvedio and powerpoint Pin
walaa ibraheem2-May-06 5:26
walaa ibraheem2-May-06 5:26 
AnswerRe: vedio and powerpoint Pin
Judah Gabriel Himango2-May-06 5:55
sponsorJudah Gabriel Himango2-May-06 5:55 
QuestionRefactoring question (performance) Pin
gantww2-May-06 5:25
gantww2-May-06 5:25 
AnswerRe: Refactoring question (performance) Pin
Judah Gabriel Himango2-May-06 6:01
sponsorJudah Gabriel Himango2-May-06 6:01 

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.