窗体抖动,为何?

helysan 2005-08-20 12:57:03
我的c#窗体 form1 中调用另一个窗体 form2 时,采用 showdialog 方法,但是,form2 返回时,form1 窗体明显晃动、抖动一次,让使用者感觉眼花,怎么解决这个问题?
...全文
61 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
速马 2005-08-20
  • 打赏
  • 举报
回复
>>> form2 返回时,form1 窗体明显晃动、抖动一次
一定是关闭form2后对form1进行了什么操作

防止窗口闪烁的最简单的办法是启用双缓冲:
public void EnableDoubleBuffering()
{
// Set the value of the double-buffering style bits to true.
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
}
helloworld84 2005-08-20
  • 打赏
  • 举报
回复
我的不会有这种现象啊
saucer 2005-08-20
  • 打赏
  • 举报
回复
where are you calling your Form2.ShowDialog()? show some code? or try


using System;
using System.Drawing;
using System.Windows.Forms;

class TestDialog : Form
{
public TestDialog()
{
Button btn = new Button();
btn.Text="Hello";
btn.Location = new Point(100,100);
btn.Click += new EventHandler(Button_Click);
Controls.Add(btn);
}

void Button_Click(object sender, EventArgs e)
{
Close();
}
}

class TestForm : Form
{
public TestForm()
{
Button btn = new Button();
btn.Text="Show Dialog";
btn.Location = new Point(100,100);
btn.Size = new Size(100,30);
Controls.Add(btn);

btn.Click += new EventHandler(Button_Click);
}

void Button_Click(object sender, EventArgs e)
{
TestDialog dt = new TestDialog();
dt.ShowDialog();
}


public static void Main()
{
Application.Run(new TestForm());
}
}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧