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事件
     
  }
   
 }
这个简单的例子实现了用鼠标拖动窗口中矩形,利用双缓冲技术使动画过程不会产生闪烁.

C# 实现PNG文件的背景透明显示,解决动态显示闪烁问题 【转】的更多相关文章

  1. TortoiseSVN文件夹及文件状态图标不显示解决方法

    win8 64位系统,原本svn是好用的,安装了klive金山快盘后,svn图标都不显示了.最后通过修改注册表解决: win+R调出运行框,输入regedit,打开注册表编辑器. HKEY_LOCAL ...

  2. iOS UITableViewCell点击时子视图背景透明的解决方法

    在做iOS项目的开发中,UITableView控件的应用十分广泛.在进行自定义UITableViewCell时,经常遇到这样的问题:在UITableViewCell上面添加了一个有背景颜色的子视图,当 ...

  3. QSplashScreen无法背景透明的解决办法(强制StyleSheet生效)

    setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen | Qt::FramelessWindowHint); setAttribute( ...

  4. QSplashScreen无法背景透明的解决办法

    setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen | Qt::FramelessWindowHint); setAttribute( ...

  5. 使IE6下PNG背景透明的七种方法任你选

    原文地址:http://blog.csdn.net/mosliang/article/details/6760028 相信如何解决png在ie6下透明的问题困扰了很多人.为了追求更好的页面效果,很多人 ...

  6. 关于ie6下png背景透明

    今天我突破了一个技术难关,真的是头都大了.. 关于ie6下png背景透明的解决方法,我就不多说了,网上有很多解决方法,我用的是其中的一种: <script type="text/jav ...

  7. android 自定义Dialog背景透明及显示位置设置

    先贴一下显示效果图,仅作参考: 代码如下: 1.自定义Dialog public class SelectDialog extends AlertDialog{ public SelectDialog ...

  8. IE6 背景透明

    IE6 背景透明 第 1 种方法:定义一个样式,给某个div应用这个样式后,div的透明png背景图片自动透明了.(注意两处图片的路径写法不一样,本例中,icon_home.png图片与html文件在 ...

  9. gif修改背景透明

    1.用ImageReady打开,将选中所有帧,右键选择“恢复为背景”. 2.打开“颜色板”,点击左下角的惊叹号,用吸色器点击背景,颜色板自动选中了背景色,将其映射为透明. 3.文件->将优化结果 ...

随机推荐

  1. AlphaZero并行五子棋AI

    AlphaZero-Gomoku-MPI Link Github : AlphaZero-Gomoku-MPI Overview This repo is based on junxiaosong/A ...

  2. WS快捷键

    打开文件: Ctrl + Shift + N 打开类: Ctrl + N 打开函数: Ctrl + F12 “超级”打开: 双击 shift,可以 search anywhere. 复制整行: Ctr ...

  3. 一列道出yield和生成器的真谛

    均匀大小的块 def chunks(l, n): """Yield successive n-sized chunks from l.""" ...

  4. codevs 5790 素数序数

    5790 素数序数(筛素数版) 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold       题目描述 Description 给定一个整数n,保证n为正整数且在int范 ...

  5. Codeforces.724G.Xor-matic Number of the Graph(线性基)

    题目链接 \(Description\) 给定一张带边权无向图.若存在u->v的一条路径使得经过边的边权异或和为s(边权计算多次),则称(u,v,s)为interesting triple(注意 ...

  6. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  7. Properties属性操作

    package com.properties; import java.io.FileInputStream; import java.io.FileOutputStream; import java ...

  8. 由最小生成树(MST)到并查集(UF)

    背景 最小生成树(Minimum Spanning Tree)的算法中,克鲁斯卡尔算法(Kruskal's algorithm)是一种常用算法. 在克鲁斯卡尔算法中的一个关键问题是如何判断图中的两个点 ...

  9. ThinkPHP空操作和空控制器的处理

    所谓的空操作和空控制器,简而言之就是系统中不存在该方法或控制器,导致系统报错(本文版本3.2.3). 正确URL(测试环境):  http://oa.com/index.php/admin/publi ...

  10. USB ISP(ICSP) Open Programmer < PWM ADC HV PID >

    http://sourceforge.net/projects/openprogrammer/?source=navbar Open Programmer http://openprog.alterv ...