using System;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;
using System.Runtime.InteropServices;
namespace Web
{
public partial class FrmMain : Form
{
//防抖动
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
private const int WM_SETREDRAW = 11;
private void SetingSubFrmBanding(Form form, TabPage page)
{
SendMessage(this.Handle, WM_SETREDRAW, false, 0);
page.Controls.Clear();
form.FormBorderStyle = FormBorderStyle.None;
form.StartPosition = FormStartPosition.Manual;
form.Size = page.Size;
form.TopLevel = false;
page.Controls.Add(form);
form.Show();
SendMessage(this.Handle, WM_SETREDRAW, true, 0);
this.Refresh();
}
}
}
也可以在窗体代码中重写CreateParams消除抖动
/// <summary>
/// 消除抖动
/// </summary>
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}