Question picBox_Click and strict on

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
i have dynamically created a picturebox and its click event

VB.NET:
Dim pic As New PictureBox
AddHandler pic.Click, AddressOf pic_Click
Private Sub pic_Click(sender As Object, e As EventArgs)


End Sub


and it works fine, but i also want to sense which mouse button was clicked, so i changed it to

VB.NET:
AddHandler pic.Click, AddressOf pic_Click
Private Sub pic_Click(sender As Object, e As System.Windows.Forms.MouseEventArgs)


End Sub

but because i have Strict On, i get a narrowing in implicit type conversions error on declaring the handler. How do i fix that?
 
Zexor said:
Why have a separate click and mouse click event when they do the same thing?
Note that they could have removed the Click event when they added the MouseClick event because MouseClick is like a superset of Click. That would have broken all the existing code that used Click though.
Click event is also raised when control is 'clicked' by keyboard input (enter/space) when it has focus. MouseClick does not have this functionality.
 
Click event is also raised when control is 'clicked' by keyboard input (enter/space) when it has focus. MouseClick does not have this functionality.

Hadn't thought of that but obviously a very important difference.
 
Is there a mouse scroll event?

Perhaps it's time for you to read some documentation for yourself. Microsoft didn't spend hundreds and possibly thousands of man hours creating the MSDN Library for nothing.
 
does it only trigger if there is a scrollbar? i cant seems to trigger it. Am trying to use the mouse wheel to resize a picturebox.
 
This is from the documentation for the Control.MouseWheel event:
Occurs when the mouse wheel moves while the control has focus.
Does your PictureBox have focus while you're scrolling the wheel? Given that PictureBoxes can't receive focus, I'd say not.

Is there any particular reason that you were unable to read that for yourself? I'm keen to help people get better but if you're just not prepared to read anything then I'd like to know now.
 
well, the thing is, i dont know a picturebox cant receive focus since u can do picturebox1.focus(). And picturebox also has mousewheel event. And you didnt know how to focus a picture box 4 years ago, and am hoping you know how to do it now.
 
Last edited:
Zexor said:
i dont know a picturebox cant receive focus since u can do picturebox1.focus()
PictureBox Class (System.Windows.Forms)
The PictureBox is not a selectable control, which means that it cannot receive input focus.
You can still select it programmatically.
Zexor said:
pictureBox1.focus() does focus the picture box and trigger the mousewheel event...
Control.Focus Method (System.Windows.Forms)
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
 
Back
Top