毛毛 asked in 電腦與網際網路軟體 · 1 decade ago

VB按右鍵視窗變小 左鍵變大的程式碼非常急!!

按右鍵視窗變小 左鍵變大

按右鍵視窗變小 左鍵變大

按右鍵視窗變小 左鍵變大

非常急!!

2 Answers

Rating
  • 1 decade ago
    Favorite Answer

    由於你沒說是什麼視窗,所以將兩種情況提出

    表單視窗(Form):

    Option Explicit

    Dim ButtonDb As Integer 'ButtonDb用來紀錄滑鼠是按下左鍵或右鍵

    Const ZoomSizeX = 500 '寬度的縮放量,可自行更改

    Const ZoomSizeY = 500 '高度的縮放量,可自行更改

    Private Sub Form_DblClick() '表單滑鼠雙擊事件

    If (ButtonDb = 1) Then '按下左鍵時

    Me.Width = Me.Width ZoomSizeX '寬度變大

    Me.Height = Me.Height ZoomSizeY '高度變大

    ElseIf (ButtonDb = 2) Then '按下右鍵時

    Me.Width = Me.Width - ZoomSizeX '寬度變小

    Me.Height = Me.Height - ZoomSizeY '高度變小

    End If

    End Sub

    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    '表單滑鼠單擊事件

    ButtonDb = Button '紀錄滑鼠是按下左鍵或右鍵

    If (Button = 1) Then '按下左鍵時

    Me.Width = Me.Width ZoomSizeX '寬度變大

    Me.Height = Me.Height ZoomSizeY '高度變大

    ElseIf (Button = 2) Then

    Me.Width = Me.Width - ZoomSizeX '寬度變小

    Me.Height = Me.Height - ZoomSizeY '高度變小

    End If

    End Sub

    圖片視窗(Picture):

    '基本上跟表單視窗一樣

    '只是對象改成Picture1

    Option Explicit

    Dim ButtonDb As Integer

    Const ZoomSizeX = 500

    Const ZoomSizeY = 500

    Private Sub Picture1_DblClick()

    If (ButtonDb = 1) Then

    Picture1.Width = Picture1.Width ZoomSizeX

    Picture1.Height = Picture1.Height ZoomSizeY

    ElseIf (ButtonDb = 2) Then

    Picture1.Width = Picture1.Width - ZoomSizeX

    Picture1.Height = Picture1.Height - ZoomSizeY

    End If

    End Sub

    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    ButtonDb = Button

    If (Button = 1) Then

    Picture1.Width = Picture1.Width ZoomSizeX

    Picture1.Height = Picture1.Height ZoomSizeY

    ElseIf (Button = 2) Then

    Picture1.Width = Picture1.Width - ZoomSizeX

    Picture1.Height = Picture1.Height - ZoomSizeY

    End If

    End Sub

    Source(s): Me
  • Anonymous
    6 years ago

    到下面的網址看看吧

    ▶▶http://*****/

Still have questions? Get your answers by asking now.