{"rsdb":{"rid":"179318","subhead":"","postdate":"0","aid":"130186","fid":"86","uid":"1","topic":"1","content":"
\n

\u6700\u8fd1\u5728\u505a\u4e00\u4e2aTStringGrid\u7684\u81ea\u7ed8\u5904\u7406\uff0c\u5728\u753b\u6587\u5b57\u5904\u7406\u4e0a\u9047\u5230\u4e86\u9ad8\u5ea6\u7684\u8ba1\u7b97\u95ee\u9898\u3002\u540e\u6765\u7ecf\u8fc7\u4e00\u6bb5\u65f6\u95f4\u8fd8\u662f\u627e\u5230\u4e86\u4e00\u4e9b\u65b9\u6cd5\uff1a<\/span><\/p> \n

 <\/span><\/p> \n

1\u3001\u4f7f\u7528TLabel<\/strong><\/span><\/h1> \n

\u3000\u3000\u8fd9\u4e2a\u65b9\u6cd5\u662f\u6709\u70b9\u7ed5\u8def\u7684\uff0c\u65b9\u6cd5\u5012\u662f\u7b80\u5355\uff0c\u5c31\u662f\u4f7f\u7528AutoSize\u5c5e\u4e8e\u6765\u5b8c\u6210\u3002\u3002<\/span><\/p> \n

2\u3001\u4f7f\u7528DrawText<\/strong><\/span><\/h1> \n

\u3000\u3000DrawText\u7684\u51fd\u6570\u5b9a\u4e49\uff1a<\/span><\/p> \n

\n

\u51fd\u6570\u539f\u578b<\/strong><\/span>
int DrawText(<\/span><\/p> \n

HDC hDC, \/\/ \u8bbe\u5907\u63cf\u8ff0\u8868\u53e5\u67c4<\/span><\/p> \n

LPCTSTR lpString, \/\/ \u5c06\u8981\u7ed8\u5236\u7684\u5b57\u7b26\u4e32<\/span><\/p> \n

int nCount, \/\/ \u5b57\u7b26\u4e32\u7684\u957f\u5ea6<\/span><\/p> \n

LPRECT lpRect, \/\/ \u6307\u5411\u77e9\u5f62\u7ed3\u6784RECT\u7684\u6307\u9488<\/span><\/p> \n

UINT uFormat \/\/ \u6b63\u6587\u7684\u7ed8\u5236\u9009\u9879<\/span><\/p> \n

);<\/span><\/p> \n

\u53c2\u6570<\/strong><\/span>
hdc\uff1a<\/span><\/p> \n

[\u8f93\u5165]\u8bbe\u5907\u73af\u5883\u53e5\u67c4\u3002<\/span><\/p> \n

lpString\uff1a<\/span><\/p> \n

[\u8f93\u5165]\u6307\u5411\u5c06\u88ab\u5199\u5165\u7684\u5b57\u7b26\u4e32\u7684\u6307\u9488\uff0c\u5982\u679c\u53c2\u6570nCount\u662f-1\uff0c\u5219\u5b57\u7b26\u4e32\u5fc5\u987b\u662f\u4ee5\\0\u7ed3\u675f\u7684\u3002 \u5982\u679cuFormat\u5305\u542bDT_MODIFYSTRING\uff0c\u5219\u51fd\u6570\u53ef\u4e3a\u6b64\u5b57\u7b26\u4e32\u589e\u52a04\u4e2a\u5b57\u7b26\uff0c\u5b58\u653e\u5b57\u7b26\u4e32\u7684\u7f13\u51b2\u533a\u5fc5\u987b\u8db3\u591f\u5927\uff0c\u80fd\u5bb9\u7eb3\u9644\u52a0\u7684\u5b57\u7b26\u3002<\/span><\/p> \n

nCount\uff1a<\/span><\/p> \n

[\u8f93\u5165]\u6307\u5411\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u6570\u3002\u5982\u679cnCount\u4e3a-1\uff0c\u5219lpString\u6307\u5411\u7684\u5b57\u7b26\u4e32\u88ab\u8ba4\u4e3a\u662f\u4ee5\\0\u7ed3\u675f\u7684\uff0cDrawText\u4f1a\u81ea\u52a8\u8ba1\u7b97\u5b57\u7b26\u6570\u3002<\/span><\/p> \n

lpRect\uff1a<\/span><\/p> \n

[\u8f93\u5165\/\u8f93\u51fa]\u6307\u5411\u7ed3\u6784RECT\u7684\u6307\u9488\uff0c\u5176\u4e2d\u5305\u542b\u6587\u672c\u5c06\u88ab\u7f6e\u4e8e\u5176\u4e2d\u7684\u77e9\u5f62\u7684\u4fe1\u606f\uff08\u6309\u903b\u8f91\u5750\u6807\uff09\u3002<\/span><\/p> \n

uFormat\uff1a<\/span><\/p> \n

[\u8f93\u5165]\u6307\u5b9a\u683c\u5f0f\u5316\u6587\u672c\u7684\u65b9\u6cd5\u3002\u5b83\u53ef\u4ee5\u4e0b\u5217\u503c\u7684\u4efb\u610f\u7ec4\u5408\uff0c\u5404\u503c\u63cf\u8ff0\u5982\u4e0b\uff1a<\/span><\/p> \n

DT_CALCRECT\uff1a\u8fd9\u4e2a\u53c2\u6570\u6bd4\u8f83\u91cd\u8981\uff0c\u53ef\u4ee5\u4f7fDrawText\u51fd\u6570\u8ba1\u7b97\u51fa\u8f93\u51fa\u6587\u672c\u7684\u5c3a\u5bf8\u3002\u5982\u679c\u8f93\u51fa\u6587\u672c\u6709\u591a\u884c\uff0cDrawText\u51fd\u6570\u4f7f\u7528lpRect\u5b9a\u4e49\u7684\u77e9\u5f62\u7684\u5bbd\u5ea6\uff0c\u5e76\u6269\u5c55\u77e9\u5f62\u7684\u5e95\u90e8\u4ee5\u5bb9\u7eb3\u8f93\u51fa\u6587\u672c\u7684\u6700\u540e\u4e00\u884c\u3002\u5982\u679c\u8f93\u51fa\u6587\u672c\u53ea\u6709\u4e00\u884c\uff0c\u5219DrawText\u51fd\u6570\u6539\u53d8\u77e9\u5f62\u7684\u53f3\u8fb9\u754c\uff0c\u4ee5\u5bb9\u7eb3\u4e0b\u6b63\u6587\u884c\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u3002\u51fa\u73b0\u4e0a\u8ff0\u4efb\u4f55\u4e00\u79cd\u60c5\u51b5\uff0cDrawText\u51fd\u6570\u5c06\u8fd4\u56de\u683c\u5f0f\u5316\u6587\u672c\u7684\u9ad8\u5ea6\uff0c\u800c\u4e0d\u662f\u7ed8\u5236\u6587\u672c\u3002<\/span><\/p> \n

DT_CENTER\uff1a\u6307\u5b9a\u6587\u672c\u6c34\u5e73\u5c45\u4e2d\u663e\u793a\u3002<\/span><\/p> \n

DT_VCENTER\uff1a\u6307\u5b9a\u6587\u672c\u5782\u76f4\u5c45\u4e2d\u663e\u793a\u3002\u8be5\u6807\u8bb0\u53ea\u5728\u5355\u884c\u6587\u672c\u8f93\u51fa\u65f6\u6709\u6548\uff0c\u6240\u4ee5\u5b83\u5fc5\u987b\u4e0eDT_SINGLELINE\u7ed3\u5408\u4f7f\u7528\u3002<\/span><\/p> \n

DT_SINGLELINE\uff1a\u5355\u884c\u663e\u793a\u6587\u672c\uff0c\u56de\u8f66\u548c\u6362\u884c\u7b26\u90fd\u4e0d\u65ad\u884c\u3002<\/span><\/p> \n <\/blockquote> \n

\u51fd\u6570\u91cc\u9762\u6700\u540e\u9762\u90a3\u6bb5\u84dd\u5b57\u6807\u793a\u7684\u5f88\u91cd\u8981\uff0cDT_CALCRECT\u5c31\u662f\u7528\u6765\u8ba1\u7b97\u6587\u672c\u5c3a\u5bf8\u7684\u54e6\u3002\u3002\u505a\u4e2a\u8bd5\u9a8c\u5427\uff1a<\/span><\/p> \n

 <\/span><\/p> \n

\n
procedure<\/span> TForm1.Button1Click(Sender: TObject); <\/span>var<\/span> sData: <\/span>string<\/span>; cellRect: TRect; <\/span>begin<\/span> cellRect.Left :<\/span>= 10<\/span>; cellRect.Top :<\/span>= 10<\/span>; cellRect.Right :<\/span>= 200<\/span>; cellRect.Bottom :<\/span>= 25<\/span>; sData :<\/span>= '<\/span>\u4e2d\u4e2d\u56fd\u56fd\u56fd \u5927<\/span>'<\/span>; DrawText(Canvas.Handle, PChar(sData), Length(sData), cellRect, DT_WORDBREAK <\/span>or<\/span> DT_CALCRECT); <\/span>end<\/span>;
\/\/\u6267\u884c\u540e\u6ca1\u6709\u5728\u754c\u9762\u4e0a\u753b\u6587\u672c <\/span><\/span>procedure<\/span> TForm1.Button2Click(Sender: TObject); <\/span>var<\/span> sData: <\/span>string<\/span>; cellRect: TRect; <\/span>begin<\/span> cellRect.Left :<\/span>= 10<\/span>; cellRect.Top :<\/span>= 10<\/span>; cellRect.Right :<\/span>= 200<\/span>; cellRect.Bottom :<\/span>= 25<\/span>; sData :<\/span>= '<\/span>\u4e2d\u4e2d\u56fd\u56fd\u56fd \u5927<\/span>'<\/span>; DrawText(Canvas.Handle, PChar(sData), Length(sData), cellRect, DT_WORDBREAK); <\/span>end<\/span>;<\/span>
\/\/\u6267\u884c\u540e\u5728\u754c\u9762\u4e0a\u663e\u793a\u4e00\u884c\u5b57<\/span><\/pre> \n <\/div> \n

 <\/p> \n

\u6ce8\u610f\u70b9\uff1a<\/span><\/strong><\/p> \n