面板边框设置时自动设置标签边框 [英] label border set automatically when panel border set

查看:102
本文介绍了面板边框设置时自动设置标签边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码设置面板边框颜色。

I am using this code to set panel border colour.

private void pnlmAoutput_Paint(object sender, PaintEventArgs e)
       {
           e.Graphics.DrawRectangle(Pens.Blue, e.ClipRectangle.Left, e.ClipRectangle.Top,
                                 e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1);
           base.OnPaint(e);
       }



但是当我使用这个代码时,它会为这个面板中的所有标签设置相同的边框。

我设置了backColour =对面板和所有标签透明。

我只想在面板上设置边框而不是设置为自动标签。

如果有另一种设置面板边框的方法,那么告诉我我会尝试这个。


But when i use this code it set same border to all label which are in this panel.
I set backColour= Transparent to panel and all labels.
I just want to set border at panel not set to label which take automatically.
If there is another way to set border of panel then tell me i will try this.

推荐答案

更新标签时panel_paint调用方法,但Windows足够智能,只能绘制标签周围的区域。由于您正在使用绘制事件中的边界,因此您不是在面板周围绘制一个矩形,而是围绕面板上的控件绘制它(以及初始绘制时的面板本身)。



这可能是你想要的:



When a label is updated the panel_paint method is called, except Windows is smart enough to only paint the area around the label. Since you are using the bounds in the paint events, you are not painting a rectangle around the panel, you are painting it around the controls on the panel (as well as the panel itself on initial draw).

Here is probably what you want:

e.Graphics.DrawRectangle(Pens.Blue, 0, 0, pnlmAoutput.Width - 1, pnlmAoutput.Height -1);





e.ClipRectangle是Windows告诉你究竟需要重绘的部分。如果您在面板上执行更复杂的绘图,则可以使用此信息仅重绘性能所需的区域。



由于您不是仅重绘较小的剪辑矩形,因此需要使用控件的边界。油漆边界已经相对于您的面板放置,因此您不必翻译它们(使用0,0作为左/上,而不是实际左/上)。



e.ClipRectangle is Windows telling you exactly what part needs to be redrawn. If you were doing a more complicated drawing on the panel, you could use this information to only redraw the area you need for performance.

Since you aren't redrawing just the smaller clip rectangles, you need to use the bounds of the control. The paint bounds are already placed relative to your panel, so you don't have to translate them (use 0,0 as the left/top, not the actual left/top).


这篇关于面板边框设置时自动设置标签边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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