在其他控件之上绘制GDI类型(矩形,圆形,直线). [英] Drawing a GDI type (Rectangle, Circle, Line) on top of other Controls....

查看:208
本文介绍了在其他控件之上绘制GDI类型(矩形,圆形,直线).的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要在容器控件上绘制一个矩形和一条线,有时当我移动鼠标时,该绘制必须在用户控件和其他控件上无缝发生...

我正在使用System.Drawing命名空间执行绘图.
但是当我移动鼠标并绘制矩形时,绘制发生在用户控件的后面....我需要在控件顶部绘制形状...

我仔细检查了网络,发现有一个WIN 32样式属性可以设置为在子控件上绘画. > {get
} {CreateParams cp = base.CreateParams;
cp.Style& =(〜WS_CLIPCHILDREN);
return cp;
}
}

这行得通!!!!矩形是在子控件上绘制的.

但是这有问题,当我尝试滚动屏幕​​时,会出现很多闪烁和绘画问题...
System.Drawing命名空间中是否有任何优化的方法/属性,可用于覆盖子级控件.

在此先感谢您的帮助!

Kamlesh
程序员-认知技术解决方案

解决方案

是的,幸运的是!只需使用以下代码:

this.SetStyle(ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.OptimizedDoubleBuffer, true);


Hi,
   I have a requirement to draw a rectangle and a line on a the container control and sometimes as i move the mouse the drawing must occur seamlessly on user controls and other controls...

I'm using System.Drawing namespace to perform the drawing.
But as i move the mouse and draw the rectangles, the drawing takes place behind the user controls....I have a requirement to draw the shapes on top of the controls...

I scrounged the net to find that there is a WIN 32 style property that can be set to paint over child controls..

public static int WS_CLIPCHILDREN = 0x02000000;
protected override CreateParams CreateParams
{   get
    { CreateParams cp = base.CreateParams;
      cp.Style &= (~WS_CLIPCHILDREN);
      return cp;
   }
}

This worked!!!!  The rectangle was drawn over the child controls.

But this has problems, when ever i tried scrolling the screen there were lots of flickering and painting issues...
Is there any optimized method/property in the System.Drawing namespace which can be used to draw over child controls.

Thanx in advance for any help!

Kamlesh
Programmer - Cognizant Technology Solutions

解决方案

Yes, fortunately there is! Just use this code:

this.SetStyle(ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.OptimizedDoubleBuffer, true);


这篇关于在其他控件之上绘制GDI类型(矩形,圆形,直线).的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆