samedi 9 janvier 2016

Sort array of buttons programmatically in c#

Vote count: 0

I have a big number of buttons added programatically by user. Buttons are created by x and y number (user inputs them). For each x there is an y button. So, if my x number is 2, and y number is 3 then I will have buttons named and inserted on form like:

enter image description here

Now, how can I, using two FOR statements, position buttons on the form like: enter image description here

This is my code so far:

int left = 50;
int top = 50;
int all_zd=x*y;
        Button[] btn_arr = new Button[all_zd];
         for (int i = 1; i <=y; i++ ) 

                    {
                        for (int j = 1; j <= x; j++)
                        {
                            //Button btn = new Button();
                            btn_arr[j] = new Button();
                            {
                                btn_arr[j].Name = j.ToString() + "t" + i.ToString();
                                btn_arr[j].Text = j.ToString() + "ff" + i.ToString();
                                btn_arr[j].Height = 20;
                                btn_arr[j].Width = 50;
                                btn_arr[j].Location = new Point(left,top);
         top += btn_arr[j].Height + 2; 
        this.Controls.Add(btn_arr[j]);}}

maybe if statement?

if ((i == 1 && j % x == 1) top+= btn_arr[j].Height + 2;

Please, help, I'm really having trouble with this. Thank you in advance

asked 52 secs ago

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.



Sort array of buttons programmatically in c#

Aucun commentaire:

Enregistrer un commentaire