自己做的Usercontrol,里面的内容是画的,有刷新问题,每次刷新的时候,屏幕都闪的厉害,有什么办法能让它不闪??
解决方案 »
- c#获取主机名称和IP,不知道哪出问题了
- 一个新手问题,如何将获取了的textbox内容变成变量名再获取变量的值
- 数据库操作
- B/S的系统,如何修改为C/S 这个S不动可以吗?
- 在菜单中打开最近打开文件(急求)
- C#真难用啊,想要一个图片按钮(就是显示Picture的Button)都没有现成的吗?
- ie线程注入是怎么回事啊?大家有知道的吗?
- Remoting 还是WEB Service?寻求解决方案
- 主界面载入,后台读取数据,让用户感觉不到,是用多线程吗?
- winform程序发布web客户端遇到的一个极品问题!!!
- 高手请赐教:PropertyGrid 控件如何动态修改 DisplayName 属性
- 怎样设置属性 可透过LABEL看到FORM的背景图片
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim bmp As New Bitmap(e.ClipRectangle.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(bmp) '左边框
g.DrawImage(LeftEdge_Middle_Bitmap, 0, 0, BorderWidth, Me.Bounds.Height)
g.DrawImage(LeftEdge_Top_Bitmap, 0, 0, BorderWidth, CaptionHeight)
g.DrawImageLeftEdge_Bottom_Bitmap, 0, Me.Bounds.Height - LeftEdge_Bottom_Bitmap.Height, BorderWidth, LeftEdge_Bottom_Bitmap.Height)
'下边框
g.DrawImage(BottomEdge_Middle_Bitmap, 0, Me.Bounds.Height - BorderWidth, Me.Bounds.Width, BorderWidth)
g.DrawImage(BottomEdge_Left_Bitmap, 0, Me.Bounds.Height - BorderWidth, BottomEdge_Left_Bitmap.Width, BorderWidth)
g.DrawImage(BottomEdge_Right_Bitmap, Me.Bounds.Width - BottomEdge_Right_Bitmap.Width, Me.Bounds.Height - BorderWidth, BottomEdge_Right_Bitmap.Width, BorderWidth)
'右边框
g.DrawImage(RightEdge_Middle_Bitmap, Me.Bounds.Width - BorderWidth, 0, BorderWidth, Me.Bounds.Height)
g.DrawImage(RightEdge_Top_Bitmap, Me.Bounds.Width - BorderWidth, 0, BorderWidth, CaptionHeight)
g.DrawImage(RightEdge_Bottom_Bitmap, Me.Bounds.Width - BorderWidth, Me.Bounds.Height - RightEdge_Bottom_Bitmap.Height, BorderWidth, RightEdge_Bottom_Bitmap.Height) e.Graphics.DrawImage(bmp, 0, 0)'窗体刷新就这一句进行绘制
g.Dispose() : bmp = Nothing
End Sub
public partial class UserControl1 : UserControl
{
private Timer timer;
private Rectangle m_Rect;
public UserControl1()
{
InitializeComponent();
timer = new Timer();
m_Rect = new Rectangle(0, 0, 100, 61);
timer.Interval = 20;
timer.Enabled = true;
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
timer.Tick += new EventHandler(timer_Tick);
} bool v = true;
bool h = true;
void timer_Tick(object sender, EventArgs e)
{
if (h)
{
this.m_Rect.X++;
}
else
{
this.m_Rect.X--;
}
if (v)
{
this.m_Rect.Y++;
}
else
{
this.m_Rect.Y--;
}
if (this.m_Rect.Right > this.ClientRectangle.Right)
{
h=false;
}
else if (this.m_Rect.X < this.ClientRectangle.X)
{
h = true;
}
if (this.m_Rect.Bottom > this.ClientRectangle.Bottom)
{
v = false;
}
else if (this.m_Rect.Y < this.ClientRectangle.Y)
{
v = true;
}
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(SystemBrushes.Desktop, this.m_Rect);
}
}