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

    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.



  2. #2
    Join Date
    May 2001
    Location
    Russia
    Posts
    200

    Re: Lock Label Control

    Label Control is not editable in Run-Time.
    For creating textbox non-editable use

    Text1.Enabled = false




    Andy Tower

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    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.

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

    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.)


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

    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.


  6. #6
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    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
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  7. #7
    Join Date
    May 2001
    Posts
    2

    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.


  8. #8
    Join Date
    May 2001
    Location
    London
    Posts
    4

    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.


  9. #9
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    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.

  10. #10
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    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
  •  





Click Here to Expand Forum to Full Width

Featured