Click here to Skip to main content
15,914,447 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Convert from decimal to hexidecimal? Pin
Adam Wike1-May-10 13:32
Adam Wike1-May-10 13:32 
QuestionDynamically adding tool strip buttons [modified] Pin
MacRaider430-Apr-10 2:54
MacRaider430-Apr-10 2:54 
AnswerRe: Dynamically adding tool strip buttons Pin
Simon_Whale30-Apr-10 3:17
Simon_Whale30-Apr-10 3:17 
GeneralRe: Dynamically adding tool strip buttons Pin
MacRaider430-Apr-10 3:39
MacRaider430-Apr-10 3:39 
GeneralRe: Dynamically adding tool strip buttons Pin
MacRaider430-Apr-10 3:49
MacRaider430-Apr-10 3:49 
AnswerRe: Dynamically adding tool strip buttons Pin
Wayne Gaylard30-Apr-10 3:56
professionalWayne Gaylard30-Apr-10 3:56 
GeneralRe: Dynamically adding tool strip buttons Pin
MacRaider430-Apr-10 6:44
MacRaider430-Apr-10 6:44 
GeneralRe: Dynamically adding tool strip buttons Pin
Wayne Gaylard30-Apr-10 15:11
professionalWayne Gaylard30-Apr-10 15:11 
Hi Try this

VB.NET
Module ToolStripBase

    Public Enum ButtonFunction

        Something1
        Something2

    End Enum

    Public Function CreateButton(ByVal ButtonImage As Image, ByVal ButtonText As String, ByVal ButtonToolTipText As String, ByVal MyFunction As ButtonFunction) As ToolStripButton

        Dim btnSomething As New ToolStripButton
        btnSomething.Text = ButtonText
        btnSomething.Image = ButtonImage
        btnSomething.TextImageRelation = TextImageRelation.ImageAboveText
        btnSomething.ToolTipText = ButtonToolTipText
        Select Case MyFunction
            Case ButtonFunction.Something1
                AddHandler btnSomething.Click, AddressOf SomethingClick
            Case ButtonFunction.Something2
                AddHandler btnSomething.Click, AddressOf Something2Click
        End Select
        Return btnSomething

    End Function

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

        MsgBox(CType(sender, ToolStripButton).ToolTipText & ", " & CType(sender, ToolStripButton).Text)

    End Sub

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

        MsgBox(CType(sender, ToolStripButton).ToolTipText & ", " & CType(sender, ToolStripButton).Text)

    End Sub

End Module


Then from each form you can create each button as it is needed like this

VB.NET
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim MyToolStrip As New ToolStrip
        Dim Button1 As ToolStripButton = ToolStripBase.CreateButton(Nothing, "Test 1", "This a test", ButtonFunction.Something1)
        Dim Button2 As ToolStripButton = ToolStripBase.CreateButton(Nothing, "Test 2", "This another test", ButtonFunction.Something1)
        MyToolStrip.Items.Add(Button1)
        MyToolStrip.Items.Add(Button2)
        MyToolStrip.Parent = Me

    End Sub


Happy Coding
GeneralRe: Dynamically adding tool strip buttons Pin
MacRaider43-May-10 6:30
MacRaider43-May-10 6:30 
QuestionRead data from MS Excel Pin
nishkarsh_k30-Apr-10 2:18
nishkarsh_k30-Apr-10 2:18 
AnswerRe: Read data from MS Excel Pin
Dave Kreskowiak30-Apr-10 4:01
mveDave Kreskowiak30-Apr-10 4:01 
GeneralRe: Read data from MS Excel [modified] Pin
nishkarsh_k3-May-10 2:25
nishkarsh_k3-May-10 2:25 
GeneralRe: Read data from MS Excel Pin
Dave Kreskowiak3-May-10 5:09
mveDave Kreskowiak3-May-10 5:09 
AnswerRe: Read data from MS Excel Pin
Wayne Gaylard30-Apr-10 4:05
professionalWayne Gaylard30-Apr-10 4:05 
GeneralRe: Read data from MS Excel Pin
nishkarsh_k2-May-10 20:28
nishkarsh_k2-May-10 20:28 
GeneralRe: Read data from MS Excel [modified] Pin
nishkarsh_k2-May-10 23:37
nishkarsh_k2-May-10 23:37 
GeneralRe: Read data from MS Excel Pin
Wayne Gaylard3-May-10 0:07
professionalWayne Gaylard3-May-10 0:07 
GeneralRe: Read data from MS Excel Pin
nishkarsh_k3-May-10 2:08
nishkarsh_k3-May-10 2:08 
GeneralRe: Read data from MS Excel Pin
nishkarsh_k4-May-10 3:27
nishkarsh_k4-May-10 3:27 
GeneralRe: Read data from MS Excel Pin
Wayne Gaylard4-May-10 20:44
professionalWayne Gaylard4-May-10 20:44 
GeneralRe: Read data from MS Excel Pin
nishkarsh_k5-May-10 0:28
nishkarsh_k5-May-10 0:28 
GeneralRe: Read data from MS Excel Pin
Wayne Gaylard5-May-10 1:41
professionalWayne Gaylard5-May-10 1:41 
GeneralRe: Read data from MS Excel Pin
nishkarsh_k6-May-10 19:53
nishkarsh_k6-May-10 19:53 
GeneralRe: Read data from MS Excel Pin
nishkarsh_k16-May-10 4:11
nishkarsh_k16-May-10 4:11 
GeneralRe: Read data from MS Excel Pin
nishkarsh_k17-Aug-10 2:36
nishkarsh_k17-Aug-10 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.