CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    12

    Setting Control Properties

    Hi, I am a VB programmer learning MFC.
    I have a label on a dialog I have a button on a dialog. When I click the button I want to change the caption of the label. What is the syntax?
    I have tried the following.
    CString temp = "New Caption.";
    label1.Caption = temp;

    The line "label1.Caption = temp;" causes a compile error because I do not have a class name in front of it. My dialog is named form1. I have tried:
    Form1::label1.caption = temp;
    This produces even more compiler errors.
    Can any of you Gurus convert this simple VB statement to MFC?

    Form1.Label1.Caption = temp

    Thank You
    Hexie



  2. #2
    Join Date
    Apr 1999
    Location
    CA, USA
    Posts
    78

    Re: Setting Control Properties

    Use SetWindowText() to change the dialog's title, editbox's text, or a static text. For example,

    // the label you create is a StaticText with resource ID (IDC_STATIC1)
    CStatic *pLabel = (CStatic*)GetDlgItem(IDC_STATIC1);
    ASSERT(pLabel != NULL);

    pLabel->SetWindowText("New Caption");
    // done


    If you want to change dialog's title, simply call the same function:
    SetWindowText("New Title"); // must be called within the dialog class

    Hope this will help. Good luck.

    Lynx


  3. #3
    Join Date
    Apr 1999
    Posts
    12

    Re: Setting Control Properties

    Hi Lynx,
    Thanks for responding to my post on setting properties.
    My post was a generalized case however, I need to know how to set any property. Setting the caption of a label was not my goal. Mostly I need to know how to access any property of a custom control.
    I have a custom image box OCX made by ImageFX. It has a property call "FileName".I need to assign a string to this property to activate its internal method of loading a picture. In VB the code would look lie this:

    Form1.imgFX.FileName = "C:\myfile.bmp"

    So I need to assign a string to a property. Mainly I need to know what the syntax is for accessing Form1.
    Form1::imgFX.FileName = CString ("C:\myfile.bmp");
    Does not work. Any ideas?
    Hexie


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