ҡդӶ ʵŧ 纺촨շ٨絴͵ ᷹ФѺ

͵Դҷҧ Inbox Ѻ

˹ѡ
-
VB 6/VB.Net
ASP/ASP.Net
Ѻ¤
¹ҹ Flash Movie
ռͺش  
 RSS Feeds
 ǹŴ RSS Reader ...   Download  RSS Reader

Forum - www.g2gnet.com
Webmaster - www.g2gnet.com
Visitors - Session views
 5 6 1 6 1 4 4

7 ѹҤ ..2549
99 Users On-Line.
Visitors - Page views
 8 9 7 3 8 8 7
1 Ҿѹ ..2551

Google   
g2gnet.com
Ҵѡ:  

ҹ Drag & Drop VB 6 ;Ѳ͡¹ ͹ (Ҥ 1)

Category »  VB 6/VB.Net
: Webmaster 10/3/2552   : 12:31
(ҹ : 21393) 
CodeJock Web Siteҷٴ¡ѺҨҹ ǡѺͧͧ¹ Code ¹ Script ҷ ҹǡѹ 55555+ ... ͧѺ ... ҡҹ֡¹ Ҩҧ͡¹ ͹ SwishMax, Flash, Authorware ѹշҧҧ¹͡ Դѹ ԴͺѺ¹ (Interactive) ... ѹ ͹Ѻ ... 令Դ ջ͡ Թ˹ ѧ ѹ Interactive ... Ẻѹ ˵ط͡ Basic ҹʹ ǹѹ ö§ѧẺ Multimedia 件֧ǹ˹觢ͧ Basic ѹѧ١ѧմö Microsoft Office ҷء ¡ Visual Basic for Application (VBA) ѧԴҴ VSTO (Visual Studio Tools for Office) Ѻ෤ Dot Net (ҹ´Сѹ) ... ػѧѹҧ ǹ˭Ҩҹѡ Power Point 繵ǹʹѺ¹ѹ ҡҹö Basic ͧҡлѺͨҡ Power Point ѡɳ繡ùʹẺҧ 2 ҧҧҡԹ仹ѡ͡Ѻ ...
ǹŴ - óշԴ MS Visual Basic 6.0 (SP6) º
ǹŴ Source Code Ѻ MS Visual Basic 6.0 - Service Pack 6
 ǹŴ Microsoft Visual Basic Service Pack 6
ǹŴ - óշԴ MS Visual Basic 6.0 (SP6)
ǹŴͺ Drag & Drop (EXE File)
 ǹŴ Visual Basic 6.0 SP5: Run-Time Redistribution Pack
 ǹŴشԴ Microsoft Visual Basic 6.0 Enterprise Edition (ҡԴ¹ VB6 ͧǹŴѺм)
ͧǢͧ
ҹ Drag & Drop VB 6 ;Ѳ͡¹ ͹ (Ҥ 2)
ŢӹǹẺӡѹ - Random Number
ûءҹ MS Visual Basic 6.0 ѺþѲ͡¹͹
鹡кǹ÷ӧҹ

Design Time - ͡Ẻ˹ҵ˹Ҩ


Run Time - ӧҹ


Run Time - Ẻͺº


駼š÷ͺ ... §ҹҷ
çзй仾Ѳҵ㹡èѴ红 㹡ûԹẺͺ
Ҵ鴡ѹ ...

Option Explicit

' ÷㹡кص˹ 鹡ҡ (Drag)
Dim AxisX As Integer
Dim AxisY As Integer

' 駡 Drop ŧ˹Ҷ١ͧ (繵ͧ ... ٨ҡ˵ءó DragDrop)
Dim RedFlag As Boolean
Dim GreenFlag As Boolean
Dim BlackFlag As Boolean

' ѺǨͺ÷Ẻͺ١ͧ
Dim TotalScore As Integer

' 鹡÷Ẻͺ
Dim StartTime As Date

' ͸ԺǹǢͧѺᴧ (RED) ҹ鹾 ... ФѺ
' ˵ءó (Event) 㹡áŧ Control (Coomand Button) ҡ
Private Sub cmdRed_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    ' кص˹᡹ X ᡹ Y 鹡ҡ (Drag)
    ' ҡҡҧԴ˹ѹⴴѺ
    AxisX = X
    AxisY = Y
    
    ' Ǩͺ͹һ͡ (ᴧ) ҧŧç˹觢ͧѹ
    ' ҡ Դ͹ ... ҡ ͧԴ͹»˹
    If Not RedFlag Then cmdRed.Drag vbBeginDrag
End Sub

' ҡ Control ҧ ... 
Private Sub cmdRed_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ' ͻ͡ ... شҡҧ
    cmdRed.Drag vbEndDrag
End Sub

' ͹ѹѺ cmdRed ... ͸Ժ
Private Sub cmdGreen_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    AxisX = X
    AxisY = Y
    If Not GreenFlag Then cmdGreen.Drag vbBeginDrag
End Sub

Private Sub cmdGreen_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    cmdGreen.Drag vbEndDrag
End Sub

Private Sub cmdBlack_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    AxisX = X
    AxisY = Y
    If Not BlackFlag Then cmdBlack.Drag vbBeginDrag
End Sub

Private Sub cmdBlack_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    cmdBlack.Drag vbEndDrag
End Sub

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    ' ͹ Control º ҧŧ㹵˹觢ͧ Control ·ҧ (Label ͡)
    Source.Move X - AxisX, Y - AxisY
End Sub

Private Sub Form_Load()
    
    Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
    TotalScore = 0
    ' ˹ ... ѹѧ١ҡҧç˹
    RedFlag = False
    GreenFlag = False
    BlackFlag = False
    
    ' 鹨Ѻ
    StartTime = FormatDateTime(Now(), vbLongTime)
    
    ' ѹԧ Ҥ˹觢ͧѵصҧ͹ ... Ҩдա Դè
    ' ԸդԴ  ص˹觢ͧ (Label)  3   ...
    ' ˹ A(1, 1) / A(1,2)  纵˹觫/ͧŵǷ 1 = Left, Top
    ' ˹ A(2, 1) / A(2, 2) 纵˹觫/ͧŵǷ 2 = Left, Top
    ' ˹ A(3, 1) / A(3, 2) 纵˹觫/ͧŵǷ 3 = Left, Top
    ' ͹ ... ˹ҵẺ Array Ҵ 3  2 ѡ
    ' Ţҧ 1 - 3 (㹺ͧͧŢẺ)
    '  3, 1, 2 (ҷͧ Array) ... 蹡¤
    ' ŵǷ 1 㹵˹觷 3
    ' ŵǷ 2 㹵˹觷 1
    ' ŵǷ 3 㹵˹觷 2
    ' ҹ͹ФѺ ... ػ Ҩ ҹ令Դ͹ (Ҩԧ)
End Sub

' ˵ءóҡҧ л͡º ... ͡˵ءó DragDrop
' Ҩ͡Ըաҡҧ˹š (˵ءó DragOver)
Private Sub lblRed_DragDrop(Source As Control, X As Single, Y As Single)
    
    ' ͺһҡҧ鹪 cmdRed 
    If Source.Name = "cmdRed" Then
        ' ҧŧ˹
        Source.Move lblRed.Left, lblRed.Top
        
        ' ҧº ... شҡҧ
        cmdRed.Drag vbEndDrag
        
        ' ============================================================
        ' һ١ҧŧç˹ Դ͹˹˹ա
        ' ѹѺ˵ءó존͡ (MouseDown)
        RedFlag = True
        '
        '  ˹ö
        cmdRed.Enabled = False
        ' ѹԧ ͡˹ö顴 (Enabled = False)
        ' ҡյẺ Boolean (RedFlag) 㹡÷ͺ ...
        ' ҹͧѺ ... ͧ ... Ҩҹ
        ' ============================================================
        
        ' ṹա 1
        TotalScore = TotalScore + 1
        ' ǨͺҷӶ١ͧú 3 
        ' ҡ騺
        If CheckScore(TotalScore) Then End
        
        
    ' óշ Ҩ繵ͧ駢ͤ͡͡ ...
    ' è红㹡÷ӼԴ ػ㹵͹
    ' ҡҷӶ١ ӼԴ ... ¹ѡ¹  س 55555+
    Else
        ' ѧҡʴͤ ١ͧ駡Ѻ仵˹觷˹Ҩҡ AxisX  AxisY
        MsgBox "١ͧФФس˹.", vbOKOnly + vbExclamation, "ӼԴ"
    End If
End Sub

Private Sub lblBlack_DragDrop(Source As Control, X As Single, Y As Single)
    
    If Source.Name = "cmdBlack" Then
        Source.Move lblBlack.Left, lblBlack.Top
        cmdBlack.Drag vbEndDrag
        BlackFlag = True
        cmdBlack.Enabled = False
        TotalScore = TotalScore + 1
        If CheckScore(TotalScore) Then End
    Else
        MsgBox "١ͧФФس˹.", vbOKOnly + vbExclamation, "ӼԴ"
    End If
End Sub

Private Sub lblGreen_DragDrop(Source As Control, X As Single, Y As Single)
    
    If Source.Name = "cmdGreen" Then
    Source.Move lblGreen.Left, lblGreen.Top
        cmdGreen.Drag vbEndDrag
        GreenFlag = True
        cmdGreen.Enabled = False
        TotalScore = TotalScore + 1
        If CheckScore(TotalScore) Then End
    Else
        MsgBox "١ͧФФس˹.", vbOKOnly + vbExclamation, "ӼԴ"
    End If
End Sub

' ѧ蹷㹡õǨͺ÷Ẻͺ ... ú˹
' ѺҤṹ ... ҡú˹ (3 ) ׹Ҩԧ (True) Ѻ
Function CheckScore(ByRef TotalScore As Integer) As Boolean
    If TotalScore = 3 Then
        ' ѧ  §ҹš÷Ẻͺ
        MsgBox "١ͧ ... ˹觨ѧ¤." & vbCrLf & _
                        "ҷ : " & FormatDateTime(Time - StartTime, vbLongTime), _
                        vbOKOnly + vbInformation, ""
        CheckScore = True
    Else
        CheckScore = False
    End If
End Function
Conclusion:
͹Ѻ ... Ъ鹢ͧѺ MS Visual Basic 6.0 ҡ͹ Ҩ ö֡ҢẺ鹰ҹ䫵ҧ ë˹ѧ VB6 ͧҹ ҽ֡ͧ͹ФѺ 礧ѡ㹡ùʹͤ駹 ͧ͡Ƿҧ ҧçе ç٧੾Ѻؤ繤Ҫվҹ ...

͵ - g2gNet Dot Com
Ţ¹ҳԪ硷͹ԡ 0407314800231
CopyLeft © 2004 - 2099 g2gNet.Com All rights reserved.
Email: [email protected] . 08-6862-6560