-
June 22nd, 2004, 04:21 AM
#1
Set Background and ForeGround of the Label
How to set the background and text color of the Static Text filed
Thankx
-
June 22nd, 2004, 05:51 AM
#2
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;
}
-
June 22nd, 2004, 10:53 PM
#3
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
-
June 23rd, 2004, 02:26 AM
#4
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).
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|