Results 1 to 3 of 3

Thread: Using a Label within a class

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    5

    Angry Using a Label within a class

    Hi, what I'm trying to do here is allow the user on the actual form to enter the number of 'Count' (that's what the class is called) to be made. It receives a value for the variable 'Name', then allots it to Labelx.Text. Then, I would like Labelx to appear on the actual form, but it does not. Can anyone tell me why? This code should actually be pretty simple for experience programmers, but unfortunately I am not. Please excuse the redundancy of my code, for I can clear that up later.
    Public Class Count

    ' Option Explicit On - needed?

    Dim Name As Integer
    Dim Number As Integer
    Dim IsBeat As Boolean

    Public Sub Set_Number(ByVal Number As Integer)
    Number = Number
    Name = CStr(Number)
    End Sub

    Public Function Get_Number()
    Dim Labelx As New Label
    Labelx.Size = New System.Drawing.Size(50, 50) ' Is this needed?
    Labelx.Location = New System.Drawing.Point(100, 100) ' Is this needed?
    Labelx.Text = Name
    Labelx.Visible = True
    End Function

    End Class


    Best regards,
    Ben.

  2. #2
    Addicted Member phenom's Avatar
    Join Date
    Apr 2006
    Location
    UAE
    Posts
    233

    Re: Using a Label within a class

    Hi

    add this code at the end of Get_Number()
    VB Code:
    1. Me.Controls.Add(Labelx)

    Hope this helps...

    Regards
    =======================================
    If I helped you, Kindly Rate my post. Thanks
    -----------
    PHENOM

  3. #3
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Using a Label within a class

    Won't work as you have it...try this


    VB Code:
    1. 'on a form
    2.  Dim myCount As New Count
    3.  Me.Controls.Add(myCount.Get_Number())
    4.  
    5.  
    6. 'class
    7. Public Function Get_Number() As Label
    8.         Dim Labelx As New Label
    9.         Labelx.Size = New System.Drawing.Size(50, 50) ' Is this needed?
    10.         Labelx.Location = New System.Drawing.Point(100, 100) ' Is this needed?
    11.         Labelx.Text = Name
    12.         Labelx.Visible = True
    13.         Return Labelx
    14.     End Function
    Last edited by gtilles; Jul 7th, 2006 at 11:56 PM.
    Truly, you have a dizzying intellect.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width