首页 > 解决方案 > 如何在不影响行为的情况下处理表单中的 wndproc calcsize 进程进行自定义

问题描述

我正在开发一个自定义表单,它提供了更多选项来自定义表单的外观。在 wndproc 中获取消息 131 时,我已经覆盖了 wndproc 并在 calcsize() 方法中计算了表单的大小。我已经完成了在 calcsize() 中自定义标题栏高度的计算。请参考下面的代码。问题是在 Windows 10 和 8 中使用边框样式 sizeablewindowtool 打开表单时,表单进入任务栏(这是一种行为msdn 表单)。但是问题是当我在 windows 7 中打开表单时,表单进入任务栏。我已经检查了 msdn 表单,它没有进入 windows 7 的任务栏。请帮我找到我的错误。

  /// <summary>
        /// Calculates the non client area of the form
        /// </summary>
        /// <param name="m">reference message</param>
        /// <returns>retruns true if the method returns combiantion of values
        /// returns false if the method return zero</returns>
        private bool OnWmNcCalcSize(ref Message m)
        {
            NativeMethods.RECT rc = (NativeMethods.RECT)m.GetLParam(typeof(NativeMethods.RECT));

            int iBorderWidth = fl.BorderWidth;

                fl.PerformLayout(rc.Width, rc.Height);
                rc.top += fl.CaptionHeight;
                if (this.WindowState == FormWindowState.Maximized)
                {
                    ///<summary>
                    /// local variable to store x-coordinate of native rectangle,rc.left is -6 when we double click on title-bar and -8 when we click the maximize button.
                    ///</summary>
                    int xcoordinate = rc.left;
                    rc.left -= xcoordinate;
                    rc.right += xcoordinate;
                    rc.bottom += xcoordinate;
                }
                else
                {
                    rc.left += iBorderWidth - (iBorderWidth / 3);
                    rc.right -= iBorderWidth - (iBorderWidth / 3);
                    rc.bottom -= iBorderWidth - (iBorderWidth / 3);
                }

                Marshal.StructureToPtr(rc, m.LParam, true);
            m.Result = IntPtr.Zero;
            return true;
        }

标签: c#winforms

解决方案


推荐阅读