透明表格/页面上的平滑线条 [英] Smooth line on transparent Form/Page
本文介绍了透明表格/页面上的平滑线条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在做一个工作项目。我在一个透明的页面上移动线条。
洞项目有效,但我有一个问题。线条不平滑。
我使用了SmoothingMode,它确实使线条平滑但是它留下边缘
与透明页面背景颜色相同,即Color.WhiteSmoke(不是透明)
如何使边缘透明?
Hi
I am doing a project at work. I am moving lines on a transparent page.
The hole project works but I have one problem. The lines are not smooth.
I used SmoothingMode and it does smooth the line but it leaves the edges
the same color as the transparent page background i.e. Color.WhiteSmoke (not transparent)
How do I make the edges transparent?
Public Sub New()
'Make Page Transparent and size to Mainform boundaries.
InitializeComponent()
BackColor = Color.WhiteSmoke
TransparencyKey = Color.WhiteSmoke
FormBorderStyle = Windows.Forms.FormBorderStyle.None
Size = Screen.PrimaryScreen.Bounds.Size
Location = Point.Empty
TopMost = True
End Sub
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
'Move lines on Transparent page
Dim Ax1 = 1012 - (EthernetIPforCLXComm1.ReadSynchronous("Axis1.RMCTarPosition", 1)(0) / 4.2)
Dim Ay1 = 150
Dim Ax2 = 1055 - (EthernetIPforCLXComm1.ReadSynchronous("Axis1.RMCTarPosition", 1)(0) / 2.1)
Dim Ay2 = 1130
Dim Bx1 = 1012 - (EthernetIPforCLXComm1.ReadSynchronous("Axis2.RMCTarPosition", 1)(0) / 4.2)
Dim By1 = 150
Dim Bx2 = 1055 - (EthernetIPforCLXComm1.ReadSynchronous("Axis2.RMCTarPosition", 1)(0) / 2.1)
Dim By2 = 1130
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
MyBase.OnPaint(e)
e.Graphics.DrawLine(New Pen(Color.Red, 2), New Point(Ax1, Ay1), New Point(Ax2, Ay2))
e.Graphics.DrawLine(New Pen(Color.Red, 2), New Point(Bx1, By1), New Point(Bx2, By2))
e.Graphics.DrawLine(New Pen(Color.Teal, 2), New Point(1012, 150), New Point(1055, 1130))
End Sub
推荐答案
感谢您提出有趣的问题以及所有正确的讨论和测试。这很好知道。即使我已经回答(这很难过):-),我还有另一个建议。
底线是:我已经知道支持透明度了System.Windows.Forms
绝对糟透了。你的测试只会让我的声明变得更强。现在我们知道,当你使用透明度时,即使是这样一个易于使用和平滑(在这个词的含义:-))功能中,它们也会失败。那么,该怎么办?
我的建议是:永远不要尝试使用System.Windows.Forms
的透明度,除了一个简单的用途:当你使用OnPaint
直接渲染的对象的透明颜色与System.Drawing.Graphics
时,或在位图上渲染图形。如果您确实需要任何UI元素的透明度,请切换到WPF,其中透明度始终如一。
-SA
Thank you for the interesting question and all of your correct discussions and tests. This is good to know. Even though I already answered ("this is sad") :-), I have another suggestion.
The bottom line is: I already knew that support of transparency inSystem.Windows.Forms
absolutely sucks. Your tests only makes my statement stronger. Now we know that even such an easy-to-use and smooth (in both senses of this word :-)) feature as anltialiasing fails when you use transparency. So, what to do?
My advice is: never try transparency withSystem.Windows.Forms
, except one trivial use of it: when you use transparent colors of objects rendered directly throughOnPaint
withSystem.Drawing.Graphics
, or render graphics on bitmaps. If you really need transparency on any UI elements, switch to WPF, where transparency works consistently.
—SA
这篇关于透明表格/页面上的平滑线条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文