Winforms应用程序中的c#填充橡皮筋

前端之家收集整理的这篇文章主要介绍了Winforms应用程序中的c#填充橡皮筋前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在不透明度为0.3的窗体上绘制零不透明橡皮筋?
(橡皮筋是在 Microsoft例之后制作的

更新:

我需要那个橡皮筋来做像面具一样的东西.如果您使用Jing或任何其他屏幕截图工具,您将在尝试制作屏幕截图时完全看到我需要做的事情:屏幕变为半透明,当您进行选择时,您将看到0不透明度选择

解决方法

这是你要找的机器人吗?
  1. public Form1()
  2. {
  3. InitializeComponent();
  4. DoubleBuffered = true;
  5. }
  6.  
  7. bool mouseDown = false;
  8. Point mouseDownPoint = Point.Empty;
  9. Point mousePoint = Point.Empty;
  10.  
  11. protected override void OnMouseDown(MouseEventArgs e)
  12. {
  13. base.OnMouseDown(e);
  14. mouseDown = true;
  15. mousePoint = mouseDownPoint = e.Location;
  16. }
  17.  
  18. protected override void OnMouseUp(MouseEventArgs e)
  19. {
  20. base.OnMouseUp(e);
  21. mouseDown = false;
  22. }
  23.  
  24. protected override void OnMouseMove(MouseEventArgs e)
  25. {
  26. base.OnMouseMove(e);
  27. mousePoint = e.Location;
  28. Invalidate();
  29. }
  30.  
  31. protected override void OnPaint(PaintEventArgs e)
  32. {
  33. base.OnPaint(e);
  34.  
  35. if (mouseDown)
  36. {
  37. Region r = new Region(this.ClientRectangle);
  38. Rectangle window = new Rectangle(
  39. Math.Min(mouseDownPoint.X,mousePoint.X),Math.Min(mouseDownPoint.Y,mousePoint.Y),Math.Abs(mouseDownPoint.X - mousePoint.X),Math.Abs(mouseDownPoint.Y - mousePoint.Y));
  40. r.Xor(window);
  41. e.Graphics.FillRegion(Brushes.Red,r);
  42. Console.WriteLine("Painted: " + window);
  43. }
  44. }

猜你在找的C#相关文章