Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Costum windows form control not working 1

Status
Not open for further replies.

ganjafarmerIT

Programmer
Jun 29, 2004
30
NL
Hi guys, I'm trying to create a costum windows form control that consists of 4 controls:
a checkbox, and three labels.

I can't seem to get it to work. The problem I'm dealing with is that I can't assign any values to the labels when running my app. the label text doesn't change.

Here is my control's code:

<code>
Inherits Control
Private myCheckbox As New CheckBox
Private WithEvents myTime As New Label
Private WithEvents myStatus As New Label
Private WithEvents mySendsize As New Label

Public Sub New()
myTime.Name = "myTime1"
Me.Controls.Add(myCheckbox)
Me.Controls.Add(myTime)
Me.Controls.Add(myStatus)
Me.Controls.Add(mySendsize)

End Sub

#Region "set functions"
Public Sub setTime(ByVal time As String)
myTime.Text = time
End Sub
Public Sub setStatus(ByVal status As String)
myStatus.Text = status
End Sub
Public Sub setsendsize(ByVal size As String)
mySendsize.Text = size
End Sub
#End Region


</code>

Now I tried using properties instead of subs, but even thos won't work.

If I call the sub setsendsize("test")
nothing happens:(.
Hope you guys can help me on this one cause it's giving me a headache, it's not supposed to be this hard. I've created controls in asp.net and that was easy.
 
Use property Get and Set to get and set values to the controls of your windows control. If the control that you draged at the windows form has name: "abc" then:

abc.setsendsize = "14" 'for example

The code you wrote can be accessed and used programmatically inside with the other code, like:

setsendsize("14")
 
thanks for your reply m8, I already tried using properties to set the values of the three labels. That didn't work either:(.

the problem is that it doesn't display the text on the screen:( and doesn't generate any errors either.
reilly weird
 
Like this:


Public Property setebdsize()
Get
Return mySendsize.Text
End Get
Set(ByVal Value)
mySendsize.Text = Value
End Set
End Property


Agree?
 
Have you created an instance of the control with New in the form that hosts the control?
 
yes m8, I tried the following

<code>
Public Property time() As String
Get
Return myTime.Text
End Get
Set(ByVal Value As String)
myTime.Text = Value
End Set
End Property
</code>

myTime.text is one of the tree labels I have inside my costum control.

But it just doens't display the text on the screen.

 
earthandfire, I haven't done it my self. I thought that visual studio automatically creates it when I drag my constum control to the form?
 
Code:
   Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        Me.Controls.Add(myCheckbox)

        myStatus.Text = "STATUS"
        myStatus.AutoSize = True
        myStatus.Location = New System.Drawing.Point(0, 30)

        myTime.Text = "12:00"
        myTime.AutoSize = True
        myTime.Location = New System.Drawing.Point(0, 50)

        Me.Controls.Add(mytime)
        Me.Controls.Add(myStatus)
        Me.Controls.Add(mySendsize)
        
    End Sub


Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
I have fixed the problem.
I created an GUI usercontrol.
Which automaticly had the *.Location.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top