求VB6下绘制一个图片的方法,要求有鼠标移入移出事件和点击事件,我对VB不大熟悉,但是这个事情又很紧急,希望大家伸出援手,多谢,多谢!

解决方案 »

  1.   

    我来贴代码,历经寒苦啊!5年多不碰这个VB6玩意了,好多东西搞不定了。111.bmp 和 112.bmp 是两个图片文件,表示按钮正常和鼠标在按钮上的状态。
    VERSION 5.00
    Begin VB.Form Form1 
       Caption         =   "Form1"
       ClientHeight    =   3090
       ClientLeft      =   60
       ClientTop       =   450
       ClientWidth     =   4680
       LinkTopic       =   "Form1"
       ScaleHeight     =   3090
       ScaleWidth      =   4680
       StartUpPosition =   3  '窗口缺省
       Begin VB.Image Image3 
          Height          =   1215
          Left            =   1560
          Top             =   1680
          Width           =   2655
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = FalseDim pic1 As StdPicture, pic2 As StdPictureDim btnLeft As Single, btnTop As Single
    Dim btnRight As Single, btnBottom As SingleDim inButton As Boolean, last As BooleanPrivate Sub Form_Load()
        
        Set pic1 = LoadPicture(App.Path + "\111.bmp")
        Set pic2 = LoadPicture(App.Path + "\112.bmp")
        btnLeft = 150: btnTop = 150
        ' 亮点在这里啊!不使用 ScaleX 和 ScaleY 计算得到的长度就是有问题的。
        btnRight = ScaleX(pic1.Width, vbHimetric, vbPixels) * 15 + btnLeft
        btnBottom = btnTop + ScaleY(pic1.Height, vbHimetric, vbPixels) * 15
        
        inButton = False: last = inButton
        
        Image3.Picture = pic1
        MsgBox Image3.Picture.Width & " x " & Image3.Picture.Height & vbNewLine & _
            Image3.Width & " x " & Image3.Height
        
    End SubPrivate Function IsMouseInButton(X As Single, Y As Single) As Boolean
        IsMouseInButton = (X <= btnRight And X >= btnLeft) And (Y <= btnBottom And Y >= btnTop)
    End FunctionPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Debug.Print "x: " & X & " y: " & Y & " Button: " & Button
        inButton = IsMouseInButton(X, Y)
        If inButton <> last Then
            Me.Refresh
            Debug.Print "InButton: " & inButton & ", last: " & last
        End If
        last = inButton
    End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If inButton Then
            MsgBox ("button clicked.")
        End If
    End SubPrivate Sub Form_Paint()
        If inButton Then
            PaintPicture pic2, btnLeft, btnTop
        Else
            PaintPicture pic1, btnLeft, btnTop
        End If
    End Sub
      

  2.   

    看绘图API,例子太多,不知你具体什么情况,自己搜吧。