zoukankan      html  css  js  c++  java
  • 通用功能类:改变WinForm窗体显示颜色

    一.显示窗体调用方法

    protected override void OnLoad(EventArgs e)
            {
                MDIClientSupport.SetBevel(this, false, Color.White);
                base.OnLoad(e);
            }

    二.SetBevel方法实现

    namespace TeamFoundation.SystemManage.Common
    {
        public class MDIClientSupport
        {
            [DllImport("user32.dll")]
            private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    
            [DllImport("user32.dll")]
            private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    
            [DllImport("user32.dll", ExactSpelling = true)]
            private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    
            private const int GWL_EXSTYLE = -20;
            private const int WS_EX_CLIENTEDGE = 0x200;
            private const uint SWP_NOSIZE = 0x0001;
            private const uint SWP_NOMOVE = 0x0002;
            private const uint SWP_NOZORDER = 0x0004;
            private const uint SWP_NOREDRAW = 0x0008;
            private const uint SWP_NOACTIVATE = 0x0010;
            private const uint SWP_FRAMECHANGED = 0x0020;
            private const uint SWP_SHOWWINDOW = 0x0040;
            private const uint SWP_HIDEWINDOW = 0x0080;
            private const uint SWP_NOCOPYBITS = 0x0100;
            private const uint SWP_NOOWNERZORDER = 0x0200;
            private const uint SWP_NOSENDCHANGING = 0x0400;
    
            public static bool SetBevel(this Form form, bool show, Color backColor)
            {
                foreach (Control c in form.Controls)
                {
                    MdiClient client = c as MdiClient;
                    if (client != null)
                    {
                        client.BackColor = backColor;
                        int windowLong = GetWindowLong(c.Handle, GWL_EXSTYLE);
    
                        if (show)
                        {
                            windowLong |= WS_EX_CLIENTEDGE;
                        }
                        else
                        {
                            windowLong &= ~WS_EX_CLIENTEDGE;
                        }
    
                        SetWindowLong(c.Handle, GWL_EXSTYLE, windowLong);
    
                        // Update the non-client area.
                        SetWindowPos(client.Handle, IntPtr.Zero, 0, 0, 0, 0,
                            SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
                            SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
    
                        return true;
                    }
                }
                return false;
            }
        }
    }
  • 相关阅读:
    Hadoop的MapReduce基本框架
    通过idea测试Hadoop增删改查
    Linux系统简介以及基本操作(二)
    Linux系统简介以及基本操作(一)
    JAVA解除tomcat 对浏览器特别字符 | () {} [] 的限制
    JAVA实现读取图片
    用java实现取1-100之间的99个不重复的随机数 然后输出没有被取出的数字
    < Android Camera2 HAL3 学习文档 >
    算法<初级>
    算法<初级>
  • 原文地址:https://www.cnblogs.com/lqsilly/p/3465502.html
Copyright © 2011-2022 走看看