dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Set Background and ForeGround of the Label

  1. #1
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110

    Set Background and ForeGround of the Label

    How to set the background and text color of the Static Text filed

    Thankx

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,148
    Add a handler for OnCtlColor.
    Sample from MSDN:
    Code:
    // This OnCtlColor handler will change the color of a static control
    // with the ID of IDC_MYSTATIC. The code assumes that the CMyDialog
    // class has an initialized and created CBrush member named m_brush.
    // The control will be painted with red text and a background
    // color of m_brush.
    
    HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
       // Call the base class implementation first! Otherwise, it may
       // undo what we're trying to accomplish here.
       HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    
       // Are we painting the IDC_MYSTATIC control? We can use
       // CWnd::GetDlgCtrlID() to perform the most efficient test.
       if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
       {
          // Set the text color to red
          pDC->SetTextColor(RGB(255, 0, 0));
    
          // Set the background mode for text to transparent 
          // so background will show thru.
          pDC->SetBkMode(TRANSPARENT);
    
          // Return handle to our CBrush object
          hbr = m_brush;
       }
    
       return hbr;
    }
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110
    Thankx for the replay
    Can u please tell me the folowins

    how to draw a thick line in blue color

    How to set text bold

    Thankx

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,148
    Originally posted by dinesh123
    how to draw a thick line in blue color
    Create a CPen object and select that pen into the DC. The constructor of CPen allows you to specify a width for your pen. Once your pen is selected, draw your line. At the end, select the old pen back into the DC. (The old pen is returned to you when you select your pen into the DC).
    How to set text bold
    You'll have to create a CFont object and select it into the DC. Draw your text and afterwards select the old font back into the DC.


    Do you want the above two things in your label control?
    If so, I advise you to draw the entire control yourself instead of changing pens and fonts inside OnCtlColor.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)