MouseHover event runs a milliseconds slower in VB.net - vb.net

I've noticed something when I use Mousehover event, that it is slower in some milliseconds.
I mean that when I point my cursor on it, it is few milliseconds slower. please help me How to fix this
Here's my code:
Public Class Form1
Private Sub Button1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseHover
Button1.ForeColor = Color.White
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Button1.ForeColor = Color.Black
End Sub
End Class
Please help me.

use MouseMove event instead of MouseHover, that will do it for you. It gives you an immediate response.
Code:
Private Sub Button1_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseMove
Button1.ForeColor = Color.White
End Sub
Best wishes!
-BHARATHI Tutorials

Related

Show Form2 7seconds delayed after Form1 close

I have two forms in my application, form2 is shown on clicking a button in the form1. but i need a delay of 7 seconds between form1's close and form2's show for that i wrote the following code:
Public Class Form1
Dim i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
i = 0
Me.Close()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
i += 1
If i = 7 Then
Form1.Show()
End If
End Sub
End Class
But it does not give me the result. form2 not shown at all. what was the mistake i had made in the code? can anyone help me?
Thanks in advance.
When there's no active form left in a Windows Forms application, the application will quit. Therefore, you might want to hide the main form instead of closing it:
Me.Hide()
i think no need of unnecessary declaration for time delay because you can simply set it on your timer control itself
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 7000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Form2.Show()
Me.Close()
End Sub
End Class
or
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 7000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Close()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Form2.Show()
End Sub

Changing the background color for Form2

i have two RadioButtons one for Light Blue and the other for Ghost White and a button to show the next Form (Form2)
i want to be able to check on a Radio Button and the backcolor of form2 changes to the checked Radio Button
this is what i have on my coding so far
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
SecondForm.Show()
End Sub
Private Sub rbLightBlue_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbLightBlue.CheckedChanged
If rbLightBlue.Checked Then
SecondForm.BackColor = (Color.LightBlue)
End If
End Sub
Private Sub rbGhostWhite_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbGhostWhite.CheckedChanged
If rbGhostWhite.Checked Then
SecondForm.BackColor = (Color.GhostWhite)
End If
End Sub
The problem am having is making the background color change on Form2.
Any answer for this question will be very helpful.
I am not sure what you are doing, it probably has to do with how you are creating your SecondForm, this code does work, see if it helps you narrow it down.
Public Class Form1
Dim SecondForm As Form2 = New Form2
Private Sub rbLightBlue_CheckedChanged(sender As Object, e As EventArgs) Handles rbLightBlue.CheckedChanged
If DirectCast(sender, RadioButton).Checked Then
SecondForm.BackColor = Color.LightBlue
End If
End Sub
Private Sub rbGhostWhite_CheckedChanged(sender As Object, e As EventArgs) Handles rbGhostWhite.CheckedChanged
If DirectCast(sender, RadioButton).Checked Then
SecondForm.BackColor = Color.GhostWhite
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SecondForm.Show()
End Sub
End Class

Get Own control values in visual basic 10

I'm looking for a way to get the data of control (in this case a Trackbar) inside the trackbar itself.
I got this:
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Label1.Text = TrackBar1.Value
End Sub
But I want to replace that "trackBar1." with something like
Label1.Text = THIS_CONTROL.Value
Is this possible in Vb10 ?
Thanks
Use the sender argument:
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Dim THIS_CONTROL As TrackBar = DirectCast(sender, TrackBar)
Label1.Text = THIS_CONTROL.Value
End Sub

Refresh or Redraw picturebox in VB.net

I'm trying to view youtube captcha in my vb application but I don't know how to refresh/redraw the picture box. The youtube captcha is in http://www.youtube.com/cimg and the captcha is changing everytime I refresh the page. How can I do that using button or timer in vb.net to change the captcha. Here is the code I used to load the captcha to picturebox.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
captchaBox.ImageLocation = "http://www.youtube.com/cimg"
End Sub
i try to use captchaBox.Refresh() but it's not working. I hope someone can help me. thx
Refresh just redraws the control, it doesn't retrieve the image again. You need to reset the ImageLocation property for it to work. For example with a timer:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
captchaBox.ImageLocation = "http://www.youtube.com/cimg"
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
captchaBox.ImageLocation = "http://www.youtube.com/cimg"
End Sub
Try this:
Private Sub Form1_Load() Handles MyBase.Load
Timer1.Start()
PictureBox1.ImageLocation = "http://www.youtube.com/cimg"
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PictureBox1.Image = Nothing
PictureBox1.ImageLocation = "http://www.youtube.com/cimg"
End Sub

Disposing background worker does not work

I have a background worker that calls a form, holding a gif animation. The purpose is to display the animation while process is underway but it should close when the process is done. But it does not close even after completion of the process. Please help.
Thanks
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
frmAnimation.ShowDialog()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BackgroundWorker1.RunWorkerAsync()
Dim sqldatasourceenumerator1 As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
datatable1 = sqldatasourceenumerator1.GetDataSources()
DataGridView1.DataSource = datatable1
'I have tried CancelAsync, but did not work
BackgroundWorker1.CancelAsync()
frmAnimation.Dispose()
End Sub
BackgroundWorkers are intended to actually do the "work" of the background operation, so the main UI thread can continue rendering things onto the screen. I suspect you want the GetDataSources() function call to be done within the BackgroundWorker thread.
Try switching what's in your button click function and what's in the DoWork function of your BackgroundWorker. Specifically, I mean something like this:
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim sqldatasourceenumerator1 As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
datatable1 = sqldatasourceenumerator1.GetDataSources()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BackgroundWorker1.RunWorkerAsync()
frmAnimation.ShowDialog()
End Sub
And in addition, add some code to the RunWorkerCompleted event to handle what should be done upon completion of your background operation.
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
DataGridView1.DataSource = datatable1
frmAnimation.Close()
End Sub
You may also want to consider using frmAnimation.Show() instead of frmAnimation.ShowDialog() depending on if you want the procedure to be modal or modeless. You can read more about that here.