'以下是代碼,想得到的效果是坐標下面的字符在兩個刻度中間。
'現在問題是:1、不居中;2、在給的數>14以后,少一個字符;3、在給數18時,最左邊刻度畫不上。
Option Explicit
Private Sub Command1_Click()
Dim i As Single, MyValue As Single
Dim x(100000) As Double, y(1000000) As Double
Picture1.Cls
Picture1.AutoRedraw = True
Picture1.DrawWidth = 2
MyValue = InputBox("請輸入坐標刻度數:")
Picture1.Scale (-500, 3200)-(5200, -500) '//左上角的(X,Y),和右下角的(X,Y)
Picture1.Line (0, 0)-(5000, 0) '//畫X軸
Picture1.Line (0, 0)-(0, 3000) '//畫Y軸
Do
i = i + 5000 / MyValue
If i > 5000 Then Exit Do
x(i) = i
y(i) = 0
Picture1.Line (x(i), y(i) - 50)-(x(i), y(i)) '//畫X軸上的刻度
Picture1.CurrentX = i - (5000 / MyValue) / 2 - TextWidth("2012") / 2
Picture1.CurrentY = -50
Picture1.Print "2012"
Print i, TextWidth("2012"), i / 2 - TextWidth("2012") / 2
Loop
End Sub
uj5u.com熱心網友回復:
列印在 x1、x2之間劇中:currentx=(x1+x2-textwidth(s))/2
uj5u.com熱心網友回復:
Picture1.CurrentX = i - (5000 / MyValue) / 2 - TextWidth("2012") / 2
'上面省略了 TextWidth 的前綴,等于'
Picture1.CurrentX = i - (5000 / MyValue) / 2 - Me.TextWidth("2012") / 2
'但是 Picture1 用了自定義坐標,你用表單坐標單位計算的寬度根本和 Picture1 坐標下的寬度不一致。'
'正確的應該如下:'
Picture1.CurrentX = i - (5000 / MyValue) / 2 - Picture1.TextWidth("2012") / 2
uj5u.com熱心網友回復:
Tiger_Zhao我試了,還是不行,更不居中了啊。。。
我把全部代碼發到這,你試下。
Option Explicit
Private Sub Command1_Click()
Dim i As Single, MyValue As Single, PianYi As Single
Dim x(100000) As Double, y(1000000) As Double
Picture1.Cls
Picture1.AutoRedraw = True
Picture1.DrawWidth = 2
On Error GoTo 100
MyValue = InputBox("請輸入坐標刻度數:")
Picture1.FontSize = 18
Picture1.Scale (-500, 3200)-(5200, -800) '//左上角的(X,Y),和右下角的(X,Y)
Picture1.Line (0, 0)-(5000, 0) '//畫X軸
Picture1.Line (0, 0)-(0, 3000) '//畫Y軸
Picture1.Line (0, -100)-(0, 0) '//畫X軸第一個刻度
PianYi = 100
For i = 1 To MyValue
x(i) = i * 5000 / MyValue
y(i) = 0
Picture1.Line (x(i), y(i) - PianYi)-(x(i), y(i)) '//畫X軸上的刻度
Picture1.CurrentX = x(i) - (5000 / MyValue) / 2 - Picture1.TextWidth(i) / 2
Picture1.Print i
Print x(i), TextWidth(i), x(i) / 2 - TextWidth(i) / 2
Next i
100
End Sub
uj5u.com熱心網友回復:
'Picture1.Print i <- 列印數字時會加前綴空格,要用字串列印'
Picture1.Print CStr(i)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/153420.html
標籤:VB基礎類
上一篇:求助activereport的detail屬性怎么設定
下一篇:重復呼叫dos程式并寫入檔案名
