VB.net Borderless Form Maximize over Taskbar - vb.net

When I maximize my borderless form, the form covers the entire screen including the taskbar, which I don't want it to do. I'm finding it very difficult to find a solution to my problem on the net, all I've come up with is the below code, which displays the taskbar for a short time, but then disappears and the form still takes up the entire screen.
Private Sub TableLayoutPanel1_DoubleClick(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.DoubleClick
If e.Location.Y < 30 Then
Me.WindowState = FormWindowState.Maximized
Me.ControlBox = True
End If
End Sub
I'm starting to think the only way to solve my problem is to find the screen size height minus the taskbar height to get the form height, but I'm hoping there might be a simpler answer.

Use the form's Load event to set its maximum size, like this:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.MaximumSize = Screen.FromRectangle(Me.Bounds).WorkingArea.Size
End Sub
Maximizing it now restricts the size to the monitor's working area, which is the monitor size minus the taskbars.

Use the "working area" of the screen:
Me.Bounds = Screen.GetWorkingArea(Me)

You should better do this:
Me.MaximumSize = Screen.FromControl(Me).WorkingArea.Size
Because some users use multiple monitors. So if you use Hans Passant's way, when user maximize application to secondary monitor, application will get primary's monitor working area size and will look awful!!!

I think this is a better way to solve your problem
Private Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Normal
Me.StartPosition = FormStartPosition.Manual
With Screen.PrimaryScreen.WorkingArea
Me.SetBounds(.Left, .Top, .Width, .Height)
End With
End Sub

Related

Custom minimize button loses original minimize button animation

I would like to know if there is a way of keeping the Original Animation to keep my VB application as close to original as possible.
Private Sub Minimize_Click(sender As Object, e As EventArgs) Handles Minimize.Click
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
End Sub
I expect the minimize action to play the animation that ocurs in most if not all of the windows applications.
[Edit]:
All the apps I have installed have the default minimize animation because they all use the same windows bar, but my program doesn't because I find it not very attractive, so I created my own Print By programming the button myself I lose the animation.
You could use the opacity to create an animation of sorts.
Private Sub Minimize_Click(sender As Object, e As EventArgs) Handles Minimize.Click
For disapper As Single = 1.0! To 0 Step -0.2!
Me.Opacity = disapper
'Me.Refresh()
System.Threading.Thread.Sleep(50)
Next
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
Me.Opacity = 1.0!
End Sub
So I found that the problem is that my formborderstyle propety is set to none and the animation isn't shown when it is set to none I solved it by doing this, but even tho it works it worses things even more... For now I will stick with having no animation at all unless someone finds a solution. Thanks.
Private Sub Minimize_Click(sender As Object, e As EventArgs) Handles Minimize.Click
Me.FormBorderStyle = FormBorderStyle.FixedSingle
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
Me.FormBorderStyle = FormBorderStyle.None
End Sub
Any app minimization animation is in windows settings, and can be turned off anyway. I Don't think you can force it if you have it disabled in your userprofile System Properties settings.
This can be found in sysdm.cpl in Advanced -> Performance

Panel edge detection, stop before going out of bounds

I have a panel inside it's parent panel that I allow to move. I want it to stop moving BEFORE it falls out of the parent panel. What is the best way to accomplish this. Also I add the panels dynamically.
UPDATE:
Here is the code that goes into the "MyPanel" Panel. Only difference between "MyPanel" vs "Panel" is I add a border and the ability to move it. The "CoolMove" was from another person's answer I found online. I add a "MyPanel1" to form and then add another "MyPanel2" to that and allow it to move only if it is on the "MyPanel1". So with that, I want "MyPanel2" to stay completely in bounds of "MyPanel1". I'm struggling to get the right code to accomplish this.
Private allowCoolMove As Boolean = False
Private myCoolPoint As New Point
Public Overridable Sub MyPanel_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
'If panel is ontop of Stock panel, then allow manual moving
If Me.Parent.Name.StartsWith("S") Then
allowCoolMove = True
myCoolPoint = New Point(e.X, e.Y)
Me.Cursor = Cursors.SizeAll
Me.BringToFront()
ElseIf Not Me.Parent.Name.Contains("keyR") Then
DoDragDrop(Me, DragDropEffects.Move)
End If
End Sub
Private Sub MyPanel_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If allowCoolMove = True Then
Me.Location = New Point(Me.Location.X + e.X - myCoolPoint.X, Me.Location.Y + e.Y - myCoolPoint.Y)
End If
End Sub
Private Sub MyPanel_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
allowCoolMove = False
Me.Cursor = Cursors.Default
End Sub
Each control has a ClientRectangle property that returns the dimensions of its client area (which, for a panel, is the interior part). There is also a DisplayRectangle property, which tells you the entire area of the control.
And the Rectangle structure has a Contains method overload that takes another Rectangle structure and tells you whether one rectangle is fully contained within the bounds of another rectangle.
You should be able to put those two facts together, now, to come up with code that will solve your problem. Something like:
Dim rcParentPanelInterior As Rectangle = parentPanel.ClientRectangle
Dim rcChildPanel As Rectangle = childPanel.DisplayRectangle
If rcParentPanelInterior.Contains(rcChildPanel)
' continue to allow moving
Else
' forbid moving
End If

Un-maximize size of the form

I'm having a little something in my program that's bothering me and I would like some help please.
My form size is: 1366; 768 (that's the max resolution of the laptop I use). The form loads and it's a little bit smaller than my screen size, so I changed the load event of the form so that it starts maximized.
Private Sub form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
End Sub
Now, when I press the maximize button while the form is maximized (un-maximize), the form gets a little bit smaller. Can I choose what size to un-maximize? I want the form to be 800 x 600 when I press that button.
Thanks in advance.
Well, if you need the un-maximized event to be different than the designer size, then just set it in your OnLoad override:
Protected Overrides Sub OnLoad(e As EventArgs)
MyBase.OnLoad(e)
Me.WindowState = FormWindowState.Maximized
Me.Size = New Size(800, 600)
End Sub

VB.net - Mousehover not sensitive

I made picturebox which would change if the mover is over the image but it takes too long. can someone help me please?
Here's my code:
Private Sub button2_MouseHover(sender As Object, e As EventArgs) Handles button2.MouseHover
button1.Visible = True
button2.Visible = False
End Sub
Private Sub button1_MouseLeave(sender As Object, e As EventArgs) Handles button1.MouseLeave
button1.Visible = False
button2.Visible = True
End Sub
Thanking you in advance
If you want to adjust the time the mouse must pause over the image, the docs say;
A typical use of MouseHover is to display a tool tip when the mouse pauses on a control within a specified area around the control (the "hover rectangle"). The pause required for this event to be raised is specified in milliseconds by the MouseHoverTime property.
To achieve that, simply change the value of SystemInformation.MouseHoverTime in your code.
Alternatively, as someone has commented, use a MouseEnter event instead, this will trigger instantly.

Howto add a custom border to a FormBorderStyle=None - form?

I have a form with the property FormBorderStyle set to 'None' and with a custom bar on top side for dragging and buttons.
Now I'd like to give the form a border because it's a child form and the parent form has the same background color as the child, so it's hard to see the child form.
And no, I can't/won't change the background color.
Help
There is a way without a need to set a background image and/or fixed sized form. So this is the most proper and simple way I guess. Say you have a form named Form1, all you need to do is:
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.Black, ButtonBorderStyle.Solid)
End Sub
An alternative, if you want to use the default border provided by your Windows version:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
Me.Text = ""
Me.ControlBox = False
End Sub
You can use the Visual Basic .NET Power Packs which you can download here. It has this Control called LineShape that you can put onto your border-less form's edges, like this one program that I am currently working on.
The north border is just a LineShape with a BorderWidth set to 60 and the other borders' BorderWidths are set to 10.
Maybe you can use a BackgroundImage transparent except in the borders.
You can use this on the form paint event:
ControlPaint.DrawBorder(e.Graphics, Me.ClientRectangle, Color.Black, ButtonBorderStyle.Solid)
This will draw the client border only, also if you are resizing the form, or maximizing the form use Me.Refresh() on form resize events so that the form redraws its borders.
After seeing the answer by theGD, I did the same thing for a TableLayouPanel on a form:
Private Sub TableLayoutPanel1_Paint(sender As Object, e As PaintEventArgs) Handles TableLayoutPanel1.Paint
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.DarkOrange, ButtonBorderStyle.Solid)
End Sub