Cor,
I agree if you want a button then start with a button. On the same token if
you want a picture box start with a picture box. If you want something that
resemples both, pick the one that is closer to what you really need, then
add the code to get the features you need. Of course starting with Control,
UserControl, ContainerControl, ScrollableControl, or another control instead
might be better still...
Remember you can use Control.SetStyle(ControlStyles.Selectable, True)
followed by Control.UpdateStyles will enable PictureBoxEx to get the
keyboard focus, you can then use the normal & advanced keyboard* overrides &
events to handle the keyboard while the PictureBox has the focus...
Something like:
Imports System.ComponentModel
Public Class PictureBoxEx
Inherits PictureBox
Implements IButtonControl
Private m_dialogResult As DialogResult
Public Sub New()
SetStyle(ControlStyles.Selectable, True)
UpdateStyles()
TabStop = True
End Sub
Public Property DialogResult() As DialogResult Implements
IButtonControl.DialogResult
Get
Return m_dialogResult
End Get
Set(ByVal value As DialogResult)
m_dialogResult = value
End Set
End Property
Public Sub NotifyDefault(ByVal value As Boolean) Implements
IButtonControl.NotifyDefault
' Notifies a control that it is the default button
' so that its appearance and behavior is adjusted accordingly.
End Sub
Public Sub PerformClick() Implements IButtonControl.PerformClick
MyBase.OnClick(EventArgs.Empty)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
ControlPaint.DrawBorder3D(e.Graphics, Me.ClientRectangle)
End Sub
Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
MyBase.OnGotFocus(e)
Me.BackColor = SystemColors.Info
End Sub
Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
MyBase.OnLostFocus(e)
Me.BackColor = SystemColors.Control
End Sub
<Browsable(True), DefaultValue(True)> _
Public Shadows Property TabStop() As Boolean
Get
Return MyBase.TabStop
End Get
Set(ByVal value As Boolean)
MyBase.TabStop = value
End Set
End Property
<Browsable(True), DefaultValue(0)> _
Public Shadows Property TabIndex() As Integer
Get
Return MyBase.TabIndex
End Get
Set(ByVal value As Integer)
MyBase.TabIndex = value
End Set
End Property
End Class
Again put the PictureBoxEx on your form, with a Click event handler, tab to
it, press Enter, what happens? Note PictureBoxEx does not understand the
Space bar, which is normally the same as Enter on a button!
*advanced keyboard overrides include: IsInputChar, IsInputKey,
PreProcessMessage, ProcessCmdKey, ProcessDialogChar, ProcessDialogKey,
ProcesKeyEventArgs, ProcessKeyMessage, ProcessKeyPreview, and
ProcessMnemonic. Unfortunately I don't have any real good examples of using
these, other then they allow you to intercept the key significantly earlier
then the OnKey* methods...
Hope this helps
Jay
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eY**************@TK2MSFTNGP11.phx.gbl...
Jay,
You are right it has a click event, in my thought that was the reason that
the button was better to use than the picturebox for this kind of
solutions.
However it has to do with the click event. The picturebox cannot get focus
(in a simple way) and therefore it is in my opinion a little bit less
usable than a picturebox when you are using it for things as games (you
cannot use the enter key).
While when you use a button for that, it is easy to use.
That you inherit from control does not say everything, you can shadow
methods/properties and with that even when it is inherited is it possible
that a method/property is not functioning. In my opinion is that by
instance the text property from a picturebox.
I hope this helps,
Cor