http://blog.sina.com.cn/s/blog_402c071e0102x4rl.html

 
 以下内容,对于想要使用C#实现PNG图片背景透明显示,同时动态显示时无闪烁问题的人来说,是非常有帮助的。网络上很难找到完整的解决方案。以下是我搜集到,并加以验证过的完整解决方案。
文章一:
《How to Use Transparent Images and Labels in Windows
Forms》
《在Windows Forms 中怎样使用透明图片和透明标签》
     
  这篇文章,提供了C#例程,讲解非常清楚,代码非常好。
 
文章二:
  《C#画图解决闪烁问题》之《使用 GDI+ 双缓冲 解决绘图闪烁问题》
 
以下是文章部分内容:
使用 GDI+ 双缓冲 解决绘图闪烁问题
现在的问题是很多人不知道怎么怎么使用GDI+ 双缓冲
 
public partial class Form1 : Form
    {
     
  //记录矩形位置的变量
     
  Point p = Point .Empty ;
     
  Point location = new Point(0, 0);
     
  int x = 0;
     
  int y = 0;
 
     
  public Form1()
     
  {
     
     
InitializeComponent();
     
     
//采用双缓冲技术的控件必需的设置
     
     
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
     
     
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
     
     
this.SetStyle(ControlStyles.UserPaint, true);
     
  }
     
  protected override void OnPaint(PaintEventArgs
e)
     
  {
     
     
base.OnPaint(e);
     
      Graphics g
= e.Graphics;
     
     
g.FillRectangle(Brushes.Black, x, y, 200, 200);
     
  }
     
  private void Form1_MouseDown(object sender,
MouseEventArgs e)
     
  {
     
      if
(e.Button == MouseButtons.Right) return;
     
      p =
e.Location;
     
  }
     
  private void Form1_MouseUp(object sender,
MouseEventArgs e)
     
  {
     
      if
(e.Button == MouseButtons.Right) return;
     
      location.X
+= e.X - p.X;
     
      location.Y
+= e.Y - p.Y;
     
      p =
Point.Empty;
     
  }
     
  private void Form1_MouseMove(object sender,
MouseEventArgs e)
     
  {
     
   if (p == Point.Empty)
return;
     
      x = e.X -
p.X + location.X;
     
      y = e.Y -
p.Y + location.Y;
     
     
this.Invalidate(true);//触发Paint事件
     
  }
   
 }
这个简单的例子实现了用鼠标拖动窗口中矩形,利用双缓冲技术使动画过程不会产生闪烁.

最新文章

  1. Debian8 从本地源安装软件
  2. Objective-C中的继承和多态
  3. 交易B(队列)
  4. 使用IntelliJ IDEA编写Scala在Spark中运行
  5. A标签执行js 代码和跳转
  6. 中文字体在CSS中的表达方式
  7. Python 列表生成式、生成器、迭代器
  8. Umbraco扩展开发
  9. ACdream: Sum
  10. Case learning
  11. TypeScript -- 面向对象特性
  12. wow.js中各种特效对应的类名
  13. <转>LOG日志级别
  14. 【转】 awk 学习笔记
  15. java jdbc ResultSet结果通过java反射赋值给java对象
  16. Python之进程 1 - 基本概念
  17. apache2.4 文件浏览服务器页面配置
  18. zookeeper.Net
  19. Robot Movement(机器人移动)
  20. React-router4 第二篇url-params url参数

热门文章

  1. CSUOJ 1956 数字和
  2. CLR基础
  3. 表格插件datatables
  4. thinkphp5使用redis
  5. 使用 Nexus 搭建私服仓库时我犯的一个小错误
  6. 【BZOJ】4565: [Haoi2016]字符合并
  7. bzoj 1176
  8. BZOJ 1008 [HNOI2008]越狱 排列组合
  9. LNMP环境下打击那搭建Bugfree
  10. antd 父组件获取子组件中form表单的值