Window resizing from within MonoGame

So I don’t want the ugly title bar at the top of my project, so I have set Window,IsBorderless to true

But now I still need to resize my window.

Nothing on Window is exposed to Monogame so I can’t see any way of doing it

Has anyone else tried?

I have just tried this , and to my surprise it did nothing

    public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);

    public static void Maximise()
        System.IntPtr wParam = new System.IntPtr(0xF030);
        System.IntPtr lParam = new System.IntPtr(0);
        SendMessage(Game1.Instance.Window.Handle, 0x112, wParam, lParam);


Which sends a message WM_SYSCOMMAND with a wParam of SC_MAXIMIZE

This should work…

I recently implemented this without hiding the title bar and it was straightforward as I just added a callback to the windows resize event in the Game class constructor.

        Window.AllowUserResizing = true;
        Window.ClientSizeChanged += OnResize;

If you draw your own resize graphic in the bottom right corner and then act on any mouse down, mouse up events you could do it that way.

Here is the callback:
public void OnResize(Object sender, EventArgs e)

    if ((_graphics.PreferredBackBufferWidth != _graphics.GraphicsDevice.Viewport.Width) ||
        (_graphics.PreferredBackBufferHeight != _graphics.GraphicsDevice.Viewport.Height))
        _graphics.PreferredBackBufferWidth = _graphics.GraphicsDevice.Viewport.Width;
        _graphics.PreferredBackBufferHeight = _graphics.GraphicsDevice.Viewport.Height;


The rearrange() call adjusts the on screen graphics to the new size.
The difference for you is you will need to set the new window size as well as the back buffer size.

When user mouses down on the resize graphic, set a flag resizeOn = true;

When user releases the mouse, call the OnReize() function if resizeOn == true and set resizeOn back to false.

You may need to add the 2 lines to Game() and the callback as per my code above to get the Maximise() to work. It may be sending the resize event to your code but you are not handling it.

Note also, when the window is resized, it can interfere with switching to full screen and back if its not in a resolution supported by the graphics card. I think I switch to 1024x768 when switching to full screen to stop weird displaying.

Yes I have all that in, just cannot have the ugly title bar.

With the title bar enabled I can resize to my hearts content.,but I have Window.IsBorderLess = true and nothing works

I did a quick test and my method works - kind of.

I set Window.IsBorderLess = true;
I added a 10x10 pixel ‘button’ in the bottom right corner.
I added code to call Resize() when the button is left clicked.

The Resize() adds 10 to the width and height of the window and it works - the window got slightly bigger.
I’ll see if I can get the drag to resize working.

    public void Resize()
        _graphics.PreferredBackBufferWidth += 10;
        _graphics.PreferredBackBufferHeight += 10;


Okay tried your idea, changed my code to this

 public static void Maximise()
        Game1.Instance.Window.Position = new Point(0, 0); = Game1.Instance.GraphicsDevice.DisplayMode.Width; = Game1.Instance.GraphicsDevice.DisplayMode.Height;;


Which is better, but the OnResize() callback doesn’t get called :<

There is a difference between borders and the title bar. To remove the title bar you will want to look into using the native method SetWindowLongPtr.

I implemented resize based on mouse down, mouse release events.

It only works in one direction - making the window smaller.

This is because Mouse.GetState() does not return the X,Y position when it’s outside of the window so I can’t resize to a position on screen outside the window.

I have had a look in MonoGame code and I think we need changes

At the moment the flags on Window modify the windows style used on the host form.

    public override bool IsBorderless
        get { return _isBorderless; }
            if (_isBorderless != value)
                _isBorderless = value;
            if (_isBorderless)
                Form.FormBorderStyle = FormBorderStyle.None;
                Form.FormBorderStyle = _isResizable ? FormBorderStyle.Sizable : FormBorderStyle.FixedSingle;

What we need is to be able to get to the underlying System.Windows.Forms.Form

ControlBox will get rid of the buttons
SizeGripStyle will allow us to resize

Still not sure how to get rid of the title bar, which is the main thing I have to get rid of

Yes this is really bad actually, without setting IsBorderless to false you cannot drag the window around either.

Which of course I must have for this app…

Just call me lucky

Can any one tell me how i can resize monogame on my pc