自己做的Usercontrol,里面的内容是画的,有刷新问题,每次刷新的时候,屏幕都闪的厉害,有什么办法能让它不闪??
解决方案 »
- 关于WPF中3D模型的绘制问题?
- socket 通信 C#服务器 android客户端
- 当我使用xlChart.CopyPicture,把东西放到内存后,我想知道我放到内存中的这个东西,是什么格式的?怎么通过C#做到这点呢?
- 什么是表变量
- 怎样把arraylist的值从大到小排序
- 从索引 0 处开始,初始化字符串的格式不符合规范
- web项目创建时出现错误,请帮忙!
- 实体类里面,特殊地方
- “运行时错误”和“编译时错误”有什么区别?
- Spread 6 在VS.net中好象用不了,数据集调不出来,哪位大侠知道怎么办吗?
- 高手请赐教: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);
}
}