VB.NET Icon in taskbar disappears when maximizing form - vb.net

I set WindowState to Maximized in From1 properties but when I run the project, the icon in the taskbar disappear. If I set it to Normal the icon appear normally.
I tried to set the windowState to normal and then during form load setting it to maximized but without success.
Private Sub index_Load(sender As Object, e As EventArgs) Handles Me.Load
Btn_home.Visible = False
Me.WindowState = FormWindowState.Maximized
Panel1.Controls.Add(_menù)
currentPanel = _menù
'Me.ShowInTaskbar = True
End Sub
If I move Me.WindowState = FormWindowState.Maximized after currentPanel = _menù
is showing normally but I don't know why and also I have to get the size of the form maximized in the panel _menù.

Related

Minimize form when minimize button is clicked in VB.NET

I have a form which is maximized with this property:
Me.WindowState = FormWindowState.Maximized
and with FormBorderStyle = None. This means that when this form is opened, it can not be minimized, which is the behavior I want.
From this main form, there is a button which open another small form called 'Console' where I can see some messages thrown by the main form. This 'Console' form is with FormBorderStyle = FixedSingle, and this means that can be minimized.
The problem with this, is that when I minimize the 'Console' form, I can not opened again because the main form occupy the whole screen.
What I am trying to do is to minimize the 'Console' and be able to see it to maximize it again when I wish.
I tried to use events of the 'Console' form like SizeChanged or KeyUp and control when the minimize button is pressed.
All things I tried have gone wrong, and always when I press the minimize button, the form minimizes normally.
It is possible when I minimize the form by clicking on the minimize button, to see the minimize window down to maximize it when I want?
I accept any suggestions!
Finaly I've used this option: when I click to minimize, I just relocate the form and resize it. Maybe is a simple and manual option and for sure it will be better ways to do it, but this gives me what I need for now.
#HansPassant thanks for your help! I am going to look for information about docking layout manager as you suggested.
Here is the code:
Private Sub frmConsole_Move(sender As Object, e As EventArgs) Handles MyBase.Move
If Me.WindowState = FormWindowState.Minimized Then
Me.Size = New System.Drawing.Size(247, 0)
Me.WindowState = FormWindowState.Normal
Me.Location = New Point(padre.GMapControl.Location.X, padre.GMapControl.Location.Y + 1000)
Me.TopMost = True
ElseIf Me.WindowState = FormWindowState.Maximized Then
Me.Size = New System.Drawing.Size(447, 900)
Me.WindowState = FormWindowState.Normal
Me.Location = New Point(padre.Location.X + padre.GMapControl.Width * 0.9, padre.Location.Y)
End If
End Sub
I've used some buttons location of the main form to locate the 'Console' form, but it can be any value.
Thanks!

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 Borderless Form Maximize over Taskbar

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

Run VB.net program minimized

As shown in the picture, I want my vb.net application to run minimized like that a show a pop-up when the minimize button is hit. Is there a way I can do that?
Try this...
You can use the notifyicon control...Hide the form when it's minimized and show the notifyicon, otherwise, show the form and hide the notifyicon control...
Add notifyicon control
Add this code under the form resize event
If Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Minimized
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(5, "System", "DoubleClick on the Icon to restore the application.", ToolTipIcon.Info)
Me.Hide()
End If
Under the doubleclick event of notifyicon control, add this code...
Me.Show()
Me.WindowState = FormWindowState.Maximized
NotifyIcon1.Visible = False

VB.net form restore not showing form

I'm currently using VB.Net 2008.
The project has the "make single instance application" checkbox checked.
The application works by hiding the form when the form is minimized.
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.Hide()
End If
End Sub
When the appropriate menu item is pressed within the notifyicon the form should show itself again.
Private Sub ShowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ShowToolStripMenuItem.Click
Me.Show()
Me.WindowState = FormWindowState.Normal
End Sub
This works fine until the user tries to open the same application while the form is minimized. When this occurs the application will block a new instance of the application the user was trying to open as expected, however when the user then goes to show the form from the notifyicon's menu it will have seemed to open (it shows the form in the taskbar) but no window is shown.
At this point the window can be maximized and works as intended but by using the restore button the window will not be drawn but will still be shown in the taskbar.
If any help can be given on how to restore the form correctly from being hidden it would be most appreciated.
Thanks in advance
Just a couple of suggestions...
Instead of using Hide() and Show(), could you use the ShowInTaskbar property of the form instead?
Set it to false where you use Hide() and true where you currently use Show(), and see if that makes any difference.
Or perhaps set the WindowState to Normal before calling Show().