Page 1 of 1

Borderless but resizable windows

Posted: Thursday 22nd December 2022 2:25pm
by BruceSteers
Attached is a project that enables resizing of your forms when they do not have a titlebar/border
Default gambas behaviour is that if you set
Form.Border = True
That gives a window with a titlebar and a border that is resizable by clicking the edges/corners.
But if you set
Form.Border = False
then you get no titlebar, no border and the form cannot be resized

The attached program seen in the image shows how i've used it to make my own custom window that i can hide/show min/max/close buttons and has a fancy background for the hand made titlebar.

I personally have a number of applications that i want to be resizable but not have a border.
My previous solution was to have an option to show/hide the window titlebar/border to resize but that was ugly.
So this is fairly useful to me, so i share it with you :)

The Resizing can be disabled/enabled by simply setting the Form.Borderless property false or true.
(Note: Setting .Borderless = True will automatically set .Margin = True and .Border = False)

With this project you can add the Form.class from it's .src folder into your own projects .src folder then any Form of your project will have the new Property Form.Borderless
If Form.Borderless = True then the following happens to that form...
There is no titlebar/border but the window will be resizable/moveable.

There are the following options...

Form.HandleSize , sets the number of pixels from the edge that will be used for resizing.
Form.MouseMovable , makes the form move if the mouse is dragged inside the form container

Default HandleSize is form.Padding-1 (the -1 pixel is inside and used to restore the Form.Mouse state)
(Default Padding is Desktop.Scale)

So for example if you set Form.Padding = 4 and Form.HandleSize = 2 then on the left edge line pixels 1 and 2 will resize and pixels 3 and 4 will move.

Most of the feature happens in the OBS_MouseDown() and OBS_MouseMove() events of the Form.class
You can alternatively import those 2 event methods into your own forms Form_MouseDown() and Form_MouseMove() events and add/set the needed variables.

Happy Christmas :)

Re: Borderless but resizable windows

Posted: Saturday 24th December 2022 4:56am
by BruceSteers
Okay so some enhancements done now...

(Note; this project was initially a custom window thing not just about resizing a window with no titlebar so i've added to that as well as improving the resize method)

The resizing function..
  • now it takes note of any desktop Panels using the Screen.Available dimensions.
  • now it takes into account relative mouse position when clicked on right and bottom edges (it used to just put the line on Mouse screen position)
  • now setting Form.Borderless = False act's like an on/off switch as it will disable the resizing but not make Form.Border = True.
  • less likely to fail to put mouse image back to normal.
The custom window project now includes...
  • a Frame.class that supports Gradient backgrounds, used on the title and for the panels giving a nice curvy 3d effect.
  • a ShadowLabel.class , inherits Label.class and has a Shadow property to shadow text.
  • custom titlebar buttons can be hidden or placed on the left.
  • titlebar colours dim when the window is inactive.
Hopefully you my find some useful code in there :)