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!
Related
I have a panel and button.
A form with some text-box.
Trying to display form inside my panel. code that i have written is....
Private Sub Btn_Click(sender As Object, e As EventArgs) Handles Btn.Click
Dim f As New form()
f.TopLevel = False
f.WindowState = FormWindowState.Normal
f.FormBorderStyle = FormBorderStyle.None
f.Visible = True
Pages.Controls.Add(f)
End Sub
in another page, i have written.....
Dim f As New add_customer()
f.TopLevel = False
f.WindowState = FormWindowState.Normal
f.FormBorderStyle = FormBorderStyle.None
f.Visible = True
Form1.Pages.Controls.Add(f)
Form displays inside panel. Button inside that form works well, Combo-box works well, Check-box works well, all most everything works well, but text-box isn't working.
Tried that form to open outside panel. All is fine. But inside panel it doesn't work.
All the letters and text-box become transparent.
Main form
After Customer button clicked
After add customer button clicked
When pages run solely....
Help needed.
I have found the solution.
When the TransparencyKey property is assigned a Color, the areas of the form that have the same BackColor will be displayed transparently. Any mouse actions, such as the click of the mouse, that are performed on the transparent areas of the form will be transferred to the windows below the transparent area. For example, if the client region of a form is made transparent, clicking the mouse on that area would send the event notification of the click to any window that is below it. If the color assigned to the TransparencyKey property is the same as any controls on the form, they also will be displayed transparently.
I was unaware of this property of Transparency.
I Have changed background colour and all is good now.
Thanks Visual Vincent for your fast reply.....
This link is useful.
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.transparencykey(v=vs.110).aspx
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
I'll just get straight to it, I have this code:
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
startup.Show()
Me.WindowState = FormWindowState.Minimized
Me.ShowInTaskbar = False
Me.Hide()
End Sub
This is going to be the form which loads first, having the entire project shutting down when this form closes (hence why I have to load this form first & calling the startup from this)
After the startup form has finished it's code, I have this code:
...
frmMain.ShowInTaskbar = True
frmMain.WindowState = FormWindowState.Normal
Me.Close()
How can I get the main form to load again without actually triggering it's _load event (thus avoiding it to trigger an infinite loop).
did you mean show the main form?
frmMain.Show()
frmMain.BringToFront()
Try this in order to show the hidden form:
frmMain.Show()
I'd suggest a better way to tackle this is to show the startup form from the application startup event. Your main form can then be a main form instead of being hidden.
startup.WindowState = FormWindowState.Normal
Call startup.Show()
Call startup.BringToFront()
Call startup.Activate()
The essential step to unhide from windowstate minimized, which is the windowstate of hidden forms, is to change the windowstate to normal. An example of this is shown in my first line of code. The other lines are for showing, bringing to the front and activating the formerly hidden form with the name startup. Goodluck!
I have a 1080p touchscreen application. When a modal pops up, i want to emphasize that by darkening the main form.
Right now i use a second form, the size of the main form, that is black and has 50% opacity. Whenever a modal needs to appear, i open the opaque form, and then open the desired modal.
I feel this is a bit devious for my purpose. Its also not asshole-proof that when the user alt tabs, the forms will glitch out of sequence.
Is there a better way to achieve the darkening effect. Perhaps by darkening the main form from within itself?
Solved it myself by doing the following:
Place a hidden picturebox with dock:fill on the main form,
Take a screenshot of the current screen and darken it
assign the image to the picturebox and make it visible
open the modal in a new win
when the modal is dismissed
hide the picturebox
It really stupid that VB.net doesn't have this function built into it. Here's what you do to get around it:
Make a new form and call it Shade. I'm going to assume your main form is called frmMain. For the sake of clarity, lets assume the form you're launching is called dlgX.
Add the following lines in the Load event of dlgX (that's the sub with dlgX.Load or Me.Load or MyBase.Load):
Shade.Opacity = 0.001
Shade.Show()
Shade.Location = frmMain.Location ' Form location will only update if the form is visible.
Shade.Hide()
Shade.FormBorderStyle = Windows.Forms.FormBorderStyle.None 'This gets rid of the windows Titlebar and window border.
Shade.Size = frmMain.Size
Shade.BackColor = Color.Black
Shade.Opacity = 0.5
Shade.Show() ' Form size will only update the next time you show it.
Shade.TopMost = True ' Puts Shade over main form
Me.TopMost = True ' Puts current form over shade
Under all events that dismiss the form dlgX (OK.click, Cancel.click, etc), add the following lines:
Shade.Close
Or you can even make your own sub that handles all events where the form is closed:
Private Sub DispelShades(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosed
Shade.Close()
End Sub
This is way simpler than the PictureBox scenario and you don't have to mess with layering issues and having to ensure that the PictureBox renders on top of everything (for example, tabs really do not like having things rendered above them and they will not let you render a picture box above them). Rendering a black semi transparent form above your main form gets around all these headaches.
If you have multiple forms to shade, just make a Shad1, Shade2, Shade3 etc.
This is pretty obvious but it's worth stating: if you're shading the main form, you'll also want to make it unclickable by opening dlgX via dlgX.ShowDialog and not dlgX.Show
Here is some code, very similar to the method in Thomas's answer. Note to use the Darkness property in a Try...Finally block, to make sure you never leave the form in the dark state.
Public Class Form1
Private _PB As PictureBox
Public WriteOnly Property Darkness
Set(value)
If value Then
Dim Bmp = New Bitmap(Bounds.Size.Width, Bounds.Size.Height)
Me.DrawToBitmap(Bmp, New Rectangle(Point.Empty, Bounds.Size))
Using g = Graphics.FromImage(Bmp)
Dim Brush As New SolidBrush(Color.FromArgb(125, Color.Black))
g.FillRectangle(Brush, New Rectangle(Point.Empty, Bmp.Size))
End Using
_PB = New PictureBox
Me.Controls.Add(_PB)
_PB.Size = Bounds.Size
_PB.Location = Bounds.Location - PointToScreen(Point.Empty)
_PB.Image = Bmp
_PB.BringToFront()
Else
If _PB IsNot Nothing Then
Me.Controls.Remove(_PB)
_PB.Dispose()
End If
End If
End Set
End Property
Private Sub btnDialog_Click(sender As Object, e As EventArgs) Handles btnDialog.Click
Try
Darkness = True
MsgBox("Modal dialog")
Finally
Darkness = False
End Try
End Sub
End Class
Is there a way to force a form to be active and shown?
From another form i am doing:
Me.Hide
Form2.Show
When this code is run, the Form2 is minimized.
I've also tried:
Me.WindowState = FormWindowState.Normal
in the load event, and it still loaded it in minimized mode.
Try Me.BringToFront(); or you can set the property TopMost true and thus the form will be always on top.