dHeather
Active member
- Joined
- Jun 18, 2012
- Messages
- 27
- Programming Experience
- Beginner
Hello,
Can somebody tell me where I'm going wrong please?
I have a routine (below) that when a user hovers over a button a thumb is created in a picture box of the target file. The problem I have is that a lot of the target files are large and creating the thumb can take a while (up to a second). What I am trying to do is to add threading so I can interupt the MouseEnter event if the use clicks. I can't get it working though. Can anyone tell me where I'm going wrong please?
Thank you very much
My code is Below:
[XCODE]
Imports System.IO
Imports System.Drawing
Imports System.Threading '<----------
PublicClass Form1
Dim FileString, FolderString AsString
Dim myFiles AsNew List(Of IO.FileInfo)
Dim myButtons AsNew List(Of Button)
Dim t AsNew Thread(AddressOf Image_Buttons_MouseEnter) '<----------
PrivateSub Image_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click, Button17.Click, Button18.Click, Button19.Click, Button20.Click, Button21.Click, Button22.Click, Button23.Click, Button24.Click, Button25.Click, Button26.Click, Button27.Click, Button28.Click, Button29.Click, Button30.Click, Button31.Click
t.Abort() '<---------
Dim CurrentBtn As Button = sender
Dim FileName AsString = myFiles(CurrentBtn.Text - 1).ToString
Try
Process.Start("D:\" & FolderString & myFiles(CurrentBtn.Text - 1).ToString)
Catch ex As Exception
EndTry
EndSub
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
For i AsInteger = 6 To 31
myButtons.Add(Me.Controls("Button" & i))
Next i
Me.Label23.Parent = Me.Label22
Me.Label23.BackColor = Color.Transparent
Me.PictureBox1.Visible = True
Me.PictureBox1.Image = My.Resources.New_logo_4__small_
FolderString = "acouStac Info\acouStac Photos\"
EndSub
PrivateSub Image_Buttons_MouseEnter(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button6.MouseEnter, Button7.MouseEnter, Button8.MouseEnter, Button9.MouseEnter, Button10.MouseEnter, Button11.MouseEnter, Button12.MouseEnter, Button13.MouseEnter, Button14.MouseEnter, Button15.MouseEnter, Button16.MouseEnter, Button17.MouseEnter, Button18.MouseEnter, Button19.MouseEnter, Button20.MouseEnter, Button21.MouseEnter, Button22.MouseEnter, Button23.MouseEnter, Button24.MouseEnter, Button25.MouseEnter, Button26.MouseEnter, Button27.MouseEnter, Button28.MouseEnter, Button29.MouseEnter, Button30.MouseEnter, Button31.MouseEnter
t.Start() '<----------
Dim CurrentBtn As Button = sender
Dim FileName AsString = myFiles(CurrentBtn.Text - 1).ToString
Dim TempImg As Bitmap = System.Drawing.Image.FromFile("D:\" & FolderString & FileName)
Dim ImgWidth AsSingle = TempImg.Width
Dim ImgHeight AsSingle = TempImg.Height
Dim newWidth AsInteger
Dim newHeight AsInteger
If TempImg.Width > TempImg.Height Then
newWidth = 300
newHeight = (newWidth / TempImg.Width) * TempImg.Height
Else
newHeight = 300
newWidth = (newHeight / TempImg.Height) * TempImg.Width
EndIf
Dim resized As Bitmap = New Bitmap(newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(resized)
g.DrawImage(TempImg, New Rectangle(0, 0, resized.Width, resized.Height), 0, 0, TempImg.Width, TempImg.Height, GraphicsUnit.Pixel)
Me.PictureBox1.Image = resized
g.Dispose()
EndSub
PrivateSub Image_Buttons_MouseLeave(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button6.MouseLeave, Button7.MouseLeave, Button8.MouseLeave, Button9.MouseLeave, Button10.MouseLeave, Button11.MouseLeave, Button12.MouseLeave, Button13.MouseLeave, Button14.MouseLeave, Button15.MouseLeave, Button16.MouseLeave, Button17.MouseLeave, Button18.MouseLeave, Button19.MouseLeave, Button20.MouseLeave, Button21.MouseLeave, Button22.MouseLeave, Button23.MouseLeave, Button24.MouseLeave, Button25.MouseLeave, Button26.MouseLeave, Button27.MouseLeave, Button28.MouseLeave, Button29.MouseLeave, Button30.MouseLeave, Button31.MouseLeave
t.Abort() '<---------
Me.PictureBox1.Image = My.Resources.New_logo_4__small_
EndSub
PrivateSub ListView1_MouseDoubleClick(ByVal sender AsObject, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick
Try
Process.Start("D:\" & FolderString & Me.ListView1.SelectedItems(0).Text)
Me.Button5.Focus()
Catch ex As Exception
EndTry
EndSub
EndClass
[/XCODE]
Can somebody tell me where I'm going wrong please?
I have a routine (below) that when a user hovers over a button a thumb is created in a picture box of the target file. The problem I have is that a lot of the target files are large and creating the thumb can take a while (up to a second). What I am trying to do is to add threading so I can interupt the MouseEnter event if the use clicks. I can't get it working though. Can anyone tell me where I'm going wrong please?
Thank you very much
My code is Below:
[XCODE]
Imports System.IO
Imports System.Drawing
Imports System.Threading '<----------
PublicClass Form1
Dim FileString, FolderString AsString
Dim myFiles AsNew List(Of IO.FileInfo)
Dim myButtons AsNew List(Of Button)
Dim t AsNew Thread(AddressOf Image_Buttons_MouseEnter) '<----------
PrivateSub Image_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click, Button17.Click, Button18.Click, Button19.Click, Button20.Click, Button21.Click, Button22.Click, Button23.Click, Button24.Click, Button25.Click, Button26.Click, Button27.Click, Button28.Click, Button29.Click, Button30.Click, Button31.Click
t.Abort() '<---------
Dim CurrentBtn As Button = sender
Dim FileName AsString = myFiles(CurrentBtn.Text - 1).ToString
Try
Process.Start("D:\" & FolderString & myFiles(CurrentBtn.Text - 1).ToString)
Catch ex As Exception
EndTry
EndSub
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
For i AsInteger = 6 To 31
myButtons.Add(Me.Controls("Button" & i))
Next i
Me.Label23.Parent = Me.Label22
Me.Label23.BackColor = Color.Transparent
Me.PictureBox1.Visible = True
Me.PictureBox1.Image = My.Resources.New_logo_4__small_
FolderString = "acouStac Info\acouStac Photos\"
EndSub
PrivateSub Image_Buttons_MouseEnter(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button6.MouseEnter, Button7.MouseEnter, Button8.MouseEnter, Button9.MouseEnter, Button10.MouseEnter, Button11.MouseEnter, Button12.MouseEnter, Button13.MouseEnter, Button14.MouseEnter, Button15.MouseEnter, Button16.MouseEnter, Button17.MouseEnter, Button18.MouseEnter, Button19.MouseEnter, Button20.MouseEnter, Button21.MouseEnter, Button22.MouseEnter, Button23.MouseEnter, Button24.MouseEnter, Button25.MouseEnter, Button26.MouseEnter, Button27.MouseEnter, Button28.MouseEnter, Button29.MouseEnter, Button30.MouseEnter, Button31.MouseEnter
t.Start() '<----------
Dim CurrentBtn As Button = sender
Dim FileName AsString = myFiles(CurrentBtn.Text - 1).ToString
Dim TempImg As Bitmap = System.Drawing.Image.FromFile("D:\" & FolderString & FileName)
Dim ImgWidth AsSingle = TempImg.Width
Dim ImgHeight AsSingle = TempImg.Height
Dim newWidth AsInteger
Dim newHeight AsInteger
If TempImg.Width > TempImg.Height Then
newWidth = 300
newHeight = (newWidth / TempImg.Width) * TempImg.Height
Else
newHeight = 300
newWidth = (newHeight / TempImg.Height) * TempImg.Width
EndIf
Dim resized As Bitmap = New Bitmap(newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(resized)
g.DrawImage(TempImg, New Rectangle(0, 0, resized.Width, resized.Height), 0, 0, TempImg.Width, TempImg.Height, GraphicsUnit.Pixel)
Me.PictureBox1.Image = resized
g.Dispose()
EndSub
PrivateSub Image_Buttons_MouseLeave(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button6.MouseLeave, Button7.MouseLeave, Button8.MouseLeave, Button9.MouseLeave, Button10.MouseLeave, Button11.MouseLeave, Button12.MouseLeave, Button13.MouseLeave, Button14.MouseLeave, Button15.MouseLeave, Button16.MouseLeave, Button17.MouseLeave, Button18.MouseLeave, Button19.MouseLeave, Button20.MouseLeave, Button21.MouseLeave, Button22.MouseLeave, Button23.MouseLeave, Button24.MouseLeave, Button25.MouseLeave, Button26.MouseLeave, Button27.MouseLeave, Button28.MouseLeave, Button29.MouseLeave, Button30.MouseLeave, Button31.MouseLeave
t.Abort() '<---------
Me.PictureBox1.Image = My.Resources.New_logo_4__small_
EndSub
PrivateSub ListView1_MouseDoubleClick(ByVal sender AsObject, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick
Try
Process.Start("D:\" & FolderString & Me.ListView1.SelectedItems(0).Text)
Me.Button5.Focus()
Catch ex As Exception
EndTry
EndSub
EndClass
[/XCODE]
Last edited: