zoukankan      html  css  js  c++  java
  • 学习笔记 winForm move功能 与 drag 功能

    vb.Net WinForm move button function

    #Region "Move vb.net button"
        Private isDrag As Boolean = False
        Private downPoint As Point
        Private Sub Button2_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) _
           Handles Button2.MouseDown
            isDrag = True
            downPoint = e.Location
        End Sub
    
        Private Sub Button2_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) _
          Handles Button2.MouseMove
            If isDrag Then
                Button2.Location = e.Location + Button2.Location - downPoint
            End If
        End Sub
    
        Private Sub Button2_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) _
          Handles Button2.MouseUp
            isDrag = False
        End Sub
    #End Region

    vb.Net WinForm drag button function

    Set control's AllowDrag = True

    Set groupBox's AllowDrag = True

    #Region "drag vb.Net Button to GroupBox"
        Private Sub Button1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) _
            Handles Button1.MouseDown
            Button1.DoDragDrop(Button1, DragDropEffects.All)
        End Sub
    
        Private Sub GroupBox1_dragdrop(sender As Object, e As DragEventArgs) _
            Handles GroupBox1.DragDrop
            Button1.Left = e.X
            Button1.Top = e.Y
    
        End Sub
    
        Private Sub GroupBox1_DragOver(sender As Object, e As DragEventArgs) _
            Handles GroupBox1.DragOver
            e.Effect = DragDropEffects.All
        End Sub
    #End Region

    vb6 CodeArchitects.VB6Library.VB6CommandButton drag

    Set control's AllowDrag = True

    Set form's AllowDrag = True

     Dim CustomEditMode As Boolean = True
        Dim MouseY As Integer
        Dim MouseX As Integer
        Private Sub Button1_MouseDown(ByRef Button As Short, ByRef Shift As Short, ByRef x As Single, ByRef Y As Single) Handles Button1.MouseDown
            If CustomEditMode Then
                MouseY = Y
                MouseX = x
                Button1.Drag(1)
            End If
        End Sub
    
        Private Sub Button1_MouseUp(ByRef Button As Short, ByRef Shift As Short, ByRef x As Single, ByRef Y As Single) Handles Button1.MouseUp
            Button1.Drag(2)
        End Sub
    
        Private Sub Button1_DragDrop(ByRef Source As Control, ByRef x As Single, ByRef Y As Single) Handles Button1.DragDrop
            MouseY = (MouseY - Y)  
            MouseX = (MouseX - x) 
    
            Call Form_DragDrop(Source, Button1.Left, Button1.Top)
    
        End Sub
    
        Private Sub Form_DragDrop(ByRef Source As Control, ByRef x As Single, ByRef Y As Single) Handles MyBase.DragDrop
            If Not CustomEditMode Then 
                Exit Sub
            End If
            Source.Left = (x - MouseX) / 15
            Source.Top = (Y - MouseY) / 15
            Source.Enabled = True
    
        End Sub
  • 相关阅读:
    2 java开发环境的配置步骤
    1 java 笔记
    sql 创建新表时的完成格式
    sql 将英文句子中的单词首字母转换为大写
    c# datatable 如何转CSV文件
    c#调用存储过程实现批量增加和修改数据
    c#如何使用MemoryStream和BinaryFormatter进行对象的序列化和返序列化
    supersr--KVO/KVC
    supersr--控制器的生命周期:
    Javascript高级编程学习笔记(16)—— 引用类型(5) Function类型
  • 原文地址:https://www.cnblogs.com/xiaoyinxxy/p/2997515.html
Copyright © 2011-2022 走看看