Tray application not displaying properly - vb.net

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.

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:

how to navigate adorner when click button

I create a sample of adorner to inform client the use usage of each component.
What i want to ask is, how do i move the control/adorner to other component.
in the picture when i click the help button,it show the adorner. how do i move the adorner to the textedit2 purple square. the adorner using usercontrol.
this is the form1 code
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AdornerUIManager1.ShowGuides = DevExpress.Utils.DefaultBoolean.True
End Sub
Private Sub AdornerUIManager1_QueryGuideFlyoutControl(sender As Object, e As DevExpress.Utils.VisualEffects.QueryGuideFlyoutControlEventArgs) Handles AdornerUIManager1.QueryGuideFlyoutControl
If e.SelectedElement.TargetElement Is Button1 Then
e.Control = New LabelControl() With {
.AllowHtmlString = True,
.Width = 350,
.AutoSizeMode = LabelAutoSizeMode.Vertical,
.Padding = New Padding(20),
.Text = "<b>Navigation Bar</b><br>" & "A side navigation control that supports integration with Office Navigation Bar<br><br>" & "Shows navigation options for your currently selected module"}
End If
If e.SelectedElement.TargetElement Is TextEdit1 Then
Dim x As New UserControl1
x.Label1.Text = "xxXXXxx"
x.WindowsUIButtonPanel1.Buttons(0).Properties.Checked = True
e.Control = x
End If
End Sub
this is the usercontrol code
Public Class UserControl1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim x As Form1
x.AdornerUIManager1.Elements(0).TargetElement = x.TextEdit3
End Sub
End Class
when i try to click, it got error

How to make a label blink

I have a Stopwatch in my form with Interval = 1000 displayed in the hh:mm:ss format.
When it reaches the 5th second it should start to blink the label background as green but so far I can only make the background color turn to green without any flash.
This is how I turn the background color to green:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label1.Text = SW.Elapsed.ToString("hh\:mm\:ss")
If Label1.Text = "00:00:05" Then
Label1.BackColor = Color.Green
End If
End Sub
How do I make the label blink?
You could use a simple Async method to do this.
The following code will give Label1 the effect of flashing. Since we have used While True this will continue indefinitely once you hit "00:00:05".
Private Async Sub Flash()
While True
Await Task.Delay(100)
Label1.Visible = Not Label1.Visible
End While
End Sub
You would call this inside your Timer1_Tick method:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label1.Text = SW.Elapsed.ToString("hh\:mm\:ss")
If Label1.Text = "00:00:05" Then
Label1.BackColor = Color.Green
Flash()
End If
End Sub
If you only want to flash a couple of times we can make a simple change to Flash():
Private Async Sub Flash()
For i = 0 To 10
Await Task.Delay(100)
Label1.Visible = Not Label1.Visible
Next
'set .Visible to True just to be sure
Label1.Visible = True
End Sub
By changing the number 10 to a number of your choice you can shorten or lengthen the time taken to flash. I have added in Label1.Visible = True after the For loop just to be sure that we see the Label once the flashing has finished.
You will have to import System.Threading.Tasks to make use of Task.Delay.
You need a label, two textboxes, and a button.
The screen allows you to 'set' a couple of colours - this could be taken further, by adding an Error colour, a Warning colour (where you haven't filled a field in...?) and more.
This colour selection would, in a real application, be done by an admin person, from a separate screen, and stored in the DB.
The timer frequency would also be set in the Admin screen/function.
This particular screen needs the textboxes to be double-clicked, and a colour selected for each one.
The back colour for each box changes. Then press the Start button.
If you press the Start button again, it toggles the timer (on/off)
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' not quite correct for what I want, but close...
' https://bytes.com/topic/visual-basic-net/answers/368433-blinking-text
Me.Label1.Text = "A blinking text box"
Me.Label1.BackColor = TextBox2.BackColor
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Me.Label1.BackColor = TextBox2.BackColor Then
Me.Label1.BackColor = TextBox1.BackColor
Else
Me.Label1.BackColor = TextBox2.BackColor
End If
End Sub
Private Sub TextBox1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseDoubleClick
Dim dlg As New ColorDialog()
If dlg.ShowDialog() = DialogResult.OK Then
TextBox1.BackColor = dlg.Color
End If
End Sub
Private Sub TextBox2_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles TextBox2.MouseDoubleClick
Dim dlg As New ColorDialog()
If dlg.ShowDialog() = DialogResult.OK Then
TextBox2.BackColor = dlg.Color
End If
End Sub
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
Timer1.Enabled = Not Timer1.Enabled
End Sub
End Class
Try to put something like this in Timer1_Tick event handler -
Label1.Visible = Not Label1.Visible
Set the timer to enabled and it will do the job.
If you specify the color when the Text is 00:00:05 then you should also specify what the Backcolor should be when the text is something else i.e 00:00:06
Try this and see if it works:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label1.Text = SW.Elapsed.ToString("hh\:mm\:ss")
If Label1.Text = "00:00:05" Then
Label1.BackColor = Color.Green
else
Label1.Backcolor = Color.Yellow '(Change color as needed)
End If
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

How to Dock to StatusBar

I have Form with StatusBar on it. On StatusBar there are ToolStripStatusLabel1 and ToolStripProgressBar1. Normaly, ToolStripProgressBar is not visible.
But when I start file copying ToolStripStatusLabel1 becames invisible and ToolStripProgressBar becames visible.
like this:
ToolStripStatusLabel1.Visible = False
ToolStripProgressBar1.Visible = True
Problem is that in this condition I cant get that ProgressBar take all the space of StatusBar not with increasing it's width nor with setting it's Dock property to .Fill.
ToolStripStatusLabel1.Visible = False
ToolStripStatusLabel1.Width = 0
ToolStripProgressBar1.Dock = DockStyle.Fill
Is it possible to get ToolStripProgressBar1 to take full Width of StatusBar in described situation?
The ToolStripProgressBar is quite limited and can't do what you want.
An alternative is to make a regular ProgressBar take the place of your entire StatusStrip:
Public Class Form1
Private PB As New ProgressBar
Private ShowProgress As Boolean = False
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ShowProgressBar(True)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ShowProgressBar(False)
End Sub
Private Sub ShowProgressBar(ByVal Visible As Boolean)
ShowProgress = Visible
If ShowProgress Then
Dim rc As Rectangle = StatusStrip1.RectangleToScreen(StatusStrip1.ClientRectangle)
PB.Bounds = Me.RectangleToClient(rc)
PB.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Bottom
Me.Controls.Add(PB)
PB.BringToFront()
Else
Me.Controls.Remove(PB)
End If
End Sub
End Class