PanelEx.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. namespace IntelligentControlForsx.ChildForms
  8. {
  9. public class PanelEx : Panel
  10. {
  11. /// <summary>
  12. /// OnPaintBackground 事件
  13. /// </summary>
  14. /// <param name="e"></param>
  15. protected override void OnPaintBackground(PaintEventArgs e)
  16. {
  17. // 重载基类的背景擦除函数,
  18. // 解决窗口刷新,放大,图像闪烁
  19. return;
  20. }
  21. /// <summary>
  22. /// OnPaint 事件
  23. /// </summary>
  24. /// <param name="e"></param>
  25. protected override void OnPaint(PaintEventArgs e)
  26. {
  27. // 使用双缓冲
  28. this.DoubleBuffered = true;
  29. // 背景重绘移动到此
  30. if (this.BackgroundImage != null)
  31. {
  32. e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  33. e.Graphics.DrawImage(
  34. this.BackgroundImage,
  35. new System.Drawing.Rectangle(0, 0, this.Width, this.Height),
  36. 0,
  37. 0, this.BackgroundImage.Width, this.BackgroundImage.Height, System.Drawing.GraphicsUnit.Pixel);
  38. }
  39. base.OnPaint(e);
  40. }
  41. }
  42. }