在form上指定位置写字???在线等待,来者有分,信誉之上!

happydou 2003-09-04 04:49:28
1、如何在form上指定位置写字?例如在坐标为(100,100)的位置显示hello
2、当form画的线段变化后,原来的线段更新掉,显示当前的图画
不清楚的地方,我在线回答
...全文
66 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gelim 2003-09-04
  • 打赏
  • 举报
回复
放在moduel:

Option Explicit

Public Const DT_BOTTOM = &H8
Public Const DT_CALCRECT = &H400
Public Const DT_CENTER = &H1
Public Const DT_EXPANDTABS = &H40
Public Const DT_EXTERNALLEADING = &H200
Public Const DT_LEFT = &H0
Public Const DT_NOCLIP = &H100
Public Const DT_NOPREFIX = &H800
Public Const DT_RIGHT = &H2
Public Const DT_SINGLELINE = &H20
Public Const DT_TABSTOP = &H80
Public Const DT_TOP = &H0
Public Const DT_VCENTER = &H4
Public Const DT_WORDBREAK = &H10

Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Type SIZE
cx As Long
cy As Long
End Type

Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
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
Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hDC As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As SIZE) As Long


放在form:
Option Explicit

Const LongStr = "Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text."

Private Sub Command1_Click()
Dim r As RECT, s As SIZE

r.Left = 50: r.Top = 20
DrawText Me.hDC, "Draw Text Test", 14, r, DT_CALCRECT
Line (r.Left, r.Top)-(r.Right, r.Bottom), RGB(255, 255, 0), BF
DrawText Me.hDC, "Draw Text Test", 14, r, 0

r.Left = 50: r.Top = 50: r.Right = 300
DrawText Me.hDC, LongStr, Len(LongStr), r, DT_CALCRECT Or DT_WORDBREAK
Line (r.Left, r.Top)-(r.Right, r.Bottom), RGB(255, 255, 0), BF
DrawText Me.hDC, LongStr, Len(LongStr), r, DT_WORDBREAK
End Sub

Gelim 2003-09-04
  • 打赏
  • 举报
回复
使用drawtext或textout


LeoUltraman 2003-09-04
  • 打赏
  • 举报
回复
所谓英雄所见略同
呵呵
可以散分了楼主
LeoUltraman 2003-09-04
  • 打赏
  • 举报
回复
(1)form.CurrentX=100
form.CurrentY=100
form.Print "hello"
(2)form.cls
call DrawLine()
射天狼 2003-09-04
  • 打赏
  • 举报
回复
1.
form1.Currentx = 100
form1.Currenty = 100
form1.print "hello"

2.
form1.cls(不知是不是这样,没太明白)

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧