setting the font of the view in the doc/ view architecture
-
i have a program done using the doc/view architecture. i want to change the font of whatever text i display in the view but am unable to figure out how to do so and in which member function of CView such as OnDraw, OnUpdate, etc?:confused:
Hi, In the OnDraw function you can select a new font into the DC and do all your drawing(text) and it will be in that font. CTestView::OnDraw(CDC *pDC) { CFont NewFont; NewFont.Create(Specify Parameters); CFont *pOldFont = pDC->SelectObject(&NewFont); // Draw your text // Select old font back pDC->SelectObject(pOldFont); } Hope it helps Vikash Parida
-
Hi, In the OnDraw function you can select a new font into the DC and do all your drawing(text) and it will be in that font. CTestView::OnDraw(CDC *pDC) { CFont NewFont; NewFont.Create(Specify Parameters); CFont *pOldFont = pDC->SelectObject(&NewFont); // Draw your text // Select old font back pDC->SelectObject(pOldFont); } Hope it helps Vikash Parida
or are you on about controls in your view, e.g. CEdit's and CStatics ??? If so, then create a CFont object member in your view e.g. in OnInitialUpdate
// m\_fntStyle1 is a CFont member of the view m\_fntStyle1.CreateFont(42, 0, 0, 0, FW\_BOLD, TRUE, FALSE,0,0,0,0,0,0, "Times New Roman"); m\_staticField1.SetFont(&m\_fntStyle1); m\_staticField2.SetFont(&m\_fntStyle1); m\_staticField3.SetFont(&m\_fntStyle1); // etc
The link to MSDN for CreateFont Hope this helps, Andy
-
Hi, In the OnDraw function you can select a new font into the DC and do all your drawing(text) and it will be in that font. CTestView::OnDraw(CDC *pDC) { CFont NewFont; NewFont.Create(Specify Parameters); CFont *pOldFont = pDC->SelectObject(&NewFont); // Draw your text // Select old font back pDC->SelectObject(pOldFont); } Hope it helps Vikash Parida
-
Hi, In the OnDraw function you can select a new font into the DC and do all your drawing(text) and it will be in that font. CTestView::OnDraw(CDC *pDC) { CFont NewFont; NewFont.Create(Specify Parameters); CFont *pOldFont = pDC->SelectObject(&NewFont); // Draw your text // Select old font back pDC->SelectObject(pOldFont); } Hope it helps Vikash Parida
hi, i tried to do as u told but the font does not change. CFont Font; CFont* pOldFont; LOGFONT lgFont; CTextFormatterDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); lgFont.lfHeight = -19; lgFont.lfWidth = 0; lgFont.lfWeight = FW_BOLD; lgFont.lfItalic = TRUE; lgFont.lfStrikeOut = TRUE; lgFont.lfUnderline = TRUE; lgFont.lfCharSet = ANSI_CHARSET; lgFont.lfOutPrecision = OUT_CHARACTER_PRECIS; lgFont.lfQuality = DEFAULT_QUALITY; strcpy(lgFont.lfFaceName, ""); Font.CreateFontIndirect(&lgFont); pOldFont = pDC->SelectObject(&Font); pDC->TextOut(0, 0, pDoc->GetText()); pDC->SelectObject(pOldFont); Font.DeleteObject();
-
hi, i tried to do as u told but the font does not change. CFont Font; CFont* pOldFont; LOGFONT lgFont; CTextFormatterDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); lgFont.lfHeight = -19; lgFont.lfWidth = 0; lgFont.lfWeight = FW_BOLD; lgFont.lfItalic = TRUE; lgFont.lfStrikeOut = TRUE; lgFont.lfUnderline = TRUE; lgFont.lfCharSet = ANSI_CHARSET; lgFont.lfOutPrecision = OUT_CHARACTER_PRECIS; lgFont.lfQuality = DEFAULT_QUALITY; strcpy(lgFont.lfFaceName, ""); Font.CreateFontIndirect(&lgFont); pOldFont = pDC->SelectObject(&Font); pDC->TextOut(0, 0, pDoc->GetText()); pDC->SelectObject(pOldFont); Font.DeleteObject();
maxsteel wrote: strcpy(lgFont.lfFaceName, ""); You need to give the name of the font ("Tahoma", "Times New Roman" etc...)
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"