CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2000
    Location
    Hawaii
    Posts
    19

    vb label control

    How do you lock a label caption in VB. I'm trying to make a program close to a poker/slotmachine game that uses label controls instead of textbox controls. I want to be able to lock a label caption when a checkbox is checked. For example:

    To lock a textbox control:

    if check1.value = vbchecked then
    text1.locked = true
    end if

    How do you do something similar using a label control? Can anyone help me? Thank you very much.



  2. #2
    Join Date
    Aug 2000
    Location
    England
    Posts
    185

    Re: vb label control

    I think labels are locked by default anyway. They are non-editable, so there is no need to have an enabled property. If you mean changing the colour then try setting the background colour property at run-time.

    Andrew


  3. #3
    Join Date
    Jul 2000
    Location
    Hawaii
    Posts
    19

    Re: vb label control

    Thank you so much for your help. Unfortunately, what I'm looking for is something that would lock a label control once it is associated with a checkbox control. For example, when a command button is clicked, display random integers on label control's caption property unless the checkbox control is checked (In other words, hold whatever integer the label is displaying when the checkbox is checked.)


  4. #4
    Join Date
    Aug 2000
    Location
    England
    Posts
    185

    Re: vb label control

    Well in that case you don't need to lock it. All you need is to have a check to see whether the check box is selected and if it is not then display the random numbers, otherwise ignore it...


    if (me.myCheckBox.value = false) then
    me.myLabel.caption = ' some random number
    else
    ' whatever else you want to do here
    end if





  5. #5
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: vb label control

    I think what you wanna achieve is more toward programming logic instead of the properties of the controls. Anyway, I think the easiest way is to use Control Array of Labels and CheckBoxes. Check out the codes below:

    Form1 with 2 CheckBoxes (index 0, 1) and 2 Labels (index 0, 1)

    private Sub Command1_Click()
    ' loop through the controls
    for i = 0 to (Label1.Count-1)
    ' check if the related checkbox is checked or not
    if (Check1(i).Value <> vbChecked) then
    ' assign random number
    Label1(i).Caption = SomeRandomNumber()
    end if
    next i
    End Sub




    -Cool Bizs

    Good Luck,
    -Cool Bizs

  6. #6
    Join Date
    Jul 2000
    Location
    Hawaii
    Posts
    19

    Re: vb label control

    Thank you very very very much, coolbiz. It works!!! I do have one more question, if it's not too much to ask...how do you limit the number of checkboxes to be checked? For example, if I only wanted to select 3 out of 7 checkboxes...

    You've been a great help. I'm still trying to learn. Thank you very much again!


  7. #7
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: vb label control

    Since the Checkboxes are actually Control Array, then you use the Click event to check.


    private Sub Check1_Click(Index as Integer)
    ' count how many has been checked
    Dim nCurCount as Integer
    Dim i as Integer
    for i = 0 to (Check1.Count - 1)
    If (Check1(i).Value = vbChecked) then nCurCount = nCurCount + 1
    next i

    If (nCurCount > 2) then
    MsgBox "Max reached"
    Check1(Index).Value = vbUnchecked
    End If
    End Sub




    -Cool Bizs

    Good Luck,
    -Cool Bizs

  8. #8
    Join Date
    Jul 2000
    Location
    Hawaii
    Posts
    19

    Re: vb label control

    Thank you so much, Coolbiz...You've been such a great help. I have manage to finish my program and it's because of all your help...Thanks..Thanks..and Thanks Again!


  9. #9
    Join Date
    Jun 2000
    Location
    Nepal
    Posts
    108

    Re: vb label control

    Don't forget to rate a reply if it is useful to you.


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

Featured