Run a Program even if in system tray vb.net - vb.net

*I have a program that copies files from one directory to the other. I want it to run when minimised and an icon should show in the system tray so I created these codes. The minimise and system tray icon shows but AS SOON AS IT IS MINIMISED, THE COPYING SEIZES. I want the process to continue when the form is minimised. Please Help.
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
Notif.Visible = True
Notif.BalloonTipText = "Copying"
Notif.BalloonTipTitle = "Serious Copying"
Notif.ShowBalloonTip(5000)
Notif.Text = "Serious Copying"
ShowInTaskbar = False
Me.Visible = False
End If
End Sub
Private Sub notifycn1_DoubleClick(sender As Object, e As EventArgs) Handles notifycn1.DoubleClick
Me.Visible = True
Me.show()
ShowInTaskbar = True
Notif.Visible = False
Me.WindowState = FormWindowState.Normal
End Sub

Related

Autoscroll inconsistent

Im having a hardtime figuring What went wrong ,My program Has 3 buttons (Bread,Coffe,Pasta) and a panel, each buttons show a different form,
I currently set the Panel's autoscroll to true
MenuPanel.AutoScroll = True
The Coffee,bread and pasta button function is
Private Sub btnCoffee_Click(sender As Object, e As EventArgs) Handles btnCoffee.Click
MenuPanel.Controls.Clear()
CoffeeForm.TopLevel = False
CoffeeForm.WindowState = FormWindowState.Maximized
CoffeeForm.Visible = True
MenuPanel.Controls.Add(CoffeeForm)
CoffeeForm.Show()
End Sub
Private Sub btnBread_Click(sender As Object, e As EventArgs) Handles btnBread.Click
MenuPanel.Controls.Clear()
BreadForm.TopLevel = False
BreadForm.WindowState = FormWindowState.Maximized
BreadForm.Visible = True
MenuPanel.Controls.Add(BreadForm)
BreadForm.Show()
End Sub
Private Sub btnPasta_Click(sender As Object, e As EventArgs) Handles btnPasta.Click
MenuPanel.Controls.Clear()
PastaForm.TopLevel = False
PastaForm.WindowState = FormWindowState.Maximized
PastaForm.Visible = True
MenuPanel.Controls.Add(PastaForm)
PastaForm.Show()
End Sub
The autoscroll works for the first time and after Some clicks on the The buttons (Maybe 4-5 clicks and scrolled with Mousewheel)
the Vertical Scrollbar disappear from the panel
what went wrong?
I am currently using vb.net 2019
1:

Application.Exit() not working when using form closing methods to minimise to tray

I am using this code to minimise the form to the tray when the X button is pressed
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
NotifyIcon1.Visible = True
NotifyIcon1.Icon = SystemIcons.Application
NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
NotifyIcon1.BalloonTipTitle = "Running In the Background"
NotifyIcon1.BalloonTipText = "Application is running in the Background. Double click it to maximize the form"
NotifyIcon1.ShowBalloonTip(50000)
Me.Hide()
ShowInTaskbar = True
e.Cancel = True
End Sub
I have a Quit button too which will actually exit the application, but I think it's using the code above to minimise the form instead.
Private Sub btn_Quit_Click(sender As Object, e As EventArgs) Handles btn_Quit.Click
Dim confirm As DialogResult = MessageBox.Show("Are you sure you wish to Exit the App?", "Exit Application?", MessageBoxButtons.YesNo)
If confirm = DialogResult.Yes Then
Application.Exit()
End If
End Sub
How can I override the FormClosing sub when using the Quit button?
I tried using End but that didn't work either
You should use the FormClosingEventArgs passed to Form_Closing handler. It will tell you whether someone tried to close the Form, or if the application is exiting. There are other reasons too which you can check out
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Select Case e.CloseReason
Case CloseReason.ApplicationExitCall
e.Cancel = False
Case CloseReason.FormOwnerClosing
NotifyIcon1.Visible = True
NotifyIcon1.Icon = SystemIcons.Application
NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
NotifyIcon1.BalloonTipTitle = "Running In the Background"
NotifyIcon1.BalloonTipText = "Application is running in the Background. Double click it to maximize the form"
NotifyIcon1.ShowBalloonTip(50000)
Me.Hide()
ShowInTaskbar = True
e.Cancel = True
End Select
End Sub

Tray application not displaying properly

Below I have the code for a framework I am working with. The problem I am having is that the Icon will not show up in the system tray unless the commented code is included. The weirdest part is that the other lines of code for the notifyicon1 properties will then work. Can someone please help me understand what is going on?
Public Class Main
Public WithEvents notifyicon1 As New NotifyIcon
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Width = 1200
Height = 850
ShowIcon = True
Me.Text = "V1.0.0.0"
' icon
Icon = My.Resources.icon_4
'set the form properties
BackColor = Color.White
Dim start As New startup()
End Sub
Private Sub Main_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
notifyicon1.Visible = True
Me.Hide()
Icon = My.Resources.icon_4
notifyicon1.Visible = True
notifyicon1.BalloonTipText = "Hi from right system tray"
notifyicon1.ShowBalloonTip(500)
'With notifyicon1
' .Icon = My.Resources.icon_4
' .Visible = True
' .ShowBalloonTip(500)
'End With
End If
End Sub
Private Sub NotifyIcon1_DoubleClick(sender As Object, e As MouseEventArgs) Handles notifyicon1.DoubleClick
Me.Show()
Me.WindowState = FormWindowState.Normal
notifyicon1.Visible = False
End Sub
End Class
As Hans pointed out, you need to set the notifyicon1's Icon property, which you do in the With statement, but not in the code above.
Change the Icon = My.Resources.icon_4 with notifyicon1.Icon = My.Resources.icon_4, as you don't seem to be using the Icon property anywhere.

Is it possible to use ToolStrip Controller as TabMenu in VB.net?

i am new at VB.net.. i am making one Application for my friend. but i have one problem while using toolstrip...
i want to use toolstrip menu as tabmenu... like if i select any button from toolstrip menu, than form content change..just like while we change tab then form content will change which is inside that tab...is it possible to do so?
I don't have any code at the moment so i can not attach it..i have tried googling my problem but i didn't found any solution of this problem...hope you guys understand my problem..thank you!
If I understand you correctly, for each "tab" you could create a panel on your form and set the Visible property of each to False. Then for each button click event in your ToolStrip, you could make them all Visible=False apart from the one you want to show.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Panel1.Visible = False
Panel2.Visible = False
Panel3.Visible = False
End Sub
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
Panel1.Visible = True
Panel2.Visible = False
Panel3.Visible = False
End Sub
Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
Panel1.Visible = False
Panel2.Visible = True
Panel3.Visible = False
End Sub
Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click
Panel1.Visible = False
Panel2.Visible = False
Panel3.Visible = True
End Sub
End Class

Create a program to run from the system tray

I would like to create a program to run from the bottom right system tray of Windows.
But I don't know where to start from?
Can someone tell \ show me where to look and examples or what commands to use \ research ?
Add a NotifyIcon to the main windows form.
Use the Resize event in Form to control when to show the NotifyIcon and hide the form:
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
NotifyIcon1.Visible = true
Me.Hide()
NotifyIcon1.BalloonTipText = "Hi from right system tray"
NotifyIcon1.ShowBalloonTip(500)
End If
End Sub
Use the events in NotifyIcon to show the form again:
Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.Show()
Me.WindowState = FormWindowState.Normal
NotifyIcon1.Visible = False
End Sub
You can download a full example in AutoDNIE google code project
I review the answers I note that miss the icon.
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
NotifyIcon1.Visible = True
NotifyIcon1.Icon = SystemIcons.Application
NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
NotifyIcon1.BalloonTipTitle = "Verificador corriendo"
NotifyIcon1.BalloonTipText = "Verificador corriendo"
NotifyIcon1.ShowBalloonTip(50000)
'Me.Hide()
ShowInTaskbar = False
End If
End Sub
Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
'Me.Show()
ShowInTaskbar = True
Me.WindowState = FormWindowState.Normal
NotifyIcon1.Visible = False
End Sub
You can also do:
Sub ToggleHide()
If Me.WindowState = FormWindowState.Normal Then
Me.ShowInTaskbar = False
Me.WindowState = FormWindowState.Minimized
Else
Me.ShowInTaskbar = True
Me.WindowState = FormWindowState.Normal
End If
End Sub