VC ++和C#中的字体区别是什么 [英] What is font difference in VC++ and C#
本文介绍了VC ++和C#中的字体区别是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用C#绘制简单文本
I draw simple text using C#
private void Form1_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Rectangle pRect = new Rectangle(126, 35, 182, 59);
StringFormat objStrFormat = new StringFormat();
objStrFormat.Alignment = StringAlignment.Center;
objStrFormat.LineAlignment = StringAlignment.Center;
e.Graphics.DrawRectangle(Pens.Black, pRect);
e.Graphics.FillRectangle(new SolidBrush(Color.DarkOrange), pRect);
Font pLOGFONT = new Font("Arial", 20, FontStyle.Bold);
e.Graphics.DrawString("Sample Text", pLOGFONT, new SolidBrush(Color.Black), pRect, objStrFormat);
}
与上面使用MFC的代码相同
Same as above code using MFC
CBrush* OldBrush;
CFont* OldFont=NULL;
CPen *OldPen=NULL;
CPen BClrPen;
CBrush BgBrush;
CFont m_TextFont;
CClientDC dc(this);
COLORREF rgb(RGB(0,0,0));
BClrPen.CreatePen(PS_SOLID,1,rgb);
OldPen=dc.SelectObject(&BClrPen);
BgBrush.CreateSolidBrush(RGB(123,150,0));
OldBrush=dc.SelectObject(&BgBrush);
dc.Rectangle(126,35,308,94);
dc.SelectObject(OldBrush);
dc.SelectObject(OldPen);
BClrPen.DeleteObject();
memset(&lf,0,sizeof(LOGFONT));
lf.lfHeight = 31;
lf.lfWidth = 20;//Need to set 14.5
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = 700;
lf.lfItalic = 0;
lf.lfUnderline = 0;
lf.lfStrikeOut = 0;
lf.lfCharSet = 1;
lf.lfOutPrecision = 0;
lf.lfClipPrecision = 0;
lf.lfQuality = 0;
lf.lfPitchAndFamily = 0;
lstrcpy(lf.lfFaceName, _T("Arial"));
m_TextFont.CreateFontIndirect(&lf);
dc.SetBkMode(TRANSPARENT);
COLORREF m_cBgColor(RGB(50,20,100));
dc.SetTextColor(m_cBgColor);
OldFont = dc.SelectObject(&m_TextFont);
dc.DrawText(_T("Sample Text"),11,CRect(126,35,308,94),DT_SINGLELINE | DT_CENTER | DT_VCENTER);
dc.SelectObject(OldFont);
在以上两种情况下,字体大小均设置为20,但在MFC中,字体看起来大于C#输出.唯一的区别是大小(宽度参数)在MFC中为逻辑像素,在C#中为Point.
那么,由于我在MFC中使用C#应用程序,如何将Point转换为逻辑像素或其他任何合适的方法?
In the above, in both cases the font size is set to 20 but in MFC font looks bigger than C# output. Got one difference is size (width parameter)is in logical pixel in MFC and Point in C#.
So how do I convert Point into logical pixel or any other suitable way because I am using C# application in MFC?
推荐答案
请确保字体规格相同
http://msdn.microsoft.com/en-us/library/dd145037 (v = vs.85).aspx [
make sure that font metrics are same
http://msdn.microsoft.com/en-us/library/dd145037(v=vs.85).aspx[^]
这篇关于VC ++和C#中的字体区别是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文