如何让孩子形成闪烁?

问题描述 投票:3回答:1

我正在开发一个自定义表单,提供更多选项来自定义表单的外观。我在父表单中有一个按钮,通过单击按钮,我通过以下代码显示了另一个表单。

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);
                        }
                    }
                }
            }
        }

问题是,当我点击父窗体时,子窗体不会闪烁。我不知道如何解决这个问题。任何人都可以为这个问题提供解决方案。

注意:任务栏中的图标闪烁但自定义表单没有闪烁

c# winforms
1个回答
0
投票

我不清楚,

但你可以使用MDI(多文档界面)做Master,Child表格

© www.soinside.com 2019 - 2024. All rights reserved.