|
-
May 24th, 2001, 11:46 PM
#1
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.
-
May 25th, 2001, 04:59 AM
#2
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
-
May 25th, 2001, 06:22 AM
#3
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.)
-
May 25th, 2001, 08:01 AM
#4
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
-
May 25th, 2001, 10:08 AM
#5
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
-
May 25th, 2001, 10:13 PM
#6
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!
-
May 25th, 2001, 10:33 PM
#7
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
-
May 26th, 2001, 07:22 AM
#8
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!
-
May 26th, 2001, 10:18 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|