How do I edit a (CStatic) label string at run time.
Examples/Links are cool.
Printable View
How do I edit a (CStatic) label string at run time.
Examples/Links are cool.
One solution is to add a member variable of type CSting that corresponds to the static control via resource editor.
Kuphryn
Interesting technique... It is new to me that you can add variables in the resource editor... :pQuote:
Originally posted by kuphryn
One solution is to add a member variable of type CSting that corresponds to the static control via 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.
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 ;)
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:Quote:
Originally posted by voidspace
In Place edting of static label ;)
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.
Excellent!
Will try that.
Also realised from ur post that a edit control can be used as a static label also.
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.Quote:
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 ;)