MenuStrip and ToolStripControlHost control

LaBoss

New member
Joined
Nov 2, 2010
Messages
2
Programming Experience
Beginner
Good afternoon,

I'm having some trouble with a class that uses the ToolStripControlHost, I have to create a label and a label beside the textbox, this works, the problem now and I can not access the property. .Text of textbox (dim txt). the class to this:

VB.NET:
Public Class ToolStripTextBoxWithLabel
  Inherits ToolStripControlHost

  Public Event TextoAlterado(ByVal sender As System.Object, ByVal e As System.EventArgs)

  Public Sub New(Optional ByVal lblText As String = "label")

    MyBase.New(New ControlPanel(lblText))
    AddHandler CType(MyBase.Control, ControlPanel).TextoAlterado, AddressOf InformaTextoAlterado

  End Sub

  Public Sub InformaTextoAlterado(ByVal sender As Object, ByVal e As System.EventArgs)
    RaiseEvent TextoAlterado(sender, e)
  End Sub

  Public ReadOnly Property ControlPanelControl() As ControlPanel
    Get
      Return CType(Me.Control, ControlPanel)
    End Get
  End Property

End Class


Public Class ControlPanel
  Inherits Panel

  Friend WithEvents txt As New TextBox
  Friend WithEvents lbl As New Label

  Public Event TextoAlterado(ByVal sender As System.Object, ByVal e As System.EventArgs)
  Private Sub txt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt.TextChanged
    RaiseEvent TextoAlterado(sender, e)
  End Sub

  Public Sub New(ByVal lblText As String)

    Me.Height = 20

    lbl.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or AnchorStyles.Bottom
    lbl.Text = lblText
    lbl.TextAlign = ContentAlignment.BottomLeft
    lbl.AutoSize = True
    lbl.Height = Me.Height
    lbl.Location = New Point(0, 3)
    lbl.Parent = Me

    txt.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top
    txt.Location = New Point(lbl.Right + 5, 0)
    txt.Width = Me.Width - txt.Left

    txt.Parent = Me

  End Sub
End Class


I have no idea how and what I do to access this property through the form ... I am calling the class this way:

VB.NET:
 Dim CaixaNIF As New ToolStripTextBoxWithLabel("NIF: ")

    AddHandler CaixaCliente.TextoAlterado, AddressOf TextoAlteradoCliente


Someone help me? Grateful for the help ..
 
First up, don't inherit Panel. There's already a specific mechanism for this. Add a new UserControl to your project, just like you add a new form. You then add the appropriate child controls to the UserControl in the same way you would a form. You then add the appropriate members to the UserControl. If you want to expose the Text of the TextBox then you declare an appropriate property and pass through the Text property of the TextBox, e.g.
VB.NET:
Public Property TextBoxText() As String
    Get
        Return Me.TextBox1.Text
    End Get
    Set(ByVal value As String)
        Me.TextBox1.Text = value
    End Set
End Property
You now add an instance of your UserControl to your ToolStripControlHost and access the TextBoxText property. You can then add a property to that class to pass through the UserControl's property if you like.
 
I could not understand what I do, will be able to explain myself better?

I have to add a UserControl, user and program this controller, as my class toolstrip
 

Latest posts

Back
Top