使用delphiwinapi绘图字符串

使用delphiwinapi绘图字符串,delphi,drawstring,Delphi,Drawstring,我正在为delphi使用WinAPI。 我花了几个小时尝试了拉丝程序,但仍然无法正确执行。 Delphi keep给我的信息是“没有可以通过这些参数调用的“DrawString”的重载版本”。 我试过在表单和自定义面板上写消息 uses WinApi.Windows, WinApi.Messages, System.SysUtils, System.Classes, Vcl.Dialogs, System.DateUtils, WinApi.GDIPApi, WinApi.GDIPObj, Vc

我正在为delphi使用WinAPI。 我花了几个小时尝试了拉丝程序,但仍然无法正确执行。 Delphi keep给我的信息是“没有可以通过这些参数调用的“DrawString”的重载版本”。 我试过在表单和自定义面板上写消息

uses
WinApi.Windows, WinApi.Messages, System.SysUtils, System.Classes, Vcl.Dialogs,
System.DateUtils,
WinApi.GDIPApi,
WinApi.GDIPObj,
Vcl.Forms, Vcl.Controls, Vcl.Graphics,
dxSkinsCore, dxSkinsDefaultPainters, cxGraphics, cxControls, cxLookAndFeels,
cxLookAndFeelPainters, cxContainer, cxEdit, cxGroupBox, cxCheckGroup,
Data.DB, SHIS.Dataset, Datasnap.DBClient, cxTextEdit, cxDBEdit,
cxImageComboBox, Vcl.Menus, cxCheckBox, Vcl.StdCtrls,
cxMaskEdit, cxDropDownEdit,
cxCheckComboBox, SHIS.Editor, cxButtons, SHIS.Ctrl, SHIS.ExtCommCdControl;

type
 TCommCdF = class(TForm)
 btn4: TButton;
 procedure btn4Click(Sender: TObject);
private
protected
public
 constructor Create(AOwner: TComponent); override;
 destructor Destroy; override;

procedure InitParams; override;
end;

implementation

{$R *.dfm}

uses

procedure TCommCdF.btn4Click(Sender: TObject);
 var
 testgraphics : TGPGraphics;
 testPen : TGPPen;
 testBrush : TGPSolidBrush;
 testFont : TGPFont;
 testFontFamily : TGPFontFamily;
begin
 testgraphics := TGPGraphics.Create(SElf.Handle);
 testPen := TGPPen.Create(aclBlack);
 testFontFamily := TGPFontFamily.Create('Arial');
//  testFont := TGPFont.Create(testFontFamily, 12, FontStyleBold, UnitPixel);
 testFont := TGPFont.Create('Arial', 20);
 testBrush := TGPSolidBrush.Create(aclBlack);

//  testgraphics.DrawString('Hello', 5, testFont, MakeRect(0,0,50,50),testBrush);
//  testgraphics.DrawString('Hello Finally', testFont,  MakePoint(0, 0),  testBrush);
end;

好的,查看DrawString的声明并计算出在第一次尝试中需要传递的内容。当使用
layoutRect
调用重载时,您缺少
stringFormat
参数。在第二个示例中,您将
length
参数与
font
不匹配。在这两种情况下,您都需要生成浮点结构变量,因此常量应该包含浮点值。您必须使用画布的句柄,而不是表单的句柄
testgraphics:=TGPGraphics.Create(Canvas.Handle)
code-Insight可以帮助您解决这个问题。取消对
testGraphics.DrawString
的其中一个调用的注释,将编辑器光标放在左括号后面(在
'Hello'
之前),然后键入Ctrl+Shift+Space。当您向右箭头指向每个参数时,工具提示窗口中的粗体高亮显示将更改,以显示您正在使用的参数及其预期接收的参数。