UserControl Woes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don

    #1

    UserControl Woes

    I've created a custom UserControlwith in which I have placed a Panel. I've
    changed the Panel's "Modifier" property to Public so that it appears in the
    Properties Window of the UserControl. This way, I could modify the
    properties of the panel within the UserControl when I place a UserControl on
    a Form. Or so I thought.

    I can set the properties of the Panel within the UserControl via the
    Properties Window, but none of the changes made to the Panel inside the
    UserControl in this way are remembered when I actually run the project.

    Has anyone come across this before? Is there a fix for this?

    - Don


  • Ken Tucker [MVP]

    #2
    Re: UserControl Woes

    Hi,

    Here is some code from an user control that has a textbox. It has
    the user controls textchanged, and validating events fire when the textbox's
    events fire. Also makes the user controls text property change the
    textboxes text. Hope this helps.

    Public Shadows Event TextChanged(ByV al sender As Object, ByVal e As
    EventArgs)

    Public Shadows Event Validating(ByVa l sender As Object, ByRef e As
    System.Componen tModel.CancelEv entArgs)

    Public Shadows Property Text() As String

    Get

    Return TextBox1.Text

    End Get

    Set(ByVal Value As String)

    TextBox1.Text = Value

    End Set

    End Property

    Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles TextBox1.TextCh anged

    RaiseEvent TextChanged(Me, e)

    End Sub

    Private Sub TextBox1_Valida ting(ByVal sender As Object, ByVal e As
    System.Componen tModel.CancelEv entArgs) Handles TextBox1.Valida ting

    RaiseEvent Validating(Me, e)

    End Sub



    Ken

    ---------------------
    "Don" <unknown@oblivi on.com> wrote in message
    news:1p1pe.1587 829$8l.1445249@ pd7tw1no...
    I've created a custom UserControlwith in which I have placed a Panel. I've
    changed the Panel's "Modifier" property to Public so that it appears in the
    Properties Window of the UserControl. This way, I could modify the
    properties of the panel within the UserControl when I place a UserControl on
    a Form. Or so I thought.

    I can set the properties of the Panel within the UserControl via the
    Properties Window, but none of the changes made to the Panel inside the
    UserControl in this way are remembered when I actually run the project.

    Has anyone come across this before? Is there a fix for this?

    - Don



    Comment

    • Don

      #3
      Re: UserControl Woes

      Thanks for the response, but this doesn't address my issue at all. I would
      like to be able to make changes to all controls within a user control in the
      Property Designer and have those changes stick when I run the program. I'd
      really rather not write all that code for every one of the dozens of
      properties for each control. There has to be a way to do that.

      - Don


      "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
      news:u%23n8G6ua FHA.2356@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > Hi,
      >
      > Here is some code from an user control that has a textbox. It has
      > the user controls textchanged, and validating events fire when the[/color]
      textbox's[color=blue]
      > events fire. Also makes the user controls text property change the
      > textboxes text. Hope this helps.
      >
      > Public Shadows Event TextChanged(ByV al sender As Object, ByVal e As
      > EventArgs)
      >
      > Public Shadows Event Validating(ByVa l sender As Object, ByRef e As
      > System.Componen tModel.CancelEv entArgs)
      >
      > Public Shadows Property Text() As String
      >
      > Get
      >
      > Return TextBox1.Text
      >
      > End Get
      >
      > Set(ByVal Value As String)
      >
      > TextBox1.Text = Value
      >
      > End Set
      >
      > End Property
      >
      > Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal e As
      > System.EventArg s) Handles TextBox1.TextCh anged
      >
      > RaiseEvent TextChanged(Me, e)
      >
      > End Sub
      >
      > Private Sub TextBox1_Valida ting(ByVal sender As Object, ByVal e As
      > System.Componen tModel.CancelEv entArgs) Handles TextBox1.Valida ting
      >
      > RaiseEvent Validating(Me, e)
      >
      > End Sub
      >
      >
      >
      > Ken
      >
      > ---------------------
      > "Don" <unknown@oblivi on.com> wrote in message
      > news:1p1pe.1587 829$8l.1445249@ pd7tw1no...
      > I've created a custom UserControlwith in which I have placed a Panel. I've
      > changed the Panel's "Modifier" property to Public so that it appears in[/color]
      the[color=blue]
      > Properties Window of the UserControl. This way, I could modify the
      > properties of the panel within the UserControl when I place a UserControl[/color]
      on[color=blue]
      > a Form. Or so I thought.
      >
      > I can set the properties of the Panel within the UserControl via the
      > Properties Window, but none of the changes made to the Panel inside the
      > UserControl in this way are remembered when I actually run the project.
      >
      > Has anyone come across this before? Is there a fix for this?
      >
      > - Don
      >
      >
      >[/color]


      Comment

      • Don

        #4
        Re: UserControl Woes

        I have discovered the solution to my question. If you want to edit
        properties for any nested control within a UserControl and not have your
        program forget any changes made in the Property Designer window once the
        program is executed, you should leave the scope of the control as Friend
        (i.e. don't make it Public) and, instead, create a property for it like so:


        e.g. Exposing a button called 'Button1' on a UserControl

        Imports System.Componen tModel


        <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Content)> _
        Public ReadOnly Property MyButton() As Button
        Get
        Return Me.Button1
        End Get
        End Property


        - Don


        "Don" <unknown@oblivi on.com> wrote in message
        news:1p1pe.1587 829$8l.1445249@ pd7tw1no...[color=blue]
        > I've created a custom UserControlwith in which I have placed a Panel. I've
        > changed the Panel's "Modifier" property to Public so that it appears in[/color]
        the[color=blue]
        > Properties Window of the UserControl. This way, I could modify the
        > properties of the panel within the UserControl when I place a UserControl[/color]
        on[color=blue]
        > a Form. Or so I thought.
        >
        > I can set the properties of the Panel within the UserControl via the
        > Properties Window, but none of the changes made to the Panel inside the
        > UserControl in this way are remembered when I actually run the project.
        >
        > Has anyone come across this before? Is there a fix for this?
        >
        > - Don
        >
        >[/color]


        Comment

        Working...