Custom tray panel in VB.NET - vb.net

i need to create system tray "panel" like Windows Media Player.
(not icon only, but complette form with buttons, images, etc.)
Here is wmp screenshot:
Is it possible in VB.NET & Win 10?
Thanks and sorry for my english.. :)

You actually can do kind of a "tray panel", and it isn't quite difficult. Just create a Form Object and set its FormBorderStyle property to None, which will allow you to create your custom border. Then, do the following:
Public Class Form1
Public Timer1 As New Timer
Private Sub Form1_Load(sender as Object, e as Eventargs) Handles MyBase.Load
Timer1.Interval = 1
End Sub
Private Sub Form1_MouseDown(sender as Object, e as MouseEventargs)
Timer1.Start()
End Sub
Private Sub Form1_MouseUp(sender as Object, e as MouseEventargs)
Timer1.Stop()
End Sub
Private Sub Timer1_Tick(sender as Object, e as Eventargs)
Me.Location = New Point(Me.Cursor.Position.X - (Me.Cursor.Position.X - Me.Location.X), Me.Cursor.Position.Y - (Me.Cursor.Position.Y - Me.Location.Y))
End Sub
End Class
Once you've done that (I'm not sure it will work directly, try a bit and it should), enjoy designing the GUI... ;-)
Hope this helps and by the way, your english is better than you think!

Related

VB.Net BalloonTipText appears as a black rectangle

I have a strange problem, I have created a test form FrmTest. Added a NotifyIcon and added the code shown:
Public Class FrmTest
Private Sub FrmTest_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Sub FormTest_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Click
Call SetBalloonTip()
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(30000)
End Sub
Private Sub SetBalloonTip()
NotifyIcon1.Icon = SystemIcons.Exclamation
NotifyIcon1.BalloonTipTitle = "Balloon Tip Title"
NotifyIcon1.BalloonTipText = "Balloon Tip Text."
NotifyIcon1.BalloonTipIcon = ToolTipIcon.Error
End Sub
End Class
When I click to make the balloon appear I get this:
I must be doing something obviously wrong but I am stumped!
There is nothing to say you did well...
That is what a balloon Tip looks like on Windows 10. Best of luck.

Problems loading more than 1 form - VB.net

I searched over the Stackoverflow and Google about solution for my problem but no way! so it's the time to ask my own question.
I'm making a big project using C# and VB.net (not our topic -_-)
I opened this question to ask about VB.net problem
I'm trying to load a lot of forms but in the same time, hide the previous form!
Firstly, look here on Form1:
Private Sub Timer4_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
If Label1.Text = "Setting profile.dat=Roblox.AuthAccess ..." Then
Form2.Show()
Me.Hide()
End If
End Sub
This is a timer, which detect if Label1's Text is "Setting profile.dat=Roblox.AuthAccess ..." it must show Form2 and then close Form1 (THIS IS WORKING PERFECTLY) :-)
Form2:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If WebBrowser1.Url.ToString().Contains("home") Then
Me.Hide()
Form3.Show()
End If
End Sub
This will detect if "WebBrowser1"'s URL does contain "home" then it will hide Form2 and show Form3 (AND HERE THE PROBLEM STARTED!!!)
Problem is: It shows Form3 then after 2 seconds, Form2 come back again (now both are opened once) and they're opening and closing forever (I close them by going to Task Manager and ending "vshost32.exe")
Form3:
Public Class Form3
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form2.Close()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Form4.Show()
End Sub
End Class
Actually, stopping timers is still not a stable solution and disabling them are more better.
Just replace Timer4.Stop() with Timer4.Enabled = False .
Thank you very much #jmcilhinney :)
I never thought about stopping every "Timer" after it's job had finished!
Just replaced Timer4_Tick with:
Private Sub Timer4_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
If Label1.Text = "Setting profile.dat=Roblox.AuthAccess ..." Then
Me.Hide()
Form2.Show()
Timer4.Stop()
End If
End Sub
So at last, I fixed that by adding Timer4.Stop() .

How to handle an button click even from a .dll

Could someone please guide me as to how I would get this actually working? Currently it gives me errors about WithEvents - although simplified it shows the form - but I have no clue what that actually means. It's an toolbox I'm making just to allow the user to better interact with some of my other code.
All I need is the form visuals/guts to be custom, but then the code to be done within my application (which doesn't have visual editing capabilities).
Is this a case where I need to use interfacing/partial classes/inheritance, or can this easily be accomplished with just some minor tweaking to what I have?
(Form created in visual studio form designer and then changed to a class library. Application code written in Autodesk Inventor "rule" environment)
Thanks!
Application code:
AddReference "C:\Users\Documents\Visual Studio 2013\Projects\WindowsApplication1\WindowsApplication1\bin\Release\SectionSymToolBox.dll"
Imports System.Windows.Forms
Public Class SectionSymRule
'Public dlg As New System.Windows.Forms.For
Public Shared ToolBox As New SectionSymToolBox.SectionSymToolBox
Dim WithEvents EClass As New EventClass
Sub Main()
ToolBox.Show()
End Sub
End Class
Form code:
Public Class SectionSymToolBox
Private Sub Main()
End Sub
Public Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
'Swap Symbols
End Sub
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Flip Symbol
End Sub
Public Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Flip Text
End Sub
Public Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
'<
End Sub
Public Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
'>
End Sub
End Class
Is this what you are looking for?
AddHandler ToolBox.Button1.Click, AddressOf HandlerMethodHere
Where HandlerMethod is a method that has the same signature as Button1.Click so for example:
Private Sub HandleButton1Click(sender As Object, e As EventArgs)
'Code here
End Sub
Obviously, replace Button1 with the name of the button.

VB Stopwatch Controlled by Mouse

Im making a stop watch to measure how long it takes for certain weapons to empty their clip in CS:GO. I have the stopwatch programmed, but it only seems to work if im clicking within the bounds of the window. If its possible, does anyone know how to make it able to start/stop even while in another program? Ill post the code below.
Public Class Form1
Dim WithEvents timer As New Timer
Dim milliseconds As Integer
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
Timer1.Start()
End Sub
Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles MyBase.MouseUp
Timer1.Stop()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
totalTime.Text = 0.0
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
totalTime.Text = totalTime.Text + 0.01
End Sub
End Class
The MouseDown and MouseUp events only happen when the mouse clicks within your application so you can't use them as events to track the time the mouse is held down in another application.
You may be able to do what you want using a global mouse hook or by looking at windows messages such as the Mouse Down and Mouse Up messages

How do i pass keyUp/keyDown events to panel in visual basic?

I have created a game in visual basic, and have decided to expand by adding multiple rooms on the game. Each room will be a panel that shows when the user enters a certain area. To start, I created a class that inherits panel properties, then added it to my main Form. I then added all the items to the panel controls. My issue is that i cannot control the player when it is in the panel controls. I have tried all sorts, but couldn't get it to work.
I did some reading and found that panel does not come with keyUp() and keyDown() events. However, I would like to know if there is a way round this.
Thanks in advance!
Code of mainRoom() class (my panel):
Public Class mainRoom
Inherits Panel
Sub New()
With Me
.SetBounds(0, 0, Form1.Width, Form1.Height)
.SendToBack()
End With
End Sub
Public Sub mainRoom_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Me.Paint
e.Graphics.FillRectangle(Brushes.DarkOrange, block)
End Sub
End Class
In main form class:
Sub setMap()
main = New mainRoom()
Me.Controls.Add(main)
End Sub
You can set the KeyPreview=True on the main form, and then handle the key up/down events from the form:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
'key down code.
e.Handled = True
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
'key up code.
e.Handled = True
End Sub
Note: if you don't want other controls' key up/down event handlers to fire after your form event handlers do, then set e.Handled=True as I have in the above example.
See MSDN for more info on KeyPreview.
BEWARE - when moving (cut/paste) existing controls via the IDE from a form into a new panel control, the event handlers are not carried across as they become children of the parent control (the new panel). So this happens:
Private Sub Button1_Click(sender As Object, e As EventArgs)
Add the event handlers back and don't spend an age googling why keypress events suddenly stop firing in panels ...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click