在我的图片框前显示一系列按钮 [英] bringing an array of buttons in front of my picturebox

查看:90
本文介绍了在我的图片框前显示一系列按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用C#制作一个非常原始的吉他Midi播放器.

我正处于起步阶段,在设计时遇到麻烦.
问题是我的按钮阵列显示在图片框的后面.

我尝试使用将图像框放在后面:

 //  
            //  pictureBox1 
            //  
            this.pictureBox1.BackgroundImage =((System.Drawing.Image)(resources.GetObject(" )));
            this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.pictureBox1.InitialImage = null;
            this.pictureBox1.Location = new System.Drawing.Point(20, 100 );
            this.pictureBox1.Name = " ;
            this.pictureBox1.Size =新的System.Drawing.Size(624, 85 );
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            this.pictureBox1.Click + =新的System.EventHandler(this.pictureBox1_Click);
            this.pictureBox1.SendToBack(); 



并尝试实现前摄功能:

 公共  void  maaktabs()
        {
             int  x,y;
            _tabs = 按钮[ 6  13  ];
             for ( int  i =  0 ; i <   6 ; i ++)
            {
                 for ( int  j =  0 ; j <   13 ; j ++)
                {
                    _tabs [i,j] =  Button();
                    _tabs [i,j] .Location =  System.Drawing.Point(x,y);
                    _tabs [i,j] .Size =  System.Drawing.Size( 30  30 );
                    _tabs [i,j] .Text = _tabsnaam [i,j];
                    _tabs [i,j] .BringToFront();
                     Controls.Add(_tabs [i,j]);
                }
            }
        } 



没有任何成功,所以我的问题是如何使按钮位于图像的前面?

我是否错误地使用了这些功能?

解决方案

提示:在控件Z顺序上阅读

解决方案1:在VS Designer中,选择按钮,然后单击菜单Format/Order/BringToFront
解决方案2:正如您发现的那样,在控件上实现了SendToBackBringToFront方法-只需在正确的位置调用它(添加所有控件后即可)
解决方案3:使用在容器(窗体)的控件集合上实现的SetChildIndex方法.
解决方案4:首先以正确的顺序添加控件-我在旧的API时代学会了Z-Order的思维方式,直到今天,这种知识仍然有用:)不要更改x和y,这意味着它们都为0,0.您需要做一些数学运算才能得出图片框中区域和每个按钮的高度和宽度,然后相应地更新x和y.

我的猜测是那边有一个吗?

干杯.


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:

//
            // 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:

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?

解决方案

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 :)


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.


这篇关于在我的图片框前显示一系列按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆