如何在其他两个现有面板上创建一个透明的 System.Windows.Forms.Panel,然后在透明面板上画一条线?
我正在用 C# 编写一个表单,并且有几个面板。我需要在两个面板之间画一条线。我在网上找到了几种解决此问题的方法,最有希望的似乎是创建第三个面板,使其透明,将其放置在原始面板的顶部并在此处画线。
即使我将其 BackColor 和 ForeColor 属性设置为透明(在代码中或在 VS 的设计视图中),我也无法使面板变得透明。
关于如何使面板本身透明(或不可见)但我在其上绘制的线在其他所有内容之上仍然可见的任何想法?
提前致谢。
I'm writing a form in C# and have several panels. I need to draw a line between two of the panels. I've found online several ways to go about this, the most promising appears to be to create a third panel, make it transparent, place it on top of my original panels and draw the line here.
I'm not able to get the panel to be transparent, even if I set its BackColor and ForeColor properties to transparent (in code or in design view of VS).
Any ideas on how to make the panel itself transparent (or not Visible) but have the line I draw on it still visible on top of everything else?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,它是透明的。通过给表单的BackgroundImage 一个值来查看这一点。您可以通过透明面板看到它。当然,这不是您想要的透明度,您想要叠加效果。对此没有直接支持。
如果您希望图层正常工作,请不要使用控件。使用 Paint 事件进行绘制。现在没问题了,如果你想要透明度那就不要画了。只需先绘制图像即可在图像上绘制一条线。这也是WPF的渲染模型。
No, it's transparent. See this by giving the form's BackgroundImage a value. You'll see it through the transparent panel. Of course, that's not the kind of transparency you want, you want stacking effects to work. There is no direct support for that.
If you want layers to work then don't use controls. Use the Paint event to draw. Now there's no problem, if you want transparency then just don't paint. Draw a line across an image simply by drawing the image first. This is also the rendering model of WPF.
实际上,您可以通过自己的用户控件轻松地完成此操作。这是一个代码示例:
在顶部绘图面板内的控件 (C# WinForms)
这与您最初尝试执行的操作类似,只是此代码不是在透明面板顶部绘制一条线,而是创建一个不规则形状的用户控件(这会发生)呈不规则形状的线)。
You can actually do this pretty easily as your own UserControl. Here's a code example:
Drawing on top of controls inside a panel (C# WinForms)
This is similar to what you were originally attempting to do, only instead of drawing a line on top of a transparent panel, this code creates an irregularly-shaped user control (which happens to be in the irregular shape of a line).