概述
MFC text控件字体大小颜色
#include "ZCStatic.h"
ZCStatic m_RESULT_B;
m_RESULT_B.SetFontSize(300, _T("宋体"));
m_RESULT_B.SetTextColor(RGB(0x00, 0xFF, 0x00));
m_RESULT_B.SetWindowTextW(L"内容");
ZCStatic.cpp
#include "StdAfx.h"
#include "ZCStatic.h"
ZCStatic::ZCStatic(void)
{
m_crBackColor = RGB(240,240,240);
m_crText = RGB(0,0,0);
//m_font.CreateFont(50,50,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"));//创建字体
m_font.CreatePointFont(200,_T("宋体"),NULL);
m_bTran = true;
}
ZCStatic::~ZCStatic(void)
{
}
BEGIN_MESSAGE_MAP(ZCStatic, CStatic)
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
HBRUSH ZCStatic::CtlColor(CDC* pDC, UINT nCtlColor)
{
if (CTLCOLOR_STATIC == nCtlColor)
{
m_hBrush.DeleteObject();
m_hBrush.CreateSolidBrush(m_crBackColor);
pDC->SelectObject(&m_font);
pDC->SetTextColor(m_crText);
pDC->SetBkColor(m_crBackColor);
if (m_bTran == true)
pDC->SetBkMode(TRANSPARENT);
}
return m_hBrush ;
//return (HBRUSH)::GetStockObject(NULL_BRUSH);
//return NULL;
}
void ZCStatic::SetTextColor( COLORREF crText )
{
m_crText = crText;
RedrawWindow();
}
void ZCStatic::SetFontSize(int nSize,CString fonttype)
{
//nSize *= -1;
//m_lf.lfHeight = nSize;
m_font.DeleteObject();
//m_font.CreateFontIndirect(&m_lf);
m_font.CreatePointFont(nSize,fonttype);
RedrawWindow();
}
void ZCStatic::SetBackColor(COLORREF crBackColor)
{
//m_hBrush.DeleteObject();
//m_hBrush.CreateSolidBrush(crBackColor);
m_crBackColor = crBackColor;
RedrawWindow();
}
void ZCStatic::SetTransparent(bool bTran)
{
m_bTran = bTran;
RedrawWindow();
}
ZCStatic.h
#pragma once
#include "afxwin.h"
class ZCStatic :
public CStatic
{
public:
ZCStatic(void);
~ZCStatic(void);
protected:
public:
DECLARE_MESSAGE_MAP()
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
public:
void SetTextColor( COLORREF crText );
void SetFontSize(int nSize,CString fonttype);
void SetBackColor(COLORREF crBackColor);
void SetTransparent(bool bTran) ;
COLORREF m_crText; // 字体颜色
COLORREF m_crBackColor; // 背景颜色
CBrush m_hBrush; // 画刷
//HBRUSH m_hBrush; // 画刷
LOGFONT m_lf; // 字体大小
CFont m_font; // 字体
bool m_bTran; // 是否透明
};
最后
以上就是瘦瘦毛衣为你收集整理的MFC text控件字体大小颜色的全部内容,希望文章能够帮你解决MFC text控件字体大小颜色所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复