如何在windows窗体中清除透明控件上的图形

So, I am pretty unfamiliar with windows forms development.

I'm trying to create a "hey I'm busy doing stuff" component that just spins a shape around. I want this control to be transient and draw on top of any other controls. The class inherits directly from Control.

So I have this in the constructor:

SetStyle(ControlStyles.Opaque, true);

and this:

protected override CreateParams CreateParams
{
    get
    {
        CreateParams parms = base.CreateParams;
        parms.ExStyle |= 0x20; 
        return parms;
    }
}

Which gets me a control that will draw on top of other controls.

Now my problem is this. I repaint the control a few times a second to give the appearane of a smooth animation. However, I can't figure out how to clear what was drawn in the previous frame. Using e.Graphics.Clear(Color.Transparent) in OnPaint turns the whole control black.

Is there a way to just clear the drawn contents of a control?

I've noticed that Resizing the the control will clear the background.

Things that Don't Work

  1. Overriding OnPaintBackground to do nothing. Or just calling base.OnPaintBackground. Same results.

#0

Okay, I found the solution here: http://www.bobpowell.net/transcontrols.htm

The Parent controls actually must be invalidated in order to retain the transparent background.

#1

You may have to override OnPaintBackground that this article presents: http://saftsack.fs.uni-bayreuth.de/~dun3/archives/creating-a-transparent-panel-in-net/108.html

You may also need to Invalidate the control when it needs to be cleared to force OnPaintBackground to be called.

推荐文章

当UITextField失去焦点时隐藏键盘

当UITextField失去焦点时隐藏键盘

推荐文章

单引号和双引号html属性之间的功能区别是什么?

单引号和双引号html属性之间的功能区别是什么?

推荐文章

Django活塞问题-“oauth_user_auth()只接受1个参数(给定2个参数)”

Django活塞问题-“oauth_user_auth()只接受1个参数(给定2个参数)”

推荐文章

免注册COM:引用VB6 DLL的VB6可执行文件

免注册COM:引用VB6 DLL的VB6可执行文件

推荐文章

Ruby中的一行嵌套散列创建?(我来自Perl)

Ruby中的一行嵌套散列创建?(我来自Perl)

推荐文章

获取mongoDB w/Java驱动程序中最后插入的文档的ID

获取mongoDB w/Java驱动程序中最后插入的文档的ID

推荐文章

自制网站的自定义禁止页

自制网站的自定义禁止页

推荐文章

直接路由事件问题

直接路由事件问题

推荐文章

jQuery图像选择器

jQuery图像选择器

推荐文章

如何在Erlang中对字符串进行XML编码?

如何在Erlang中对字符串进行XML编码?

推荐文章

有没有可能缩小一个图片,使其成为你的背景全部在css中?

有没有可能缩小一个图片,使其成为你的背景全部在css中?

推荐文章

终止Safari或邮件

终止Safari或邮件

推荐文章

将R中的矩阵转换为数据帧时出现问题(R认为所有数值类型都是因子)

将R中的矩阵转换为数据帧时出现问题(R认为所有数值类型都是因子)

推荐文章

Linq-InvalidCastException-where不过滤无效类型

Linq-InvalidCastException-where不过滤无效类型

推荐文章

iPad和iPhone的坐标系统有什么区别?

iPad和iPhone的坐标系统有什么区别?

推荐文章

JQUERY onClick更改“top”属性

JQUERY onClick更改“top”属性