vs C# 怎么设置窗口属性? 显示没有边框新窗口

大家在打开VS2019,PS这种

会先有一个图,上面显示一张图片VS2019和PS logo啥的,没有边框的,这个如何实现?
怎么设置窗口属性?


using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace contextUI
{
    public partial class ConextForm : Form
    {
        public bool Sizeable = true;

        [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
        private static extern IntPtr CreateRoundRectRgn
        (
            int nLeftRect,
            int nTopRect,
            int nRightRect,
            int nBottomRect,
            int nWidthEllipse,
            int nHeightEllipse
        );

        [DllImport("dwmapi.dll")]
        public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);

        [DllImport("dwmapi.dll")]
        public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);

        [DllImport("dwmapi.dll")]
        public static extern int DwmIsCompositionEnabled(ref int pfEnabled);

        private bool m_aeroEnabled = false;
        private const int CS_DROPSHADOW = 0x00020000;
        private const int WM_NCPAINT = 0x0085;
        private const int WM_ACTIVATEAPP = 0x001C;

        public struct MARGINS
        {
            public int leftWidth;
            public int rightWidth;
            public int topHeight;
            public int bottomHeight;
        }

        private const int WM_NCHITTEST = 0x84;
        private const int HTCLIENT = 0x1;
        private const int HTCAPTION = 0x2;

        protected override CreateParams CreateParams
        {
            get
            {
                m_aeroEnabled = CheckAeroEnabled();

                CreateParams cp = base.CreateParams;
                if (!m_aeroEnabled)
                    cp.ClassStyle |= CS_DROPSHADOW;

                return cp;
            }
        }

        private bool CheckAeroEnabled()
        {
            if (Environment.OSVersion.Version.Major >= 6)
            {
                int enabled = 0;
                DwmIsCompositionEnabled(ref enabled);
                return (enabled == 1) ? true : false;
            }
            return false;
        }

        const int HTLEFT = 10;
        const int HTRIGHT = 11;
        const int HTTOP = 12;
        const int HTTOPLEFT = 13;
        const int HTTOPRIGHT = 14;
        const int HTBOTTOM = 15;
        const int HTBOTTOMLEFT = 0x10;
        const int HTBOTTOMRIGHT = 17;

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            switch (m.Msg)
            {
                case WM_NCPAINT:
                    if (m_aeroEnabled)
                    {
                        var v = 2;
                        DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                        MARGINS margins = new MARGINS()
                        {
                            bottomHeight = 1,
                            leftWidth = 1,
                            rightWidth = 1,
                            topHeight = 1
                        };
                        DwmExtendFrameIntoClientArea(this.Handle, ref margins);

                    }
                    break;
                case 0x0084:
                    if (Sizeable)
                    {
                        base.WndProc(ref m);
                        Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF);
                        vPoint = PointToClient(vPoint);
                        if (vPoint.X <= 5)
                        {
                            if (vPoint.Y <= 5)
                            {
                                m.Result = (IntPtr)HTTOPLEFT;
                            }
                            else
                            if (vPoint.Y >= ClientSize.Height - 5)
                            {
                                m.Result = (IntPtr)HTBOTTOMLEFT;
                            }
                            else
                            {
                                m.Result = (IntPtr)HTLEFT;
                            }
                        }
                        else
                        if (vPoint.X >= ClientSize.Width - 5)
                        {
                            if (vPoint.Y <= 5)
                            {
                                m.Result = (IntPtr)HTTOPRIGHT;
                            }
                            else
                            if (vPoint.Y >= ClientSize.Height - 5)
                            {
                                m.Result = (IntPtr)HTBOTTOMRIGHT;
                            }
                            else
                            {
                                m.Result = (IntPtr)HTRIGHT;
                            }
                        }
                        else
                        if (vPoint.Y <= 5)
                        {
                            m.Result = (IntPtr)HTTOP;
                        }
                        else
                        {
                            if (vPoint.Y >= ClientSize.Height - 5)
                            {
                                m.Result = (IntPtr)HTBOTTOM;
                            }
                        }

                    }
                    break;

                default:
                    break;
            }
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.ClientSize = new Size(284, 261);
            this.DoubleBuffered = true;
            this.Name = "conextForm";
            this.ResumeLayout(false);

        }
    }
}
好吧,我2了,直接在formboardstyle中设置为none就行了...

窗口样式:

Inco:改图标样式;

MaxmizeBox:true;显示右上角最大化按钮;

MinmizeBox:true;显示右上角最小化按钮;

ShowInco:true;显示左上角小图标;

ShowInTaskbar:true;窗体显示在任务栏;

TopMost:true;窗口置顶显示;

Opactiy:0%;整个窗口透明度

布局:

AutoScroll:true / false;如果控件超出窗口返回,是否自动显示小蜜蜂论坛发帖机滚动条;

AutoSize:true / false;窗口的范围是否会超出控件的大小;

MaximumSize:0,0;窗口可依拖拽的最大时的大小;

MinmusmSize:0,0;窗口可以拖拽的最小的大小;

Size:300,300;窗口打开时默认的大小;

StartPasition:CenterScreen;窗口打开时默认桌面位置,居中;

WindowState:Maximized;默认打开窗口最大化;

外观:

Font:宋体,9pt;可以修改字体大小,字体越大控件越大;

Text:输入文本;

TextAlign:文字位置;

FromBorderStyle:FixedSingle;窗口不可拖拽大小;

FromBorderStyle:None;隐藏窗口的边框;

DropDownStyle:DropDownList;让下拉框无法输入文本;

行为:

MaxLegth:可输入的字符长度;

PasswordChar:文本用什么文字显示;

ReadOnly:是否可读;

TabIndex:TAB键索引,设置可按顺序来;

Visible:控件是否隐藏;

WordWrap:是否自动换行;

设计:

(Name):当前窗口 / 控件的后台名字;

工具箱:

公共控件:

buttom:按钮;

labell:文本;

checkBox:复选框;

ComboBox:下拉菜框;

发布了74 篇原创文章 · 获赞 0 · 访问量 3091

猜你喜欢

转载自blog.csdn.net/netyou/article/details/104407452