Media Player won't do anything - vb.net

My code looks to be right, but when I press button nothing happens. What am I doing wrong?
Code below:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AxVLCPlugin21.playlist.add("C:\Users\Adminx\Downloads\The_Hobbit_Full_Length_Trailer_2_HD.mp4")
AxVLCPlugin21.playlist.play()
End Sub
End Class
Also in my toolbox the vlc things are written in Chinese. Is it meant to look like that (look at picture below)

I've figured what I was doing wrong
I needed to change:
AxVLCPlugin21.playlist.add("C:\Users\Adminx\Downloads\The_Hobbit_Full_Length_Trailer_2_HD.mp4")
To this:
AxVLCPlugin21.playlist.add("file:///C:/Users/Adminx/Downloads/The_Hobbit_Full_Length_Trailer_2_HD.mp4")

Related

Add an event handler to a my.settings value

I want to invoke a method every time a value from My.Settings is changed. Something like:
Private Sub myValue_Changed(sender As Object, e As EventArgs) Handles myValue.Changed
(...)
End Sub
I know that, if I wanted to do it with a variable, I have to make it a class and set the event on it. But I canĀ“t do it with the value from My.Settings.
Is there any way to do this?
As suggested in the comments on another answer, you can receive notification of a change in a setting via a Binding. Alternatively, you can do essentially what the Binding class does yourself, as there's not really all that much to it, e.g.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim settingsPropertyDescriptors = TypeDescriptor.GetProperties(My.Settings)
Dim setting1PropertyDescriptor = settingsPropertyDescriptors(NameOf(My.Settings.Setting1))
setting1PropertyDescriptor.AddValueChanged(My.Settings, AddressOf Settings_Setting1Changed)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Settings.Setting1 = "Hello World"
End Sub
Private Sub Settings_Setting1Changed(sender As Object, e As EventArgs)
Debug.WriteLine($"{NameOf(My.Settings.Setting1)} changed to ""{My.Settings.Setting1}""")
End Sub
This code adds a changed handler to the property via a PropertyDescriptor, just as the Binding class does.
In a word: no. My.Settings doesn't support this on it's own.
What you can do is make your own class that wraps My.Settings. As long as you use this new class, and never go to My.Settings directly any more, then you can put an event on that class which will do what you need.
However, even here, there's no way to enforce the use of the new class, and prevent direct access to My.Settings.
Are you looking for something like this? ApplicationSettingsBase.SettingChanging Event
Partial Friend NotInheritable Class MySettings
Inherits Configuration.ApplicationSettingsBase
Private Sub MySettings_SettingChanging(sender As Object, e As System.Configuration.SettingChangingEventArgs) Handles Me.SettingChanging
If e.SettingName.Equals(NameOf(My.Settings.Setting1)) Then
'Do Stuff
End If
End Sub
End Class

How to change properties of a button in visual basic

I am starting to work on my project and I've decided to use Visual Basic. I've used it in the past but I am quite new with Windows Forms. I want my code to change the background image of the button once I press the said button. However, pressing the button does nothing. Where have I gone wrong?
Public Class Form1
Private Sub TitleScreen_Click(sender As Object, e As EventArgs) Handles TitleScreen.Click
BackgroundImage = My.Resources.Player1CharacterInformationScreen
End Sub
End Class
Public Class Form1
Private Sub TitleScreen_Click(sender As Object, e As EventArgs) Handles TitleScreen.Click
TitleScreen.BackgroundImage = My.Resources.Player1CharacterInformationScreen
End Sub
End Class

Improve UI responsiveness on windows form application

I am currently working on a project and decided to create a user interface for it using visual studio with a windows forms application(Visual Basic).
The problem I'm facing is that the user interface doesn't respond as quickly and smoothly as I'd like it to.
Mainly, I am using pictures as buttons to make the user form look more modern.
However, when I hover my mouse over a "button" it takes a while until the "highlighted button" appears.
P1 is the picture of the "normal button" and P2 is the picture of the "highlighted button".
Here is the short code I have for now:
Public Class Main
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub PictureBox1_MouseHover(sender As Object, e As EventArgs) Handles P1.MouseHover
P1.Visible = False
P2.Visible = True
End Sub
Private Sub P2_MouseClick(sender As Object, e As MouseEventArgs) Handles P2.MouseClick
'Call cmdInit()
'Call cmdConnectRobot()
'Call cmdUnlock()
End Sub
Private Sub Main_MouseHover(sender As Object, e As EventArgs) Handles Me.MouseHover
If P2.Visible = True Then
P2.Visible = False
P1.Visible = True
End If
End Sub
Private Sub P4_Click(sender As Object, e As EventArgs) Handles P4.Click
End Sub
End Class
Another problem I'm facing is that when I call other subs, the user form becomes unresponsive while the sub is running.
I researched and found that I could implement multi threading or async tasks but I'm a bit lost and would be extremely grateful if someone could guide me or point me in the right direction.
Thanks in advance!!
In this case your UI is responsive, however the MouseHover event is only raised once the mouse cursor has hovered over the control for a certain amount of time (default is 400 ms), which is what is causing the delay.
What you are looking for is the MouseEnter event, which is raised as soon as the cursor enters ("touches") the control:
Private Sub P1_MouseEnter(sender As Object, e As EventArgs) Handles P1.MouseEnter
P1.Visible = False
P2.Visible = True
End Sub
You can then use that together with the MouseLeave event on the second picture box to switch back to the non-highlighted image:
Private Sub P2_MouseLeave(sender As Object, e As EventArgs) Handles P2.MouseLeave
P1.Visible = True
P2.Visible = False
End Sub
However switching picture boxes like this is not optimal. I recommend you to look into how you can use Application Resources, then modify your code to only switch the image that one picture box displays.
Here are the basic steps:
Right-click your project in the Solution Explorer and press Properties.
Select the Resources tab.
To add an image either:
a. Drag and drop the image onto the resource pane.
b. Click the arrow next to the Add Resource... button and press Add Existing File....
Now, in your code add this right below Public Class Form1:
Dim ButtonNormal As Image = My.Resources.<first image name>
Dim ButtonHighlighted As Image = My.Resources.<second image name>
Replace <first image name> and <second image name> with the names of your button images.
Now you only need one picture box for the button:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
P1.Image = ButtonNormal
End Sub
Private Sub P1_MouseEnter(sender As System.Object, e As System.EventArgs) Handles P1.MouseEnter
P1.Image = ButtonHighlighted
End Sub
Private Sub P1_MouseLeave(sender As System.Object, e As System.EventArgs) Handles P1.MouseLeave
P1.Image = ButtonNormal
End Sub
I'll start by saying i'm not a programmer by trade, and i'm sure someone will point out better ways of doing these things, but in regards to the threading question it's fairly simple to implement.
Imports System.Threading
Public Class Form1
Dim WorkerThread As New Thread(AddressOf DoWork)
'WorkerThread' can be any name you like, and 'DoWork' is the name of the sub you want to run in the new thread, and is launched by calling:
WorkerThread.start()
However there is a catch, the new thread is not able to interact directly with the GUI, so you cannot change textbox text etc... I find the easiest way to get changes made to the GUI is to drag a timer onto your form, and have the new thread change variables (pre-defined just below Public Class Form1), then use the Timer1 Tick event to monitor the variables and update the GUI if there are any changes.

VB.net Gecko WebBrowser DocumentCompleted not compatible?

I'm using GeckoBrowser, as I find it displays and loads pages faster than the native WebBrowser(IE). The only issue I'm having is when to tell the page has finished loading so I can then run more code.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
GeckoWebBrowser1.Navigate("http://www.google.com")
End Sub
Private Sub GeckoWebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles GeckoWebBrowser1.DocumentCompleted
Label1.Text = "YES"
End Sub
End Class
The error I get is "Method 'GeckoWebBrowser1_DocumentCompleted' cannot handle event 'DocumentCompleted' because they do not have a compatible signature.
I've tried changing 'WebBrowserDocumentEventArgs' to 'GeckoDocumentCompletedEventArgs' but that says 'Type - is not defined'.
Any suggestions would be greatly appreciated.
#jmcilhinney's solution worked, just used drop downs at the top.
All I really needed was to add Imports Gecko.Events at the top

Listening to another window's resize event

I try to listen to an another window's event. I always want to set the Window mode to full screen if someone try to change the window size.
After some research about this topic, I've found some information about Event hooks. Now I'm trying to get this to work, but there is no example for listening to window events.
Currently I try to use SetWinEventHook, but it seems like this is not working with window events.
Can someone give me a tip how to do that? If I find a solution, I will post the answer.
Thank you in advance!!!
Is this what you are after? You can get the resize event from the second form like this.
Public Class Form1
Dim WithEvents Form As Form2
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form = New Form2
form.Show()
End Sub
Private Sub Form_Resize(sender As Object, e As EventArgs) Handles Form.Resize
Dim size As Size = CType(sender, Form2).Size
Console.WriteLine("Window Resize: " + size.ToString)
End Sub
End Class