設定字型高度 c++ vc MFC

來源:互聯網
上載者:User

【一】樣本一

以下代碼是放在對話方塊類的OnInitDialog中,注意m_font是類成員函數,否則會因為局部變數失效的原因,而導致SetFont出現問題。

 

CFont* pfont = m_e2.GetFont();//CEdit m_e2;<br />ASSERT(NULL != pfont);<br />LOGFONT lf;<br />int nret = pfont->GetLogFont(&lf);<br />ASSERT(0 != nret);<br />lf.lfHeight=-60; //設定高度<br /> m_font.CreateFontIndirect(&lf); //CFont m_font; 是類成員函數<br />m_e2.SetFont(&m_font);

【二】樣本二

此例只改變字型高度,字型寬度不變。

void CMy3455dlgDlg::OnButton1()<br />{</p><p>CClientDC dc(this);<br />LOGFONT LogFont;<br />CFont objFont; </p><p>dc.GetCurrentFont()->GetLogFont(&LogFont);<br />LogFont.lfHeight *= 2; //字型擴大一倍<br />//LogFont.lfWidth = 0; //注意:如果加上此句,字型寬度會根據字型高度改變,保持字型的比例。<br />LogFont.lfQuality = DRAFT_QUALITY;</p><p>objFont.CreateFontIndirect(&LogFont);<br />dc.SelectObject(objFont); </p><p>dc.TextOut(0, 0, TEXT("中國"), 4);<br />}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.