By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

Emulate Picture Box double click

P: n/a
I have the following code

Private Sub PictureBox_DoubleClick(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Try
Dim p As PictureBox = CType(sender, PictureBox)
Dim filetemp As String
filetemp = Replace(p.Tag, "Thumb", "jpg")
If Me.UseEditor = True Then
System.Diagnostics.Process.Start(filetemp)
Else

End If

_Image = Image.FromFile(filetemp)

Catch ex As Exception
Throw New Exception("PictureBox_DoubleClick", ex)
End Try

End Sub

Is there a way to emulate this functionality by single clicking the
image to select and and then click a button on the form to perform the
same action as the above code? If so, please could you provide sample
code.

Thanks.
Oct 7 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
wkaibigan wrote:
Private Sub PictureBox_DoubleClick(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Try
Dim p As PictureBox = CType(sender, PictureBox)
Dim filetemp As String
filetemp = Replace(p.Tag, "Thumb", "jpg")
If Me.UseEditor = True Then
System.Diagnostics.Process.Start(filetemp)
Else

End If

_Image = Image.FromFile(filetemp)

Catch ex As Exception
Throw New Exception("PictureBox_DoubleClick", ex)
End Try

End Sub

Is there a way to emulate this functionality by single clicking the
image to select and and then click a button on the form to perform the
same action as the above code? If so, please could you provide sample
code.
Extract the code into a separate routine and call it wherever you want
to call it from.

Private Sub EditPicture( ByVal sender as PictureBox )
'Try
Dim p As PictureBox = CType(sender, PictureBox)
Dim filetemp As String _
= Replace(p.Tag, "Thumb", "jpg")
If Me.UseEditor = True Then
System.Diagnostics.Process.Start(filetemp)
Else
???
End If

_Image = Image.FromFile(filetemp)

'Catch ex As Exception
' Throw New Exception("PictureBox_DoubleClick", ex)
'End Try
End Sub

.... then ...

Private m_CurrentPicture as PictureBox = Nothing

Private Sub PictureBox_Click(ByVal sender As System.Object _
, ByVal e As System.EventArgs)

m_CurrentPictureBox = DirectCast( sender, PictureBox )

End Sub

Private Sub Button7_Click(ByVal sender As System.Object _
, ByVal e As System.EventArgs)

EditPicture( m_CurrentPictureBox )

End Sub

You'll note I've commented out your Exception Handling in EditPicture -
there's no point catching an Exception unless you're going to do
something /useful/ with it (and, IMHO, wrapping a nice, specific
Exception in a System.Exception isn't).

HTH,
Phill W.
Oct 7 '08 #2

P: n/a
On Oct 7, 2:23*pm, wkaibigan <wkaibi...@gmail.comwrote:
I have the following code

Private Sub PictureBox_DoubleClick(ByVal sender As System.Object,
ByVal e As System.EventArgs)
* * * * Try
* * * * * * Dim p As PictureBox = CType(sender, PictureBox)
* * * * * * Dim filetemp As String
* * * * * * filetemp = Replace(p.Tag, "Thumb", "jpg")
* * * * * * If Me.UseEditor = True Then
* * * * * * * * System.Diagnostics.Process.Start(filetemp)
* * * * * * Else

* * * * * * End If

* * * * * * _Image = Image.FromFile(filetemp)

* * * * Catch ex As Exception
* * * * * * Throw New Exception("PictureBox_DoubleClick", ex)
* * * * End Try

* * End Sub

Is there a way to emulate this functionality by single clicking the
image to select and and then click a button on the form to perform the
same action as the above code? If so, please could you provide sample
code.

Thanks.
Hi,
As Picturebox is a control, and control class has OnDoubleClick method
to raise DoubleClick event. So you can directly call it from anywhere
and you'd better look at that method:
http://msdn.microsoft.com/en-us/libr...ubleclick.aspx

Hope this helps,

Onur Güzel
Oct 7 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.