我可以在窗体上绘图,尤其是控件吗?
我可以在表单
上绘制所有控件之上吗?
我的表单上有一些控件(
文本框
、按钮
、COM对象
),并且我希望绘制ON它们,覆盖它们之前绘制的任何像素。
我在 C#
上使用 Windows 窗体
。
注意:Graphics
类在控件下绘制...
Is it possible for me to draw ABOVE all controls on a form
?
I have some controls (textboxes
, buttons
, COM objects
) on my form,
and I wish to draw ON them, overriding any pixels previously drawn by them.
I am using Windows Forms
on C#
.
NOTE: the Graphics
class draws under the controls...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道我在游戏中已经太晚了,并且接受的答案没有任何问题,但我发现它太复杂并且难以理解,所以我想出了一个“hack”。
1.使用以下代码创建自定义
Panel
。2.在
Form
上当前的每个控件上创建一个与Form
大小完全相同的TransparentPanel
,将其置于最前面,并设置其 < code>BackColor 为Transparent
,Enable
为false
。3.现在,您在
OnPaint
中绘制的所有内容都将绘制在任何控件的“上方”,并且不会“阻止”任何可交互的控件,例如TextBox
。I know I'm way too late in the game, and there is nothing wrong with the accepted answer, but I found it too complicated and somehow hard to understand, so I come up with a "hack" for it.
1. Make a custom
Panel
with the following code.2. Create a
TransparentPanel
exactly the same size as theForm
, over every control currently on theForm
, bring it to the front, and set itsBackColor
toTransparent
,Enable
tofalse
.3. Now everything you draw within
OnPaint
will be drawn "above" any controls, and it will not "block" any interactable controls such asTextBox
.