By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,742 Members | 1,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,742 IT Pros & Developers. It's quick & easy.

UserControl Woes

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

---------------------
"Don" <un*****@oblivion.com> wrote in message
news:1p1pe.1587829$8l.1445249@pd7tw1no...
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

Nov 21 '05 #2

P: n/a
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
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:u%****************@TK2MSFTNGP10.phx.gbl...
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

---------------------
"Don" <un*****@oblivion.com> wrote in message
news:1p1pe.1587829$8l.1445249@pd7tw1no...
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

Nov 21 '05 #3

P: n/a
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(DesignerSerializa tionVisibility.Content)> _
Public ReadOnly Property MyButton() As Button
Get
Return Me.Button1
End Get
End Property
- Don
"Don" <un*****@oblivion.com> wrote in message
news:1p1pe.1587829$8l.1445249@pd7tw1no...
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

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.