我需要将文字输出到PIC1的中央
却发现总是超出了边界
下面的代码,我总是找不到错误的原因,,,请帮助*************************************
Pic1.ScaleMode = 3  
Pic1.FontSize = 72
tmidx = (Pic1.Width / 2) - (Pic1.TextWidth("asd") / 2)
tmidy = (Pic1.Height / 2) - (Pic1.TextHeight("asd") / 2)
Pic1.CurrentX = tmidx 
Pic1.CurrentY = tmidy
Pic1.Print "asd"

解决方案 »

  1.   

    Pic1.Width ---->Pic1.ScaleWidth
    Pic1.Height --->Pic1.ScaleHeight
    要注意ScaleWidth和width的区别
      

  2.   

    忘了说明我ScaleWidth和width是一样的,,没有变化,是固定的窗口
      

  3.   

    api方法Public Function NumbersOnly(tBox As TextBox)
    Dim DefaultStyle As Long
    DefaultStyle = GetWindowLong(tBox.hWnd, GWL_STYLE)
    NumbersOnly = SetWindowLong(tBox.hWnd, GWL_STYLE, DefaultStyle Or ES_NUMBER)
    End Function
      

  4.   

    对不起,发错地方了你把'Pic1.ScaleMode = 注释掉试试
      

  5.   

    如果你设定了Pic1.ScaleMode
    还是那句话
    请用
    Pic1.Width ---->Pic1.ScaleWidth
    Pic1.Height --->Pic1.ScaleHeight
    你实际验证一下就明白了
      

  6.   

    使用 API 方法:Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End TypePrivate Const DT_CALCRECT = &H400Private 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 LongPrivate Sub Picture1_Click()
        Dim lp As RECT
        
        Picture1.FontSize = 72
        Picture1.ScaleMode = 3
        
        DrawText Picture1.hdc, "ASD", 3, lp, DT_CALCRECT
        
        Picture1.CurrentX = (Picture1.ScaleWidth - lp.Right) / 2
        Picture1.CurrentY = (Picture1.ScaleHeight - lp.Bottom) / 2
        
        Picture1.Print "ASD"
    End Sub
      

  7.   

    谢谢 ch21st(风尘鸟) ( ) 
    我可以明天给分吗?今天再继续讨论一下这个问题我想这个简单错误的产生应该是有原因的是不是,,,,在我设定了Pic1.ScaleMode后
    控件内的坐标系发生了变化而WIDTH中保存的还是老的坐标系
      

  8.   

    Pic1.ScaleMode设定为3-pixel后,width,height都以pixel(像素)为单位了.默认那个单位叫什么来着,1pixel=15那个单位.
    你这样设置当然有问题.