none
Como fazer essa rotina rodar RRS feed

  • Pergunta

  • Devido a minha pouca experiência, não consigo resolver os problemas que surgem nessas linhas:

    buttonBlue.Click += New EventHandler(AddressOf colorButtonsClick)
                buttonRed.Click += New EventHandler(AddressOf colorButtonsClick)
                buttonYellow.Click += New EventHandler(AddressOf colorButtonsClick)
                dropDown.Items.AddRange(New ToolStripItem() {buttonRed, buttonBlue, buttonYellow})
                toolStrip1.Items.Add(dropDownButton1)

    A rotina inteira é esta abaixo:

    Public Class Form1

        Class SurroundingClass
            Friend dropDownButton1 As ToolStripDropDownButton
            Friend dropDown As ToolStripDropDown
            Friend buttonRed As ToolStripButton
            Friend buttonBlue As ToolStripButton
            Friend buttonYellow As ToolStripButton
            Private Sub InitializeDropDownButton()
                dropDownButton1 = New ToolStripDropDownButton()
                dropDown = New ToolStripDropDown()
                dropDownButton1.Text = "A"
                dropDownButton1.DropDown = dropDown
                dropDownButton1.DropDownDirection = ToolStripDropDownDirection.Left
                dropDownButton1.ShowDropDownArrow = False
                buttonRed = New ToolStripButton()
                buttonRed.ForeColor = Color.Red
                buttonRed.Text = "A"
                buttonBlue = New ToolStripButton()
                buttonBlue.ForeColor = Color.Blue
                buttonBlue.Text = "A"
                buttonYellow = New ToolStripButton()
                buttonYellow.ForeColor = Color.Yellow
                buttonYellow.Text = "A"
                buttonBlue.Click += New EventHandler(AddressOf colorButtonsClick)
                buttonRed.Click += New EventHandler(AddressOf colorButtonsClick)
                buttonYellow.Click += New EventHandler(AddressOf colorButtonsClick)
                dropDown.Items.AddRange(New ToolStripItem() {buttonRed, buttonBlue, buttonYellow})
                toolStrip1.Items.Add(dropDownButton1)
            End Sub
           
        End Class
        Private Sub colorButtonsClick(ByVal sender As Object, ByVal e As EventArgs)
            Dim senderButton As ToolStripButton = CType(sender, ToolStripButton)
            Me.ForeColor = senderButton.ForeColor
        End Sub
    End Class
    quinta-feira, 4 de abril de 2019 19:25

Todas as Respostas

  • Olá, Durval! Faça as seguintes alterações:

    Public Class Form1 Class SurroundingClass Friend dropDownButton1 As ToolStripDropDownButton Friend dropDown As ToolStripDropDown Friend buttonRed As ToolStripButton Friend buttonBlue As ToolStripButton Friend buttonYellow As ToolStripButton Private Sub InitializeDropDownButton() dropDownButton1 = New ToolStripDropDownButton() dropDown = New ToolStripDropDown() dropDownButton1.Text = "A" dropDownButton1.DropDown = dropDown dropDownButton1.DropDownDirection = ToolStripDropDownDirection.Left dropDownButton1.ShowDropDownArrow = False buttonRed = New ToolStripButton() buttonRed.ForeColor = Color.Red buttonRed.Text = "A" buttonBlue = New ToolStripButton() buttonBlue.ForeColor = Color.Blue buttonBlue.Text = "A" buttonYellow = New ToolStripButton() buttonYellow.ForeColor = Color.Yellow buttonYellow.Text = "A"

    AddHandler buttonBlue.Click, AddressOf colorButtonsClick
    AddHandler buttonRed.Click, AddressOf colorButtonsClick
    AddHandler buttonYellow.Click, AddressOf colorButtonsClick 'buttonBlue.Click += New EventHandler(AddressOf colorButtonsClick) 'buttonRed.Click += New EventHandler(AddressOf colorButtonsClick) 'buttonYellow.Click += New EventHandler(AddressOf colorButtonsClick) dropDown.Items.AddRange(New ToolStripItem() {buttonRed, buttonBlue, buttonYellow})

    toolStrip1.Items.Add(dropDownButton1) End Sub End Class Private Sub colorButtonsClick(ByVal sender As Object, ByVal e As EventArgs) Dim senderButton As ToolStripButton = CType(sender, ToolStripButton) Me.ForeColor = senderButton.ForeColor End Sub End Class


    Att, Wallace


    “First do it, then do it right, then do it better.” - Addy Osmani

    quinta-feira, 4 de abril de 2019 20:45
  • Olá Wallace, copiei e colei essa rotina com tuas alterações. Ainda acusam erro nas linhas:

    AddHandler buttonBlue.Click, AddressOf colorButtonsClick
                AddHandler buttonRed.Click, AddressOf colorButtonsClick
                AddHandler buttonYellow.Click, AddressOf colorButtonsClick

    e

                       toolStrip1.Items.Add(dropDownButton1)

    erro: Reference to a non -Shared member requires on objct reference

    Deve ser algum controle que estou deixando de carregar, carreguei só toolStrip1

    O que está faltando fazer? 

    Grato.

    sexta-feira, 5 de abril de 2019 21:42
  • Public Class Form1
    
            Friend dropDownButton1 As ToolStripDropDownButton
            Friend dropDown As ToolStripDropDown
            Friend buttonRed As ToolStripButton
            Friend buttonBlue As ToolStripButton
            Friend buttonYellow As ToolStripButton
           
            Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
                dropDownButton1 = New ToolStripDropDownButton()
                dropDown = New ToolStripDropDown()
                dropDownButton1.Text = "A"
                dropDownButton1.DropDown = dropDown
                dropDownButton1.DropDownDirection = ToolStripDropDownDirection.Left
                dropDownButton1.ShowDropDownArrow = False
                buttonRed = New ToolStripButton()
                buttonRed.ForeColor = Color.Red
                buttonRed.Text = "A"
                buttonBlue = New ToolStripButton()
                buttonBlue.ForeColor = Color.Blue
                buttonBlue.Text = "A"
                buttonYellow = New ToolStripButton()
                buttonYellow.ForeColor = Color.Yellow
                buttonYellow.Text = "A"
                buttonBlue.Click += New EventHandler(AddressOf colorButtonsClick)
                buttonRed.Click += New EventHandler(AddressOf colorButtonsClick)
                buttonYellow.Click += New EventHandler(AddressOf colorButtonsClick)
                dropDown.Items.AddRange(New ToolStripItem() {buttonRed, buttonBlue, buttonYellow})
                toolStrip1.Items.Add(dropDownButton1)
            Me.Controls.Add(toolStrip1)
            
            End Sub
    
        Private Sub colorButtonsClick(ByVal sender As Object, ByVal e As EventArgs)
            Dim senderButton As ToolStripButton = CType(sender, ToolStripButton)
            Me.ForeColor = senderButton.ForeColor
        End Sub
    End Class
    
    
    http://www.macoratti.net/vbn_cwf.htm

    “First do it, then do it right, then do it better.” - Addy Osmani

    sábado, 6 de abril de 2019 17:28