关键词搜索

源码搜索 ×
×

C# Graphics画矩形出现缺少或遮挡问题解决

发布2018-08-31浏览4013次

详情内容

下面我们以多屏画视频播放的边框为例。

错误效果:

期望效果:

  1. /// <summary>
  2. /// 绘制播放视频控件边框(0:黑色,1:绿色)
  3. /// </summary>
  4. /// <param name="color">0:黑色,1:绿色</param>
  5. public void DrawVideoBorder(int color)
  6. {
  7. // 画图对象需要每次都创建,类似初始化一个不同的画布,否则出现矩形不完整情况
  8. graphics = this.CreateGraphics();
  9. //if (graphics == null)
  10. //{
  11. // graphics = this.CreateGraphics();
  12. //}
  13. lock (graphics)
  14. {
  15. if (color == 1)
  16. {
  17. graphicsColor = Color.FromArgb(60, 255, 60);
  18. // 绿色
  19. pen = new Pen(graphicsColor);
  20. } else if (color == 2)
  21. {
  22. graphicsColor = Color.FromArgb(255, 60, 60);
  23. // 红色
  24. pen = new Pen(graphicsColor);
  25. }
  26. else
  27. {
  28. graphicsColor = Color.FromArgb(105, 105, 105);
  29. // 黑色
  30. pen = new Pen(graphicsColor);
  31. }
  32. Rectangle rect = new Rectangle();
  33. rect.X = 0;
  34. rect.Y = 0;
  35. rect.Width = this.Width - 3;
  36. rect.Height = this.Height - 3;
  37. rect.Location = new Point(0,0);
  38. graphics.DrawRectangle(pen, rect);
  39. }
  40. }

请注意看注释行处的说明。

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载