Click to See Complete Forum and Search --> : Lock Label Control


Aiianah
May 24th, 2001, 11:54 PM
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.

Tower
May 25th, 2001, 01:40 AM
Label Control is not editable in Run-Time.
For creating textbox non-editable use

Text1.Enabled = false

Cimperiali
May 25th, 2001, 04:34 AM
Tower is right. But if you want to use the locked property then paste this code in a form. Run, check /uncheck the checkbox and try to write in textbox:

Option Explicit
'a checkbox,
'a text box
Private Sub Check1_Click()
'if checked = locked
Text1.Locked = Check1.Value

'to do the contrary
'(if not checked = locked)
'Text1.Locked = Not Check1.Value

End Sub

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.

Aiianah
May 25th, 2001, 06:24 AM
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.)

Aiianah
May 25th, 2001, 06:29 AM
Thank you very much for your help, Tower. But what I really need with, if possible, is something that would lock the current label display when the checkbox associated with that label is checked when a command button is clicked to display an integer randomly.

Clearcode
May 25th, 2001, 06:31 AM
First, put a timer control on your form called Timer1 and set it's interval property to 100 (1/10th of a second)

Then in it's click event do:

private Sub Timer1_Click()

Label1.Caption = Format$(rnd() * 100,"000")

End Sub




Then in your checkbox, enable or diable the timer...

private Sub Check1_Click()

Timer1.Enabled = (Ckeck1.Value <> vbChecked)

End Sub




HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com

naiiantopdog
May 25th, 2001, 12:20 PM
I believe what you're looking for is this:


private Sub Check1_Click()
Label1.Enabled = false
End Sub




Let me know if this is what you want.

sfieldho
May 25th, 2001, 01:43 PM
But there is no reason to "lock" a label - they can't be updated by the user. Simply set the label's caption to the value you want in the click event of the checkbox or the button. Throw in a DoEvents to make sure the label is repainted, if necessary.

Cimperiali
May 28th, 2001, 02:36 AM
or you cand do all in command1 click event:
'one form, two checkboxes, two label, one command button
Option Explicit

Private Sub Command1_Click()
If Check1.Value = vbChecked Then '1= true
Label1.Caption = Format$(Rnd() * 100, "000")
End If
If Check2.Value = vbChecked Then
Label2.Caption = Format$(Rnd() * 100, "000")
End If
End Sub
'if checkbox is checked, perform new calculation. Else leave it as it is



Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.

Cimperiali
May 28th, 2001, 02:52 AM
...Too fast I answered...
if you want to hold the value (=not perform new calculations) while checks are checked, simply substitute this:
...
If Check1.Value = vbChecked Then
...
with this
...
If Check1.Value = vbUnchecked Then
...

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.