[英]How to make the child form flickers?
我正在開發一個自定義表單,提供更多選項來自定義表單的外觀。我在父表單中有一個按鈕,通過單擊按鈕,我通過以下代碼顯示了另一個表單。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
CustomForm form = new CustomForm();
form.ShowDialog();
}
}
我通過以下代碼處理了On_Wm_NcActivate。我想我沒有正確處理On_Wm_NcActivate。
private void On_Wm_NcActivate(ref Message m)
{
if (!this.IsMdiContainer)
NativeMethods.LockWindowUpdate(this.Handle);
base.WndProc(ref m);
NativeMethods.LockWindowUpdate(IntPtr.Zero);
if (Style != null)
{
var msg = new Message();
msg.Msg = WindowMessages.WM_NCPAINT;
msg.HWnd = m.HWnd;
msg.WParam = (IntPtr)1;
msg.LParam = (IntPtr)0;
On_Wm_NcPaint(ref msg);
}
}
我通過以下代碼處理了On_Wm_NcPaint,以自定義標題欄以及覆蓋表單的邊框和背景。
private void On_Wm_NcPaint(ref Message m)
{
var rect = new NativePaint.RECT();
NativeMethods.GetWindowRect(m.HWnd, ref rect);
var deviceContext = NativeMethods.GetWindowDC(m.HWnd);
if (deviceContext != IntPtr.Zero)
{
var bufferDeviceContext = NativeMethods.CreateCompatibleDC(deviceContext);
if (bufferDeviceContext != IntPtr.Zero)
{
IntPtr bmp = NativeMethods.CreateCompatibleBitmap(deviceContext, rect.Width, rect.Height);
if (bmp != IntPtr.Zero)
{
if (style == null)
{
return;
}
int borderThickness = 1;
var oldBmp = NativeMethods.SelectObject(bufferDeviceContext, bmp);
using (Graphics graphics = Graphics.FromHdc(bufferDeviceContext))
{
//To clip the client area from painting based on the border thickness and title bar height.
var top = GetCaptionBarHeight() + (int)borderThickness + 5;
var left = (int)borderThickness;
var right = rect.Width - (int)borderThickness;
var bottom = rect.Height - (int)borderThickness;
if (FormBorderStyle != FormBorderStyle.None)
DrawFrame(graphics, rect);
if (FormBorderStyle == FormBorderStyle.None)
{
top = 0;
left = 0;
right = Width;
bottom = Height;
}
//Clip the client region from the window rectangle.
if (this.WindowState != FormWindowState.Minimized)
NativeMethods.ExcludeClipRect(deviceContext, left + 1, top, right - 1, bottom - 1);
NativeMethods.BitBlt(deviceContext, 0, 0, rect.Width, rect.Height, bufferDeviceContext, 0, 0, WindowMessages.SRCCOPY);
NativeMethods.SelectObject(bufferDeviceContext, oldBmp);
NativeMethods.DeleteObject(bmp);
NativeMethods.DeleteObject(oldBmp);
NativeMethods.DeleteDC(deviceContext);
NativeMethods.DeleteObject(bufferDeviceContext);
}
}
}
}
}
問題是,當我點擊父窗體時,子窗體不會閃爍。 我不知道如何解決這個問題。任何人都可以為這個問題提供解決方案。
注意:任務欄中的圖標閃爍但自定義表單沒有閃爍
我不清楚,
但您可以使用MDI (多文檔界面)執行Master,Child表單
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.