|
-
May 24th, 2001, 11:54 PM
#1
Lock 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, 01:40 AM
#2
Re: Lock Label Control
Label Control is not editable in Run-Time.
For creating textbox non-editable use
Text1.Enabled = false
Andy Tower
-
May 25th, 2001, 04:34 AM
#3
Re: Lock Label Control
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.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
May 25th, 2001, 06:24 AM
#4
Re: Lock 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, 06:29 AM
#5
Re: Lock Label Control
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.
-
May 25th, 2001, 06:31 AM
#6
Re: Lock Label Control
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
-
May 25th, 2001, 12:20 PM
#7
Re: Lock Label Control
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.
-
May 25th, 2001, 01:43 PM
#8
Re: Lock Label Control
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.
-
May 28th, 2001, 02:36 AM
#9
Re: Lock Label Control
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.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
May 28th, 2001, 02:52 AM
#10
Re: Lock Label Control
...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.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
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
|