I have the vlc AxVLCPlugin21 control inside of a visual basic 2010 form and I have set it with the
ability to recognize to pause the video or music whenever I tap the space key.
The code below works and pauses the media when the windows form is showing and the vlc control is
not full screen. However when I make the vlc full screen and tap the space bar the media no longer
pauses. I think the full screen mode causes the windows form keydown event to be blocked.
I am not sure what I could try to fix this. I know the windows form has a previevkeydown event listed below
and the vlc control itself has its own previewkeydown event. But not sure what I might try to get the pause
to work when the space bar is pressed while in full screen mode. Any ideas appreciated. I have often had
problems getting keypresses to work with programs in VB. Is it because different controls seize control depending
on various settings?
I also use a Me.KeyPreview = True in the form load which supposedly forces the windows form to take precedence over taking keystrokes.
One other idea I tried but did not work was using e.Handled = True in the
keydown event which supposedly makes the form take all keyboard events and
will not allow other controls to receive them. Did not work in full screen.
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyValue = Keys.Space Then
AxVLCPlugin21.playlist.togglePause()
End If
End Sub
Private Sub Form1_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles MyBase.PreviewKeyDown
End Sub
Private Sub AxVLCPlugin21_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles AxVLCPlugin21.PreviewKeyDown
End Sub
Related
I was working on a project and for no reason all Handles disappeared from the form
For example:
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
has become
Private Sub Button17_Click(sender As Object, e As EventArgs)
I have a lot of tools in the form
Is there a shortcut to retrieve Handles?
This happens if a control is being cut and pasted back on the form or if it's deleted and recreated with the same name.
To recreate the Handles you can click behind the closing bracket and press SPACE - TAB - SPACE and fill the rest up with the help of IntelliSense.
There's nothing to retrieve. They are just regular methods now. You need to attach them to the appropriate events like you would any other method you wrote yourself. Open the Properties window in the designer and click the Events button. Select a control on the form, click the drop-down for the event of interest and select the correct method.
I've come across a peculiar focusing issue. I have created the following "search" program:
It runs in the background.
When you double-tap the Ctrl key it becomes visible.
You can type in the textbox because the form has focus.
If the form loses focus (I click on my desktop, for example), it disappears after 3 seconds.
I double-tap the Ctrl key again, and again it becomes visible.
But this time, no matter what I try, the form is not focused and I cannot type in the textbox without first manually clicking on the form.
What's particularly interesting is that when I run this program in debug mode from Visual Studios, the program regains focus upon double-tapping Ctrl key and becoming visible, and I can immediately start typing in the text box. However, when I build this program and run it alone, the program appears but does not regain focus upon double-tapping Ctrl key, and therefore I cannot type in the text box until I manually click the form.
After Me.Show() I have tried:
Me.Focus()
Me.Validate()
Me.Select()
Textbox1.Select()
Textbox1.Focus()
The form is topmost and normally running in administrator, but the same problem arises regardless.
The issue can be recreated in a more simple manner. Create a form with
Button ("Button1")
TextBox
Two timers ("hideForm", "showForm") both with intervals of 1000
Code:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
hideForm.Start()
sender.Enabled = False
End Sub
Private Sub hideForm_Tick(sender As Object, e As EventArgs) Handles hideForm.Tick
Me.Hide()
hideForm.Stop()
showForm.Start()
End Sub
Private Sub showForm_Tick(sender As Object, e As EventArgs) Handles showForm.Tick
showForm.Stop()
Me.Show()
Me.Activate()
End Sub
End Class
Click the button, and immediately click on a different window (so the form loses focus). Wait until the form is hidden and shown again. The textbox should have focus. Try typing.
If the program is run in debugging mode in Visual Studios, it works as expected. If you build the program and run it outside of VS, the form will reappear without focus, and you cannot type in the textbox without manually selecting the form.
Sorry for the long-winded explanation. It's a difficult issue to properly describe.
Try the form event handler Activate. Inside that method, you can use setFocus to gain focus for that particular Text Box. I know this answer is too late. But hope this helps someone.
Private Sub Form_Activate()
TextBox1.SetFocus
End Sub
Try an event handler for Form_Activate, and within that handler pass the focus to your textbox.
Instead of Focus, you can also try TextBox1.Select. This SO link provides some additional information and something about the difference between Focus and Select.
Select the Textbox you want to assign a focus to in the Design View Window.
Under the Properties window, set the TabIndex to 0 (zero).
I didn't even have to use the TextBox1.Focus() command. It still bothers me that the TabIndex overrides the Focus command.
What I tried (and worked for me), was to set the Focus() of the Textbox in the event handler Shown() [VB]:
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
Me.Textbox1.Focus()
End Sub
Note: the Select() method just didn't do the job. I hope this helps anyone else that comes with this same issue.
I wrote a program to controle the audio volume by a remote control.
It needs to keep focused, otherwise it does not receive its commands anymore.
In order to get the focus back a used a timer, checking every second if the form still has the focus.
Here is the code:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Not Me.Focused Then
Me.Activate()
End If
End Sub
As long as I run it from within Visual Studio this works perfect.
When I close Visual Studio it does not take the focus back anymore.
I ran the program on another computer on which was no Visual Studio installed and it works!
What could be the problem?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
MsgBox("test")
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
BackgroundWorker1.RunWorkerAsync()
End Sub
Once I click the Button1 ,Messagebox appears.When click okay with "Return" (enter) key it appears again and again...But when I click Return key permanently,almost 5 seconds later programs gives me the run time error.
Error is not English in my computer and I translated it.It is nearly mean "BackgroundWorker is busy,can't do two procces in the same time..."
I know that error.It is because of trying to run BackgroundWorker while it is running.In the code it just start with RunWorkerCompleted event.So it can't start again if "Work is not Completed".Who runs the BackgroundWorker ?
You need to read this post first, it talks about the dangers of re-entrancy and how dialogs (like MsgBox) solve the problem.
Which is what it is not doing in your program. A dialog can only be modal against other windows that are created on the same thread. That worker thread doesn't have any. So there is nothing that stops your Enter key press from also being seen by the control that has the focus. Button1. Note how you can simply use the mouse to select your main window and click the button. Kaboom.
That doesn't go wrong often enough as-is, you can help by leaning on the Enter key so it starts repeating. It will usually be detected by the message box window. But not always, there's a split second between DoWork ending and it starting back up. Just enough to give the UI thread a chance to see the keystroke. Now that Enter keypress operates Button1 and it starts the BGW back up again. So does the RunWorkerCompleted event handler, it cannot be started twice. Kaboom.
That's not the only problem with that dialog, you haven't discovered the other failure mode yet. A dialog needs an owner window, one that it can be displayed on top of. That message box does have one, it has to fallback to the desktop window. Now it is crapshoot which window is going to be in front. Could be the dialog, could be your main window. With the message box underneath your main window. The user cannot see it, has no idea that there is one. No taskbar button either.
Long story short: this cannot work. Only display UI on the UI thread. Only use a worker thread to do non-UI related work.
The combination of Shift+Ctrl+Plus Sign rotates my PDF in a web browser control. However, I have to click the "Rotate" button 2 times before the document rotates. Why?
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Me.WebBrowser1.Focus()
SendKeys.Send("+(^{+})")
End Sub
SendKeys is an unreliable method for this. I recommend Input Simulator you can even send multiple keys at once.