CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2001
    Location
    San Diego CA
    Posts
    378

    In-Place label edit

    How do I edit a (CStatic) label string at run time.

    Examples/Links are cool.

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757
    One solution is to add a member variable of type CSting that corresponds to the static control via resource editor.

    Kuphryn

  3. #3
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by kuphryn
    One solution is to add a member variable of type CSting that corresponds to the static control via resource editor.
    Interesting technique... It is new to me that you can add variables in the resource editor...

    @voidspace: Do you mean editing or changing? In the first case, you'd better use a CEdit control instead (you can change its style between read-only and editable). If you just want to change its text at runtime, use ClassWizard to add a DDX member variable of type CString for the control. Make sure to change the control ID from the default IDC_STATIC to something else, as IDC_STATIC has a special meaning and will prevent you from adding a DDX variable.

  4. #4
    Join Date
    Apr 2001
    Location
    San Diego CA
    Posts
    378
    Oh No!

    And CStatic member control variables is required if you want to change the value programatically. ( also renaming)

    I understand that.

    What I meant was when the program is running. I have a label say

    "Name"(displayed and it has a control variable) and adjacent to it I have a edit ctrl in which they type name. I want the user to be able to click on the label "Name" and the label should turn into a edit control momentarily and allow "Name" to be modified to "Alias". Upon lossing focus from that control it should turn back into a label.

    In Place edting of static label

  5. #5
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by voidspace
    In Place edting of static label
    I see. So if a read-only edit control (which you temporarily change to editable) doesn't fit your needs, what about the following approach:
    When the static control is clicked, dynamically create an edit control having the same bounds. As soon as it loses focus, get the text and destroy the control.

  6. #6
    Join Date
    Apr 2001
    Location
    San Diego CA
    Posts
    378

    Thumbs up

    Excellent!

    Will try that.
    Also realised from ur post that a edit control can be used as a static label also.

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635
    Originally posted by voidspace
    "Name"(displayed and it has a control variable) and adjacent to it I have a edit ctrl in which they type name. I want the user to be able to click on the label "Name" and the label should turn into a edit control momentarily and allow "Name" to be modified to "Alias". Upon lossing focus from that control it should turn back into a label.

    In Place edting of static label
    One approach is to have an edit control and a static the same size and location in the resource editor. Hide whichever one you don't want to be seen at the time. Sounds like a kind of counter intuitive user interface though.

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