I am creating a user control that contains a panel as well as 4 string and integer properties. I would like to display the text of the properties in the user control during design time. How do I do this? I am having a hard time finding examples.
Odd question, the usual problem is hiding a property. Make it look something like this:
Imports System.ComponentModel
Public Class UserControl1
Private mAardvark As Integer
<DefaultValue(0)> _
Public Property Aardvark() As Integer
Get
Return mAardvark
End Get
Set(ByVal value As Integer)
mAardvark = value
End Set
End Property
End Class
Amy, it's hard to tell exactly what you're after.
When you have properties in user controls you can see and edit those properties in the Properties Window in design view.
So if you take nobugz answer in the properties window you will be able to set a value for the property Aardvark.
Is what you're asking that you want to see the value of the property in something like a text box?
If that is the case you need to make sure that the value returned from the property is a value i.e. not nothing! And that the property is set in an event like Load.
Also at design time the usercontrol view does not draw the values, if you drop the control on a form you will be able to see the values of your properties in a text box.
I am not exactly sure what you are asking, but I have assumed you want to display the property text in the control at design-time and hide this at run-time.
If this is the case, you will need to update the Label.Text value whenever the property value changes.
I have assumed that your control includes a Label named lblPageNum and a property PageNum.
Public Class TheUserControl
Private myPageNum As String
Public Property PageNum() As String
Get
PageNum = myPageNum
End Get
Set(ByVal value As String)
myPageNum = value
' This is where we set the value of the label at design-time
lblPageNum.Text = myPageNum
End Set
End Property
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Me.DesignMode Then
Me.lblPageNum.Visible = True
Else
Me.lblPageNum.Visible = False
End If
End Sub
End Class