防止窗口闪烁的最简单的办法是启用双缓冲:
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();
}
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);
}
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);