有关用LOGFONT写文字的问题(100分)

  • 主题发起人 主题发起人 shaofun
  • 开始时间 开始时间
S

shaofun

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TTextForm.FormMouseDown(Sender: TObject; Button: TMouseButton;<br>Shift: TShiftState; X, Y: Integer);<br>var<br>&nbsp; m:LOGFONT;<br>&nbsp; hdc1:HDC;<br>&nbsp; N,O:HGDIOBJ;<br>begin<br>&nbsp; m.lfEscapement:=StrToInt(edit2.text)*10;<br>&nbsp; m.lfHeight:=11;<br>&nbsp; m.lfWidth:=0;<br>&nbsp; m.lfWeight:=400;<br>&nbsp; m.lfItalic:=0;<br>&nbsp; m.lfUnderline:=0;<br>&nbsp; m.lfStrikeOut:=0;<br>&nbsp; m.lfOutPrecision:=0;<br>&nbsp; m.lfClipPrecision:=0;<br>&nbsp; m.lfQuality:=0;<br>&nbsp; m.lfPitchAndFamily:=0;<br>&nbsp; m.lfCharSet:=0;<br>&nbsp; StrPLCopy(m.lfFaceName,'宋体',31);<br>&nbsp; hdc1:=GetDC(Self.Handle);<br>&nbsp; N:=CreateFontIndirect(m);<br>&nbsp; O:=SelectObject(hdc1,N);<br>&nbsp; SetBKMode(hdc1,TRANSPARENT);<br>&nbsp; TextOut(hdc1,X,Y,PChar(edit1.text),length(edit1.text));<br>&nbsp; N:=SelectObject(hdc1,O);<br>&nbsp; DeleteObject(N);<br>end;<br><br>利用上面的代码写的文字<br>1.m.lfHeight为11时文字仍为0度,可将其设为12后,文字角度就为设计角度了,不知为何?<br>2.StrPLCopy(m.lfFaceName,'宋体',31);这行不起作用,不知为何?<br>&nbsp;<br><br>&nbsp; <br>[回应主题] <br>[到上一篇] <br>[版主首页] <br>[返回上级] <br>[发新文章] <br>&nbsp;<br><br><br>&nbsp;<br>
 
1.lfHeight指定以逻辑单位标定的字体高度,取值可为正负或零,对于需要随意定义<br>&nbsp; 字体高度的情况下通常取负值,以保证获得实际尺寸的字体。<br>2.StrPLCopy(m.lfFaceName,'宋体'#0,31); 试试。
 
1.试过了,与正负无关<br>2.也试过了,没用
 
procedure TTextForm.FormMouseDown(Sender: TObject; Button: TMouseButton;<br>Shift: TShiftState; X, Y: Integer);<br>var<br>&nbsp; m:LOGFONT;<br>&nbsp; hdc1:HDC;<br>&nbsp; tf:TFont;<br>&nbsp; N,O:HGDIOBJ;<br>begin<br>&nbsp; hdc1:=GetDC(Self.Handle);<br>&nbsp; with Form1.canvas do<br>&nbsp; begin<br>&nbsp; &nbsp; Font.Name:='宋体';<br>&nbsp; &nbsp; Font.Height:=11;<br>&nbsp; &nbsp; tf:=TFont.Create;<br>&nbsp; &nbsp; tf.Assign(Font);<br>&nbsp; &nbsp; GetObject(tf.Handle,sizeof(m),@m);<br>&nbsp; &nbsp; m.lfEscapement:=StrToInt(edit2.text)*10;<br>&nbsp; &nbsp; m.lfWidth:=0;<br>&nbsp; &nbsp; m.lfWeight:=400;<br>&nbsp; &nbsp; m.lfItalic:=0;<br>&nbsp; &nbsp; m.lfUnderline:=0;<br>&nbsp; &nbsp; m.lfStrikeOut:=0;<br>&nbsp; &nbsp; m.lfOutPrecision:=0;<br>&nbsp; &nbsp; m.lfClipPrecision:=0;<br>&nbsp; &nbsp; m.lfQuality:=0;<br>&nbsp; &nbsp; m.lfPitchAndFamily:=0;<br>&nbsp; &nbsp; tf.Handle := CreateFontIndirect(m);<br>&nbsp; &nbsp; Font.Assign(tf);<br>&nbsp; &nbsp; tf.Free;<br>&nbsp; end;<br>&nbsp; N:=CreateFontIndirect(m);<br>&nbsp; O:=SelectObject(hdc1,N);<br>&nbsp; SetBKMode(hdc1,TRANSPARENT);<br>&nbsp; TextOut(hdc1,X,Y,PChar(edit1.text),length(edit1.text));<br>&nbsp; N:=SelectObject(hdc1,O);<br>&nbsp; DeleteObject(N);<br>end;<br><br>按以上代码运行,事情解决了,可原先代码的问题到底出在哪儿还没搞清楚。
 
1.不明白<br>2.应该是 StrPLCopy(@m.lfFaceName,'宋体',31);
 
还有LOGFONT的字体颜色如何设定?
 
字体颜色应该是由 Device Context 决定的,使用 SetTextColor 这个 API 函数。如:<br>SetTextColor(Canvas.Handle, ColorToRGB(clRed));
 
我程序中用了Font对话框后用:<br>&nbsp; with FLogFont do begin<br>&nbsp; &nbsp; &nbsp; lfHeight:=Font.Height;<br>&nbsp; &nbsp; &nbsp; ......<br>&nbsp; &nbsp; &nbsp; lfFaceName:='宋体';<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;就行了。<br>但我对lfFaceName的动态改变不知道如何是好。<br>
 
多人接受答案了。
 
后退
顶部