Button1.DoDragDrop(Button1, DragDropEffects.Copy || DragDropEffects.Move); //形成拖拽效果,移动+拷贝的组合效果
Button1.DoDragDrop(Button1, DragDropEffects.Copy Or DragDropEffects.Move) '形成拖拽效果,移动+拷贝的组合效果
private void Form1_DragEnter(System.Object sender, System.Windows.Forms.DragEventArgs e)
{
//当Button被拖拽到WinForm上时候,鼠标效果出现
if ((e.Data.GetDataPresent(typeof(Button)))) {
e.Effect = DragDropEffects.Copy;
}
}
Private Sub Form1_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter
If (e.Data.GetDataPresent(GetType(Button))) Then '当Button被拖拽到WinForm上时候,鼠标效果出现
e.Effect = DragDropEffects.Copy
End If
End Sub
private void Form1_DragDrop(System.Object sender, System.Windows.Forms.DragEventArgs e)
{
//拖放完毕之后,自动生成新控件
Button btn = new Button();
btn.Size = Button1.Size;
btn.Location = this.PointToClient(new Point(e.X, e.Y));
//用这个方法计算出客户端容器界面的X,Y坐标。否则直接使用X,Y是屏幕坐标
this.Controls.Add(btn);
btn.Text = "按钮" + count.ToString;
count = count + 1;
}
Private Sub Form1_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop
'拖放完毕之后,自动生成新控件
Dim btn As New Button
btn.Size = Button1.Size
btn.Location = Me.PointToClient(New Point(e.X, e.Y)) '用这个方法计算出客户端容器界面的X,Y坐标。否则直接使用X,Y是屏幕坐标
Me.Controls.Add(btn)
btn.Text = "按钮" + count.ToString
count = count + 1
End Sub
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class Form1
{
//计数变量,说明输出了第N个Button
private int count = 1;
private void Form1_Load(System.Object sender, System.EventArgs e)
{
this.AllowDrop = true;
//窗体自身支持接受拖拽来的控件
}
private void Button1_MouseDown(System.Object sender, System.Windows.Forms.MouseEventArgs e)
{
//左键的话,标志位为true(表示拖拽开始)
if ((e.Button == System.Windows.Forms.MouseButtons.Left)) {
Button1.DoDragDrop(Button1, DragDropEffects.Copy | DragDropEffects.Move);
//形成拖拽效果,移动+拷贝的组合效果
}
}
private void Form1_DragEnter(System.Object sender, System.Windows.Forms.DragEventArgs e)
{
//当Button被拖拽到WinForm上时候,鼠标效果出现
if ((e.Data.GetDataPresent(typeof(Button)))) {
e.Effect = DragDropEffects.Copy;
}
}
private void Form1_DragDrop(System.Object sender, System.Windows.Forms.DragEventArgs e)
{
//拖放完毕之后,自动生成新控件
Button btn = new Button();
btn.Size = Button1.Size;
btn.Location = this.PointToClient(new Point(e.X, e.Y));
//用这个方法计算出客户端容器界面的X,Y坐标。否则直接使用X,Y是屏幕坐标
this.Controls.Add(btn);
btn.Text = "按钮" + count.ToString();
count = count + 1;
}
public Form1()
{
DragDrop += Form1_DragDrop;
DragEnter += Form1_DragEnter;
Load += Form1_Load;
}
}
Public Class Form1
'计数变量,说明输出了第N个Button
Private count As Integer = 1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.AllowDrop = True '窗体自身支持接受拖拽来的控件
End Sub
Private Sub Button1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
'左键的话,标志位为true(表示拖拽开始)
If (e.Button = Windows.Forms.MouseButtons.Left) Then
Button1.DoDragDrop(Button1, DragDropEffects.Copy Or DragDropEffects.Move) '形成拖拽效果,移动+拷贝的组合效果
End If
End Sub
Private Sub Form1_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter
If (e.Data.GetDataPresent(GetType(Button))) Then '当Button被拖拽到WinForm上时候,鼠标效果出现
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub Form1_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop
'拖放完毕之后,自动生成新控件
Dim btn As New Button
btn.Size = Button1.Size
btn.Location = Me.PointToClient(New Point(e.X, e.Y)) '用这个方法计算出客户端容器界面的X,Y坐标。否则直接使用X,Y是屏幕坐标
Me.Controls.Add(btn)
btn.Text = "按钮" + count.ToString
count = count + 1
End Sub
End Class
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有