1

I am having trouble making a winform non-resizable in Win 8.

I've disabled the maximise button and it is starting maximised by default but when I double click on the top bar or when dragging from the top bar it changes size.

How to disable those actions?

sd_dracula
  • 3,796
  • 28
  • 87
  • 158
  • 2
    Set the form's `FormBorderStyle` property to `FixedSingle`, `Fixed3D` or `FixedDialog` – Matthew Watson Apr 24 '14 at 08:52
  • possible duplicate of [How do I disable form resizing for users in C# Winforms](http://stackoverflow.com/questions/5416380/how-do-i-disable-form-resizing-for-users-in-c-sharp-winforms) – Willem van Rumpt Apr 24 '14 at 08:53
  • I already tried all of those. Does not work. Double clicking the top bar and dragging it still causes the form to resize to it's default size. Maybe it works on Win 7 but not on 8. – sd_dracula Apr 24 '14 at 08:57
  • If nothing helps: Have you considered setting the maxSize of the form = the min size of the form? – Marc Wittmann Apr 24 '14 at 09:03
  • What exactly is the behavior you're after? To have the form fill up the entire screen, and not be resizable? Then I suspect that you set WindowState to Maximized. Instead, set it to Normal, and in FormLoad, set the Width and the Height to the screen resolution – Willem van Rumpt Apr 24 '14 at 09:10
  • That's exactly what I have. I will try your suggestion. – sd_dracula Apr 24 '14 at 09:13

3 Answers3

3

I think the below is the behavior you're after:

Set:

FormBorderStyle to FixedSingle / Fixed3D / FixedDialog

MaximizeBox to false

MinimizeBox to false

WindowState to Normal

Implement the Load event of the form:

    private void Form1_Load(object sender, EventArgs e)
    {
        Width = Screen.PrimaryScreen.Bounds.Width;
        Height = Screen.PrimaryScreen.Bounds.Height;
    }

If you want the Form to start at Location(0, 0), set StartPosition to Manual, and Location to (0, 0)

Willem van Rumpt
  • 6,490
  • 2
  • 32
  • 44
1

A picture is worth a thousand words:

enter image description here

Set FormBorderStyle to any of FixedSingle, Fixed3D, FixedDialog as mentioned in comments, but also set MaximizeBox value to false. It should work.

msmolcic
  • 6,407
  • 8
  • 32
  • 56
  • It works but not if you double click or drag from the top bar. I need to somehow ignore the double click event but the form's Double Click event does not trigger when doing that on the top bar so I am at a loss. – sd_dracula Apr 24 '14 at 09:09
  • Well, I just tried it on my PC and even if I double click or drag to the top it remains unchanged.. maybe it's not the problem with the form itself. – msmolcic Apr 24 '14 at 09:11
  • what OS are you using? – sd_dracula Apr 24 '14 at 09:12
  • Windows 8.1. Try setting maximum size of the box as mentioned in comments. Also try this solution: http://www.vbforums.com/showthread.php?622268-RESOLVED-Disable-maximize-on-double-click-titlebar – msmolcic Apr 24 '14 at 09:14
0

Try this on Form resize or sizechange event after setting properties mention in above answers

 private void Form1_Resize(object sender, EventArgs e)
 {
      if(this.WindowState==System.Windows.Forms.FormWindowState.Maximized)
      this.WindowState = System.Windows.Forms.FormWindowState.Normal;
 }

or if you want that form remain maximize then

private void Form1_Resize(object sender, EventArgs e)
 {
      if(this.WindowState==System.Windows.Forms.FormWindowState.Normal)
      this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
 }
Mehul Patel
  • 1,084
  • 2
  • 12
  • 28