VBA或VB 使用 DrawText API 在窗體上繪制文本
- 2020-04-22 08:00:00
- zstmtony 原創(chuàng)
- 4109
Product(s): Microsoft Visual Basic for Windows
Version(s): WINDOWS:4.0
Operating System(s):
Keyword(s): kbprogramming kbVBp400 kb32bitOnly
Last Modified: 11-JAN-2001
-------------------------------------------------------------------------------
The information in this article applies to:
- Microsoft Visual Basic Standard Edition, 32-bit, for Windows, version 4.0
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows, version 4.0
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows, version 4.0
-------------------------------------------------------------------------------
SUMMARY
=======
The DrawText API gives users the ability to write text to a Device context
giving various alignment and word-wrapping features. This article provides a
code sample showing how to achieve these effects under the 32-bit Edition of
Visual Basic 4.0.
MORE INFORMATION
================
1. Start a new project in Visual Basic. Form1 is created by default.
2. Add a Command button to Form1.
3. Place the following code in the General Declarations section of Form1:
Option Explicit
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" _
(ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, _
lpRect As RECT, ByVal wFormat As Long) As Long
Private Const DT_BOTTOM = &H8
Private Const DT_CENTER = &H1
Private Const DT_LEFT = &H0
Private Const DT_RIGHT = &H2
Private Const DT_TOP = &H0
Private Const DT_VCENTER = &H4
Private Const DT_WORDBREAK = &H10
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Command1_Click()
Dim lSuccess As Long
Dim sPrintText As String
Dim MyRect As RECT
Form1.Font.Size = 12
Form1.ScaleMode = vbPixels
MyRect.Left = 0
MyRect.Right = Form1.ScaleWidth
MyRect.Top = 20
MyRect.Bottom = 60
sPrintText = "Print this text"
lSuccess = DrawText(Form1.hdc, sPrintText, Len(sPrintText), _
MyRect, DT_CENTER or DT_WORDBREAK)
End Sub
4. Press the F5 key to run the project, and press the Command button. Text
should appear in the middle of the form and be word-wrapped. If you Resize
the form and run the project again, you will note that the text still appears
in the middle of the form on the horizontal axis.
Following is a list of all the constants that can be used with the DrawText API
to give the various effects documented in the Win32 SDK:
Global Const DT_TOP = &H00000000
Global Const DT_LEFT = &H00000000
Global Const DT_CENTER = &H00000001
Global Const DT_RIGHT = &H00000002
Global Const DT_VCENTER = &H00000004
Global Const DT_BOTTOM = &H00000008
Global Const DT_WORDBREAK = &H00000010
Global Const DT_SINGLELINE = &H00000020
Global Const DT_EXPANDTABS = &H00000040
Global Const DT_TABSTOP = &H00000080
Global Const DT_NOCLIP = &H00000100
Global Const DT_EXTERNALLEADING = &H00000200
Global Const DT_CALCRECT = &H00000400
Global Const DT_NOPREFIX = &H00000800
Global Const DT_INTERNAL = &H00001000
Global Const DT_EDITCONTROL = &H00002000
Global Const DT_PATH_ELLIPSIS = &H00004000
Global Const DT_END_ELLIPSIS = &H00008000
Global Const DT_MODIFYSTRING = &H00010000
Global Const DT_RTLREADING = &H00020000
Global Const DT_WORD_ELLIPSIS = &H00040000
REFERENCES
==========
The Win32 SDK has a comprehensive summary of Drawtext and other Drawing and Text
functions.
Additional query words:
======================================================================
Keywords : kbprogramming kbVBp400 kb32bitOnly
Technology : kbVBSearch kbAudDeveloper kbVB400Search kbVB400
Version : WINDOWS:4.0
Issue type : kbhowto
=============================================================================
分享
Access數(shù)據(jù)庫(kù)自身
- office課程播放地址及課程明細(xì)
- Excel Word PPT Access VBA等Office技巧學(xué)習(xí)平臺(tái)
- 將( .accdb) 文件格式數(shù)據(jù)庫(kù)轉(zhuǎn)換為早期版本(.mdb)的文件格式
- 將早期的數(shù)據(jù)庫(kù)文件格式(.mdb)轉(zhuǎn)換為 (.accdb) 文件格式
- KB5002984:配置 Jet Red Database Engine 數(shù)據(jù)庫(kù)引擎和訪問(wèn)連接引擎以阻止對(duì)遠(yuǎn)程數(shù)據(jù)庫(kù)的訪問(wèn)(remote table)
- Access 365 /Access 2019 數(shù)據(jù)庫(kù)中哪些函數(shù)功能和屬性被沙箱模式阻止(如未啟動(dòng)宏時(shí))
- Access Runtime(運(yùn)行時(shí))最全的下載(2007 2010 2013 2016 2019 Access 365)
Access VBA函數(shù)模塊
- access vba代碼太長(zhǎng),換行,分行的寫(xiě)法
- VB6 VBA Access真正可用并且完美支持中英文的 URLEncode 與 URLDecode 函數(shù)源碼
- 自定義VB中的urlencode函數(shù),將URL中特殊部分進(jìn)行編碼
- Access 函數(shù)簡(jiǎn)化串接sql字符串,減少符號(hào)導(dǎo)致的書(shū)寫(xiě)錯(cuò)誤
- vba完全關(guān)閉IE瀏覽器及調(diào)用IE瀏覽器的簡(jiǎn)單應(yīng)用
- 利用FollowHyperlink方法打開(kāi)超鏈接提示“無(wú)法下載您要求的信息”的解決方案
- 在access中用代碼打開(kāi)文本框中超鏈接地址
Access Activex第三方控件
- Activex控件或Dll 在某些電腦無(wú)法正常注冊(cè)的解決辦法(regsvr32注冊(cè)時(shí)卡住)
- office使用部分控件時(shí)提示“您沒(méi)有使用該ActiveX控件許可的問(wèn)題”的解決方法
- RTF文件(富文本格式)的一些解析
- Access樹(shù)控件(treeview) 64位Office下出現(xiàn)橫向滾動(dòng)條不會(huì)自動(dòng)定位的解決辦法
- Access中國(guó)樹(shù)控件 在win10電腦 節(jié)點(diǎn)行間距太小的解決辦法
- EXCEL 2019 64位版(Office 2019 64位)早就支持64位Treeview 樹(shù)控件 ListView列表等64位MSCOMMCTL.OCX控件下載
- VBA或VB6調(diào)用WebService(直接Post方式)并解析返回的XML
Access ADP Sql Server等
- 早期PB程序連接Sqlserver出現(xiàn)錯(cuò)誤
- MMC 不能打開(kāi)文件C:/Program Files/Microsoft SQL Server/80/Tools/Binn/SQL Server Enterprise Manager.MSC 可能是由于文件不存在,不是一個(gè)MMC控制臺(tái),或者用后來(lái)的MMC版
- sql server連接不了的解決辦法
- localhost與127.0.0.1區(qū)別
- Roych的淺談數(shù)據(jù)庫(kù)開(kāi)發(fā)系列(Sql Server)
- sqlserver 自動(dòng)備份對(duì)備份目錄沒(méi)有存取權(quán)限的解決辦法
- 安裝Sql server 2005 express 和SQLServer2005 Express版企業(yè)管理器 SQLServer2005_SSMSEE
Access 行業(yè)應(yīng)用開(kāi)發(fā)
- 金蝶KIS旗艦版 登錄時(shí)“類(lèi)型不匹配”
- access行業(yè)交流QQ群-部分行業(yè)交流群(倉(cāng)庫(kù) 人事 工資 考勤 CRM HRM MRP ERP 等)
- access垃圾分類(lèi)數(shù)據(jù)庫(kù)
- Office提高企業(yè)辦公管理效率
- Access交流網(wǎng)Acccess通用開(kāi)發(fā)平臺(tái)樹(shù)導(dǎo)航出錯(cuò)的解決辦法
- Access交流網(wǎng)Access通用開(kāi)發(fā)平臺(tái)的使用幫助教程及FAQ
- Access采購(gòu)倉(cāng)庫(kù)系統(tǒng)作品源代碼
文章分類(lèi)
聯(lián)系我們
聯(lián)系人: | 王先生 |
---|---|
Email: | 18449932@qq.com |
QQ: | 18449932 |
微博: | officecn01 |