Did a User Control with a little properties, achor of buttons and so on,
that worked nice.
Set ContextMenu & ButtonText as properties, subscribe on CommandButtonCl ick
event to get the button click event.
Thanks Jay for ideas.
Code below for others to use if anyone need it.
Regards
Fredrik Melin
'-------------------------------------------------------------------
Public Class ucDropDownButto n
Inherits System.Windows. Forms.UserContr ol
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents cmdCommand As System.Windows. Forms.Button
Friend WithEvents cmdDropDown As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.cmdCommand = New System.Windows. Forms.Button
Me.cmdDropDown = New System.Windows. Forms.Button
Me.SuspendLayou t()
'
'cmdCommand
'
Me.cmdCommand.A nchor =
CType((((System .Windows.Forms. AnchorStyles.To p Or
System.Windows. Forms.AnchorSty les.Bottom) _
Or System.Windows. Forms.AnchorSty les.Left) _
Or System.Windows. Forms.AnchorSty les.Right),
System.Windows. Forms.AnchorSty les)
Me.cmdCommand.L ocation = New System.Drawing. Point(5, 4)
Me.cmdCommand.N ame = "cmdCommand "
Me.cmdCommand.S ize = New System.Drawing. Size(97, 24)
Me.cmdCommand.T abIndex = 0
Me.cmdCommand.T ext = "Create"
'
'cmdDropDown
'
Me.cmdDropDown. Anchor =
CType(((System. Windows.Forms.A nchorStyles.Top Or
System.Windows. Forms.AnchorSty les.Bottom) _
Or System.Windows. Forms.AnchorSty les.Right),
System.Windows. Forms.AnchorSty les)
Me.cmdDropDown. Location = New System.Drawing. Point(101, 4)
Me.cmdDropDown. Name = "cmdDropDow n"
Me.cmdDropDown. Size = New System.Drawing. Size(18, 24)
Me.cmdDropDown. TabIndex = 1
Me.cmdDropDown. Text = "V"
'
'ucDropDownButt on
'
Me.Controls.Add (Me.cmdDropDown )
Me.Controls.Add (Me.cmdCommand)
Me.Name = "ucDropDownButt on"
Me.Size = New System.Drawing. Size(122, 31)
Me.ResumeLayout (False)
End Sub
#End Region
Public Event CommandButtonCl icked(ByVal sender As Object, ByVal e As
EventArgs)
Private m_cMenu As ContextMenu
Public Property ButtonText() As String
Get
Return cmdCommand.Text
End Get
Set(ByVal Value As String)
cmdCommand.Text = Value
End Set
End Property
Public Property cMenu() As ContextMenu
Set(ByVal Value As ContextMenu)
m_cMenu = Value
End Set
Get
Return m_cMenu
End Get
End Property
Private Sub cmdDropDown_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdDropDown.Cli ck
Dim pos As Point = cmdDropDown.Loc ation
pos.Y += cmdDropDown.Hei ght
Me.m_cMenu.Show (Me, pos)
End Sub
Private Sub ucDropDownButto n_Click(ByVal sender As Object, ByVal e As
System.EventArg s) Handles cmdCommand.Clic k
RaiseEvent CommandButtonCl icked(sender, e)
End Sub
End Class
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:ed******** ******@TK2MSFTN GP11.phx.gbl...
Fredrik,
I would use either two buttons...
Or I would create a custom control (possibly deriving from Button) &
handle painting & mouse clicks (possibly overriding Control.OnClick )
myself to decide if the "default" click event should be handled or the
ContextMenu should be displayed...
Post if you want a sample, I can see if I can come up with one later, no
promises...
Hope this helps
Jay
"Fredrik Melin" <me*@n.o.spam.d acsa.net.remove .as.needed> wrote in message
news:Os******** ******@TK2MSFTN GP12.phx.gbl... Yes, but I wanted the nice feature with a arrow down for options and to
have a "default" click event, if no menu was selected.
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. . Fredrik,
Not sure of a pre-built control, however I've used the Click event of a
normal Button to call ContextMenu.Sho w method.
Something like:
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim pos As Point = Button1.Locatio n
pos.Y += Button1.Height
Me.ContextMenu1 .Show(Me, pos)
End Sub
Hope this helps
Jay
"Fredrik Melin" <me*@no-spam.dacsa-remove-this.net> wrote in message
news:OF******** ******@TK2MSFTN GP09.phx.gbl...
Have anyone seen a component or know how to create a button like
toolbar dropdown button without the toolbar (to be used like a normal
button)
Regards
Fredrik Melin