请参考:http://blog.csdn.net/muchforest/archive/2007/08/13/1741079.aspx
问题!:给winform窗口加个风格 WS_CLIPCHILDREN? 具体怎么实现
问题2:对于GDI,用创建内存DC的方法就可以了? 具体怎么实现参考C#绘图双缓冲技术总结: http://community.csdn.net/Expert/PostNew.asp?room=5201但是这代码运行不了
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rect = e.ClipRectangle;
Bitmap bufferimage = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(bufferimage);
g.Clear(this.BackColor);
g.SmoothingMode = SmoothingMode.HighQuality; //高质量
g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量
foreach (IShape drawobject in doc.drawObjectList)
{
if (rect.IntersectsWith(drawobject.Rect))
{
drawobject.Draw(g);
if (drawobject.TrackerState == config.Module.Core.TrackerState.Selected
&& this.CurrentOperator == Enum.Operator.Transfrom)//仅当编辑节点操作时显示图元热点
{
drawobject.DrawTracker(g);
}
} }
using (Graphics tg = e.Graphics)
{
tg.DrawImage(bufferimage, 0, 0); //把画布贴到画面上
}
}
问题!:给winform窗口加个风格 WS_CLIPCHILDREN? 具体怎么实现
问题2:对于GDI,用创建内存DC的方法就可以了? 具体怎么实现参考C#绘图双缓冲技术总结: http://community.csdn.net/Expert/PostNew.asp?room=5201但是这代码运行不了
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rect = e.ClipRectangle;
Bitmap bufferimage = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(bufferimage);
g.Clear(this.BackColor);
g.SmoothingMode = SmoothingMode.HighQuality; //高质量
g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量
foreach (IShape drawobject in doc.drawObjectList)
{
if (rect.IntersectsWith(drawobject.Rect))
{
drawobject.Draw(g);
if (drawobject.TrackerState == config.Module.Core.TrackerState.Selected
&& this.CurrentOperator == Enum.Operator.Transfrom)//仅当编辑节点操作时显示图元热点
{
drawobject.DrawTracker(g);
}
} }
using (Graphics tg = e.Graphics)
{
tg.DrawImage(bufferimage, 0, 0); //把画布贴到画面上
}
}
主界面图片很多???是BackgroundImage ???还是Image ???要是这两个的话 没有办法改另:主窗体弄那么多图片干什么???控件背景???
{
tg.DrawImage(bufferimage, 0, 0); //把画布贴到画面上
}改成 e.Graphics.DrawImage(bufferimage, 0, 0); //把画布贴到画面上
Bitmap bufferimage 可以定义成private,频繁新建总感觉不好
public static extern int GetWindowLong(HandleRef hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);protected override void CreateHandle()
{
base.CreateHandle();
int windowLong = (GetWindowLong(new HandleRef(this, this.Handle), -16));
SetWindowLong(new HandleRef(this, this.Handle), -16, windowLong | WS_CLIPCHILDREN);
}
如果需要刷新窗体,只需要调用Invalidate。
{
int full_time_visible = timerInterval * picboxNetwork.Width / 1000;
Bitmap bm = new Bitmap(picboxNetwork.Width, picboxNetwork.Height, PixelFormat.Format16bppRgb555);
Graphics g = Graphics.FromImage((Image)bm); //draw each line in the graph
DrawGraph(g, picboxNetwork.Height, full_downlines, full_uplines, false); IntPtr oBm = bm.GetHbitmap();
picboxNetwork.Image = Image.FromHbitmap(oBm);
DeleteObject(oBm);
bm.Dispose();
g.Dispose();
}
int windowLong = (GetWindowLong(new HandleRef(this, this.Handle), -16));
int oldvalue = SetWindowLong(new HandleRef(this, this.Handle), -16, windowLong | WS_CLIPCHILDREN);
//恢复...
SetWindowLong(new HandleRef(this, this.Handle), -16, oldvalue);
Graphics g = Graphics.FromImage(bufferimage);
在 OnPaint里面,new Bitmap是很费时的,当然会闪了