带来的WinForms控制前 [英] Bring Winforms control to front

查看:95
本文介绍了带来的WinForms控制前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有带来控制向前方以外control.BringToFront()的任何其他方法?我有一系列标签上的用户控件,当我试图将其中一人面前它不工作。我甚至通过所有的控制循环,并送他们除了一个我很感兴趣,所有的回来了,它不会改变任何事情。

下面是其中标签被添加到用户控制的方法

 私人无效AddUserLabel()
{
    UserLabel场=新UserLabel();
    ++ fieldNumber;    field.Name =田+ fieldNumber.ToString();    field.Top = field.FieldTop + fieldNumber;
    field.Left = field.FieldLeft + fieldNumber;
    field.Height = field.FieldHeight;
    field.Width = field.FieldWidth;
    field.RotationAngle = field.FieldRotation;
    field.Bar code = field.Bar codeD;
    field.HumanReadable = field.HumanReadable;
    field.Text = field.FieldText;
    field.ForeColor = Color.Black;    field.MouseDown + =新MouseEventHandler(label_MouseDown);
    field.MouseUp + =新MouseEventHandler(label_MouseUp);
    field.MouseMove + =新MouseEventHandler(label_MouseMove);    userContainer.Controls.Add(场);    SendLabelsToBack(); //发送所有标签背    userContainer.Controls [field.FieldName] .BringToFront();
}

下面是发送所有的人都到后面的方法。

 私人无效SendLabelsToBack()
{
    的foreach(在userContainer.Controls UserLabel LBL)
    {
        lbl.SendToBack();
    }
}


解决方案

是啊,有另一种方式。在 Controls.SetChildIndex()也改变Z顺序。索引为0的一个是在顶部的之一。不买任何东西,虽然, BringToFront()使用此方法。

SendLabelsToBack()方法给出不能工作,这也将发送标签添加到后面。但是,你的下一个语句修复一遍。

好吧,这是不行的,这意味着 BringToFront()方法没有得到执行。看在输出窗口中的第一次机会异常的通知。由于写的,你的 SendLabelsToBack()将如果用户控件包含比UserLabel其他任何控制导致异常。此外,设置一个断点的之后的的 BringToFront()电话和检查 userContainer.Controls值[0] .Name点时,它打破了。

Are there any other methods of bringing a control to the front other than control.BringToFront()? I have series of labels on a user control and when I try to bring one of them to front it is not working. I have even looped through all the controls and sent them all the back except for the one I am interested in and it doesn't change a thing.

Here is the method where a label is added to the user control

private void AddUserLabel()
{
    UserLabel field = new UserLabel();
    ++fieldNumber;

    field.Name = "field" + fieldNumber.ToString();         

    field.Top = field.FieldTop + fieldNumber;
    field.Left = field.FieldLeft + fieldNumber;
    field.Height = field.FieldHeight;
    field.Width = field.FieldWidth;
    field.RotationAngle = field.FieldRotation;
    field.Barcode = field.BarCoded;
    field.HumanReadable = field.HumanReadable;
    field.Text = field.FieldText;
    field.ForeColor = Color.Black;

    field.MouseDown += new MouseEventHandler(label_MouseDown);
    field.MouseUp += new MouseEventHandler(label_MouseUp);
    field.MouseMove += new MouseEventHandler(label_MouseMove);

    userContainer.Controls.Add(field);

    SendLabelsToBack(); //Send All labels to back

    userContainer.Controls[field.FieldName].BringToFront();
}

Here is the method that sends all of them to the back.

private void SendLabelsToBack()
{
    foreach (UserLabel lbl in userContainer.Controls)
    {
        lbl.SendToBack();
    }
}

解决方案

Yeah, there's another way. The Controls.SetChildIndex() also changes Z-order. The one with index 0 is the one on top. Doesn't buy you anything though, BringToFront() uses this method.

Your SendLabelsToBack() method as given cannot work, it will also send the label to added to the back. But your next statement fixes that again.

Okay, that doesn't work, which means the BringToFront() method doesn't get executed. Look in the Output window for a "first chance exception" notification. As written, your SendLabelsToBack() will cause an exception if the user control contains any control other than a UserLabel. Also, set a breakpoint after the BringToFront() call and check the value of userContainer.Controls[0].Name when it breaks.

这篇关于带来的WinForms控制前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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