簡體   English   中英

如何在屬性透明時更改靜態控件的字體大小和字體

[英]How to change font size and font of static control when the property is transparent

我創建了兩個CStatic控件。 一個屬性設置為透明模式; 另一個是正常的。 更改字體大小后,一個是OK,它已更改,但設置透明模式1的大小不會更改。

有人知道為什么嗎?

//////////////////////////////////////////////////
/* Resource File */
LTEXT           "This Is Normal Text.",IDC_FONT2,7,119,303,21,WS_BORDER
LTEXT           "This Include Transparent.",IDC_FONT,7,7,306,21,WS_BORDER | NOT WS_GROUP | WS_TABSTOP,WS_EX_TRANSPARENT


/* FontTest.CPP */
class CFontSizeDlg : public CDialogEx
{
public:
    CStatic m_myFont;
    CStatic m_myFont2;
}

/* FontTest.CPP */
void CFontSizeDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_FONT, m_myFont);
    DDX_Control(pDX, IDC_FONT2, m_myFont2);
}

void CFontSizeDlg::OnBnClickedButton2()
{
    CFont hNewFont;
    LOGFONT lf;                        // Used to create the CFont.

    CFont *currentFont = GetFont();
    currentFont->GetLogFont(&lf);
    lf.lfHeight = 25;
    lf.lfWidth = 10;

    hNewFont.DeleteObject();
    hNewFont.CreateFontIndirect(&lf);    // Create the font.

     // Use the font to paint a control.
    m_myFont2.SetFont(&hNewFont);
    m_myFont.SetFont(&hNewFont);

    // hNewFont.Detach(); // will create GDI leak
    hNewFont.DeleteObject();
}

您需要確保'new'字體的范圍與靜態控件的范圍相同。 在您的示例中,完成按鈕事件處理程序時會破壞字體。 嘗試將hNewFont設為成員變量並設置一次。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM