Create a program to run from the system tray - vb.net

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

Related

Vb. net button second click

On first click I'd like to see listbox and some buttons disabled.
On second click I'd like to see that listbox and buttons enabled again.
My current code is:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button2.Click
lstbx_1.Enabled = False
lstbx_2.Enabled = False
outbtn.Enabled = False
Button2.Text = "remove approval"
End Sub
Try this code:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
lstbx_1.Enabled = Not (lstbx_1.Enabled)
lstbx_2.Enabled = Not (lstbx_2.Enabled)
outbtn.Enabled = Not (outbtn.Enabled)
If lstbx_1.Enabled = False Then
Button2.Text = "remove approval"
Else
Button2.Text = "Your Text"
End If
End Sub

Application not quitting

I coded my application to hide and show icon in the system tray. When you click on icon and exit, my application disappear but the application still shows running in task manager. Here's my closing:
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
NotifyIcon1.ContextMenuStrip = ContextMenuStrip1
End sub
Private Sub OpenWorkSheet_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = True
Me.Visible = False
Me.NotifyIcon1.Visible = True
End Sub
Private Sub OpenToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem1.Click
Try
NotifyIcon1.ContextMenuStrip = ContextMenuStrip1
Me.Visible = True
Me.WindowState = FormWindowState.Normal
NotifyIcon1.Visible = False
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Visible = True
Me.WindowState = FormWindowState.Normal
NotifyIcon1.Visible = False
Me.Close()
Application.Exit()
Me.Dispose()
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Try
NotifyIcon1.ContextMenuStrip = ContextMenuStrip1
Me.Visible = True
Me.WindowState = FormWindowState.Normal
NotifyIcon1.Visible = False
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Declare a boolean variable indicating if you're closing the entire application, so that you can let your form close correctly.
This will only set e.Cancel to True if you are not choosing to close the entire application.
Dim ClosingApp As Boolean = False
Private Sub OpenWorkSheet_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If ClosingApp = False Then
e.Cancel = True
Me.Visible = False
Me.NotifyIcon1.Visible = True
End If
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
ClosingApp = True
NotifyIcon1.Visible = False
Me.Close()
Application.Exit()
End Sub
I also removed some superfluous lines, for instance disposing the form isn't necessary as A) You are already closing the application, all its used memory will be released. B) Closing the form automatically disposes it.

Run a Program even if in system tray 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

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

Enable and disable TextBox with a checkbox in visual basic

I've 6 TextBox and 6 CheckBox. Now I want to disable the TextBox1 with a CheckBox1 and reactivate it with the Same CheckBox.
How a can do it?
Edit1 15.55 14/02/2013
I have done so to solve my problem!
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox1.Enabled = False
ElseIf CheckBox1.Checked = False Then
TextBox1.Enabled = True
End If
End Sub `
This will work, just add more for the other check boxes
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox1.Enabled = True
Else
TextBox1.Enabled = False
End If
End Sub
What this does: if checkbox1 is check, the checked_changed event fires and the code inside is ran. The if statement looks to see if the checkbox is checked or not. If it is checked, then it sets the textbox1 to enabled, if not it sets it to disabled. Be sure to set the enabled property to either enabled or disabled when you create your program. If you want it to be enabled from the start, that is the default....otherwise set it to disabled in its properties view.
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
TextBox1.Enabled = CheckBox1.Checked
End Sub
Take a look at this tutorial below. After, look at the checkbox control's events and choose the most fitting one. The property you will be changing on the textbox is Enabled.
http://www.youtube.com/watch?v=4PbUryXqZ50
This works if you have a layer built in that you can send objects behind (therefore hide things). I use this as a way to make text boxes and other items appear and disappear depending on other selections.
Private Sub checkbox_Click()
If (checkbox = True) Then
ActiveSheet.Shapes("textbox").ZOrder msoSendToFront
ActiveSheet.Shapes("textbox").ZOrder msoSendToFront
Else
ActiveSheet.Shapes("textbox").ZOrder msoSendToBack
ActiveSheet.Shapes("textbox").ZOrder msoSendToBack
End If
End Sub
This worked for me:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.Enabled = False
If Not TextBox1.Enabled Then
TextBox1.BackColor = Color.White
End If
End Sub
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox1.Enabled = True
Else
TextBox1.Enabled = False
End If
End Sub
End Class