【问题标题】:Change Edit Box Properties at Runtime in MFC在 MFC 中运行时更改编辑框属性
【发布时间】:2013-02-18 11:01:43
【问题描述】:

在我的应用程序中,我必须在运行时更改编辑框的字体、字体大小、背景颜色属性。当用户选择特定字体时,它的颜色应该会更新并在编辑框中可见。我正在尝试通过使用 CColorDialog 、 CFontDialog 来做到这一点。有什么有效的方法吗???我可以使用 Visual Studio 环境中的属性栏来更改设置,我们曾经在开发环境中更改属性。

【问题讨论】:

    标签: c++ visual-studio-2008 visual-c++ mfc


    【解决方案1】:

    您可以在以 CEdit 作为父类的类中捕获 WM_CTLCOLOR 消息,然后将 CDC 对象更改为您的内容。
    例如:

    HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor) 
    {
        HBRUSH hBrush;
        hBrush = (HBRUSH)m_myBrush; // An handle on a brush which was created with your background color for the edit
        pDC->SetBkColor(RGB(0, 0, 0)); // Color for the text background
        pDC->SetTextColor(RGB(255, 255, 255)); // Color for the text
    
        // More changes on the pDC like changing the font, etc...
        return hBrush;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多