UserControl Woes

D

Don

I've created a custom UserControlwithin 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
 
K

Ken Tucker [MVP]

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(ByVal sender As Object, ByVal e As
EventArgs)

Public Shadows Event Validating(ByVal sender As Object, ByRef e As
System.ComponentModel.CancelEventArgs)

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_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged

RaiseEvent TextChanged(Me, e)

End Sub

Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating

RaiseEvent Validating(Me, e)

End Sub



Ken

---------------------
I've created a custom UserControlwithin 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
 
D

Don

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
 
D

Don

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.ComponentModel


<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property MyButton() As Button
Get
Return Me.Button1
End Get
End Property


- Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top