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
  • 相关阅读:
    面试官:你说说互斥锁、自旋锁、读写锁、悲观锁、乐观锁的应用场景
    JAVA 线上故障排查套路,从 CPU、磁盘、内存、网络到GC 一条龙!
    面经分享:看非科班研究生如何转行斩获 ATM 大厂的 Offer ?
    Jmeter JDBC配置
    Jmeter JDBC连接
    js基础用法1
    java实现io读取数据
    mysql语句
    java修改linux文件
    linux永久或临时修改dns
  • 原文地址:https://www.cnblogs.com/xiaoyinxxy/p/2997515.html
Copyright © 2011-2022 走看看