这里似乎有100万个问题,但我找不到能工作的问题。所以,我想现在是问题1,000,001的时候了。在C#中的透明面板中绘制移动线条
我有一个自定义控件与PictureBox
和Panel
。 Panel
是具有透明背景的PictureBox
的孩子。这使我可以在PictureBox
中加载任何图像的顶部。
绘图部分工作,但删除部分没有。如果我使用Invalidate()
,我只是得到一堆闪烁,线条甚至没有显示。
如果最终目标不明显,它应该像任何像样的绘图应用程序一样工作,在该应用程序中单击一个点,拖动鼠标左键,直线移动鼠标直到您放开。
代码:
private void drawLine(Point pt) {
// Erase the last line
if (m_lastPoints != null) {
m_graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
m_graphics.DrawLine(m_transPen, m_lastPoints[0], m_lastPoints[1]);
}
// Set the last points
m_lastPoints = new Point[] { m_mouseStartPoint, pt };
m_graphics.DrawLine(new Pen(m_color), m_mouseStartPoint, pt);
}
m_transPen
被定义为new Pen(Color.FromArgb(0, 0, 0, 0));
而结果:现在
,如果我将其更改为:
m_graphics.DrawLine(Pens.White, m_lastPoints[0], m_lastPoints[1]);
我得到这个,它显示了它应该做什么,而不是白线,它们应该是透明的。
如何使用控制面? – David 2015-02-09 21:31:36
__Exactly__像你(应该)使用Panel的表面!两者都是控件,都可以绘制。最好使用“Paint”事件,在Class变量中保留Line的2个点,并在更改时使Picturebox失效。在Paint事件中使用'e.Graphics.DrawLine(..)'! – TaW 2015-02-09 21:41:38
为正确的方式绘制到一个控制看到的例子! – TaW 2015-02-09 22:01:24