简体   繁体   English

c# - 如何禁用无边框表单的调整大小

[英]How to disable resize for borderless form c#

I have a Form that is fullscreen and borderless, but I would like to prevent resizing the form by any means (dragging form up to the top, and stretching from the corner of the form. How can I achieve this?我有一个全屏且无边框的表单,但我想防止以任何方式调整表单的大小(将表单拖到顶部,并从表单的角落拉伸。我怎样才能做到这一点?

private void FormCashFlow_Load(object sender, EventArgs e)
        {
           
            CashFlow cash = new CashFlow();
            this.ControlBox = False;
            this.WindowState = FormWindowState.Maximized;
            this.SizeGripStyle = SizeGripStyle.Hide;
        }

Edit:编辑:

The Main Form contains no control box, but has a panel at the top for dragging and resizing the form (with custom logic).主窗体不包含控制框,但在顶部有一个面板,用于拖动和调整窗体大小(使用自定义逻辑)。 There is a menu on the side that has buttons for loading different forms into the main form.侧面有一个菜单,其中包含用于将不同表单加载到主表单中的按钮。 When the user clicks the button, the child form is loaded into a panel on the main form.当用户单击按钮时,子窗体将加载到主窗体上的面板中。 When the child form is loaded, the child form is maximized.当加载子窗体时,子窗体最大化。 I would like to keep that child form maximized with the inability to resize.我想在无法调整大小的情况下保持该子窗体最大化。

I apologize if this is hard to follow.如果这很难遵循,我深表歉意。

public partial class MainForm : Form
    {
        //Fields
        private IconButton currentBtn;
        private Panel leftBoderButton;
        private Form currentChildForm;


        public MainForm()
        {
            InitializeComponent();
            this.MinimumSize = new Size(1650, 800);
            leftBoderButton = new Panel();
            panelMenu.Controls.Add(leftBoderButton);

            this.Text = String.Empty;
            this.ControlBox = false;
            this.DoubleBuffered = true ;
            this.MaximizedBounds = Screen.FromHandle(Handle).WorkingArea; //Fix window full screen resize
        }


        [DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
        private extern static void ReleaseCapture();

        [DllImport("user32.DLL", EntryPoint = "SendMessage")]
        private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int lParam);
       
        
        private void panelMain_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(Handle, 0xA1, 0x2, 0);
            }
        }

 private void OpenChildForm(Form childForm)
        {
            if (currentChildForm != null)
            {
                currentChildForm.Close();
            }
            currentChildForm = childForm;
            childForm.TopLevel = false;
            childForm.FormBorderStyle = FormBorderStyle.None;
            childForm.Dock = DockStyle.Fill ;
            panelDesktop.Controls.Add(childForm);
            panelDesktop.Tag = childForm;
            childForm.BringToFront();
            childForm.Show();
            childForm.WindowState = FormWindowState.Maximized;
        }

private void iconButton4_Click(object sender, EventArgs e)
        {
            
            OpenChildForm(new FormCashFlow);
            
        }

I think all you need is the existing property on the form.我认为您需要的只是表单上的现有属性。

FormBorderStyle = Fixed.Single;

It wont do the borderless, but a single line that a user would not be able to grab to manually resize.它不会做无边界的,而是用户无法手动调整大小的单行。

If you want to get rid of the minimize/maximize/close button, you can also do如果你想摆脱最小化/最大化/关闭按钮,你也可以这样做

ControlBox = false;

Then the user doesn't even see those buttons to be tempted to resize the window.然后用户甚至看不到那些想要调整窗口大小的按钮。

and to ensure full screen (which you apparently already have),并确保全屏(您显然已经拥有),

WindowState = Maximized;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM