日期:2014-05-20  浏览次数:20829 次

我做了个没边框的窗口,在Paint里,画了边框和填颜色,移动窗口时
边框周围会出好多线,也就是刷新问题,请问怎么解决?
                private   void   FormCustom_Paint(object   sender,   PaintEventArgs   e)
                {
                        Graphics   g   =   e.Graphics;
                        ControlPaint.DrawBorder(g,   this.ClientRectangle,   SystemColors.Highlight,   ButtonBorderStyle.Solid);
                }


------解决方案--------------------
为窗体开启双缓冲.
------解决方案--------------------
//不知道你是通过什么方法移动的?
//记得Invalidate();刷新
//或者用API的方式移动窗体,我测试没有出现你说的情况

private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
ControlPaint.DrawBorder(g, ClientRectangle,
SystemColors.Highlight, ButtonBorderStyle.Solid);
}

[DllImport( "User32.DLL ")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
[DllImport( "User32.DLL ")]
public static extern bool ReleaseCapture();
public const uint WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 61456;
public const int HTCAPTION = 2;

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);
}

------解决方案--------------------
把如下的代码放到你的控件里试试看(VS2005):
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
drawForm(e.Graphics);
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Rectangle rect = this.ClientRectangle;
rect.Inflate(-10, -10);

Graphics _g = this.CreateGraphics();
drawForm(_g);
}

private void drawForm(Graphics _g)
{
Rectangle rect = this.ClientRectangle;
rect.Inflate(-10, -10);
BufferedGraphicsContext context = BufferedGraphicsManager.Current;
BufferedGraphics bg = context.Allocate(_g, this.ClientRectangle);
bg.Graphics.Clear(this.BackColor);
bg.Graphics.DrawRectangle(SystemPens.ControlText, rect);
bg.Render();
}