Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to make a very primitive guitar midi player with C#.

I'm in my beginning phase and having troubles with making my design.
The problem is that my array of buttons is displayed behind my picturebox.

I tried using putting my imagebox to the back:
MIDL
//
            // pictureBox1
            //
            this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage")));
            this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.pictureBox1.InitialImage = null;
            this.pictureBox1.Location = new System.Drawing.Point(20, 100);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(624, 85);
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
            this.pictureBox1.SendToBack();


And tried to implement a bringtofront function:
C#
public void maaktabs()
        {
            int x, y;
            _tabs = new Button[6,13];
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    _tabs[i, j] = new Button();
                    _tabs[i, j].Location = new System.Drawing.Point(x, y);
                    _tabs[i, j].Size = new System.Drawing.Size(30, 30);
                    _tabs[i, j].Text = _tabsnaam[ i, j];
                    _tabs[i, j].BringToFront();
                     Controls.Add(_tabs[i, j]);
                }
            }
        }


Without any succes, so my question is how can I make my buttons go in front of my image?

Am I using these functions wrongly?
Posted
Updated 6-Dec-10 21:52pm
v2
Comments
Dalek Dave 7-Dec-10 3:52am    
Edited for Grammar and Readability.

Tip: Read on Control Z-Order

Solution1: In the VS Designer select the buttons and click on menu Format/Order/BringToFront
Solution2: As you have found out there is SendToBack and BringToFront method implemented on Controls - just call it in the right place (after you have added all your controls)
Solution3: Use the SetChildIndex method implemented on the Controls collection of your container (Form).
Solution4: Add the controls in the correct order in the first place - I learned thinking in Z-Order in the old API-days and this knowledge is useful until today :)
 
Share this answer
 
Comments
William Winner 7-Dec-10 11:38am    
yep...calling BringToFront before adding it (using Controls.Add()) doesn't do anything. You need to call it after adding it.
niko D'haes 7-Dec-10 14:21pm    
Thx, solution 3 did the trick!!!!
You're not changing x and y, meaning they are all at 0,0. You'll need to do some math to come up with height and width of the area in the picture box and of each button, then update x & y accordingly.

My guess is that there is one there?

Cheers.
 
Share this answer
 
Comments
niko D'haes 7-Dec-10 14:14pm    
no i left that part out to not make the question to big, my apolagies, next time i'll add the whole code
TheyCallMeMrJames 7-Dec-10 15:46pm    
Red herrings!!! ;) no worries.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900