下述代码在resize的时候,矩形会有残影,请问如何解决,C#新学,请教了。
-----
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Diagnostics;public class Form2 : Form
{
internal class MyTableControl: System.Windows.Forms.Panel
{
private int itemHeight;
private int itemWidth;
public int ItemHeight
{
get { return itemHeight; }
set { this.itemHeight = value; }
}
public int ItemWidth
{
get { return itemWidth; }
set { this.itemWidth = value; }
}
public MyTableControl():base()
{
SetStyle(ControlStyles.UserPaint,true);
SetStyle(ControlStyles.AllPaintingInWmPaint,true);
SetStyle(ControlStyles.DoubleBuffer,true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Brush wbrush = new SolidBrush(Color.White);
Rectangle TabRect = Rectangle.FromLTRB(this.ClientRectangle.Left,this.ClientRectangle.Top+ItemHeight,this.ClientRectangle.Right-1,this.ClientRectangle.Bottom-1);
e.Graphics.FillRectangle(wbrush, TabRect);
}
}
private int m_BorderWidth = 4;
private MyTableControl tableControl;
public Form2()
{
tableControl = new MyTableControl();
tableControl.Parent = this;
tableControl.Location = new Point(2*m_BorderWidth,0);
tableControl.ItemHeight =24;
tableControl.ItemWidth = 50;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
tableControl.Size = new Size(ClientRectangle.Right - 4*m_BorderWidth,ClientRectangle.Height -8*m_BorderWidth);
}
static void Main()
{
Application.Run(new Form2());
}
}
-----
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Diagnostics;public class Form2 : Form
{
internal class MyTableControl: System.Windows.Forms.Panel
{
private int itemHeight;
private int itemWidth;
public int ItemHeight
{
get { return itemHeight; }
set { this.itemHeight = value; }
}
public int ItemWidth
{
get { return itemWidth; }
set { this.itemWidth = value; }
}
public MyTableControl():base()
{
SetStyle(ControlStyles.UserPaint,true);
SetStyle(ControlStyles.AllPaintingInWmPaint,true);
SetStyle(ControlStyles.DoubleBuffer,true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Brush wbrush = new SolidBrush(Color.White);
Rectangle TabRect = Rectangle.FromLTRB(this.ClientRectangle.Left,this.ClientRectangle.Top+ItemHeight,this.ClientRectangle.Right-1,this.ClientRectangle.Bottom-1);
e.Graphics.FillRectangle(wbrush, TabRect);
}
}
private int m_BorderWidth = 4;
private MyTableControl tableControl;
public Form2()
{
tableControl = new MyTableControl();
tableControl.Parent = this;
tableControl.Location = new Point(2*m_BorderWidth,0);
tableControl.ItemHeight =24;
tableControl.ItemWidth = 50;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
tableControl.Size = new Size(ClientRectangle.Right - 4*m_BorderWidth,ClientRectangle.Height -8*m_BorderWidth);
}
static void Main()
{
Application.Run(new Form2());
}
}
解决方案 »
- 求一替换的正则表达式,谢谢!
- 九宫运算
- 程序稳定性问题
- 调用MSSQL的存储过程出现问题了
- 参数传递(WinForm)
- C#如何把ASCII码字符串转成unicode字符串?
- VB6程序使用第三方组件Pdfgll.DLL编写一个函数cffd(),如果将函数cffd()在VB6中建立一个AactivX-DLL项目制作成DLL组件cffd.DLL,那么在C#中引用组件cffd.DLL编写的程序,到客户机上是否只需要cffd.DLL,
- 是高手请进,特别是懂彩信的高手
- 在c#如何将DataGridview中的内容打印出来?
- 是不是所有dll都可以被c#调用?
- 请教一下反射调用中的异常处理问题
- C#控制excel样式 数值
SetStyle(ControlStyles.UserPaint,true);SetStyle(ControlStyles.AllPaintingInWmPaint,true);
SetStyle(ControlStyles.DoubleBuffer,true);
e.Graphics.FillRectangle(new SolidBrush(Color.Transparent), Rec);
//消除上次画图的痕迹,貌似用Clear()也可以
Rectangle TabRect = Rectangle.FromLTRB(this.ClientRectangle.Left,this.ClientRectangle.Top+ItemHeight,this.ClientRectangle.Right-1,this.ClientRectangle.Bottom-1);
e.Graphics.FillRectangle(wbrush, TabRect);
请实际运行下,呵呵。
BufferedGraphics bg = ctx.Allocate(e.Graphics, new Rectangle(new Point(0, 0), panel1.Size));
gOfbuff = bg.Graphics;
gOfbuff.Draw();
bg.render
{
intoGrid();
} private void zhuChart_Resize(object sender, EventArgs e)
{
Invalidate();
}在你的paint重绘事件里加上你绘图的方法.
在你的改变大小里加上上面的Invalidate();就行,你试试
protected override void OnResize(EventArgs e)
{
this.Invalidate();
}
加上libinguest的上述改动即可,呵呵,我还以为默认就会repaint的呢。谁解释下。