using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace xiaojian2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ }
private void button1_Click(object sender, EventArgs e)
{
this.splitContainer1.Panel2.Controls.Clear();
for (int i = ; i < ; i++)
{
//Form1 xx = new Form1();
//xx.Show();
Button btn = new Button() { Name = "btn" + i, Text = "Test" + i, Size = new Size(, ) };
btn.Location = new Point( * (i % ), * (i / ));
btn.MouseDown += button1_MouseDown;
btn.MouseMove += button1_MouseMove;
this.splitContainer1.Panel2.Controls.Add(btn); //向前台页面添加生成的按钮,
} }
Point pt;
private void button1_MouseDown(object sender, MouseEventArgs e)
{
pt = Cursor.Position;
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{ if (MouseButtons == MouseButtons.Left)
{
int px = Cursor.Position.X - pt.X;
int py = Cursor.Position.Y - pt.Y; Button butt = (Button)sender;//获取是哪个按钮,并转换 butt.Location = new Point(butt.Location.X + px, butt.Location.Y + py);
pt = Cursor.Position; }
}
}
}

20150506—WinForm自动生成按钮&按钮拖动的更多相关文章

  1. 懒人小工具1:winform自动生成Model,Insert,Select,Delete以及导出Excel的方法

       懒人小工具2:T4自动生成Model,Insert,Select,Delete以及导出Excel的方法    github地址:https://github.com/Jimmey-Jiang/J ...

  2. JavaScript自动生成博文目录导航/TOP按钮

    博客园页面添加返回顶部TOP按钮 进入网页管理->设置 在"页面定制CSS代码"中添加如下css样式,当然你可以改为自己喜欢的样式 此处可以将背景色background-co ...

  3. winform基本控件----按钮

    这次来引用一个我们上课时候老师给的一个实验内容,来说一下winform程序设计中的按钮控件的使用.下面是我们老师给的实验内容. 实验目的: 掌握Winform的开发环境. 掌握窗体的创建和基本方法. ...

  4. C# 动态生成的按钮及定义按钮的事件的代码

    内容闲暇时间,把内容过程中比较常用的内容备份一下,如下的内容内容是关于C# 动态生成的按钮及定义按钮的事件的内容,应该对码农们也有用途. HtmlGenericControl control = ne ...

  5. Net实现钩子函数(Hook)以及通过SendMessage实现自动点击按钮和给文本框赋值

    1.实现钩子函数 钩子(Hook)的实现需要三个主要的函数和一个委托 [DllImport("user32.dll", CharSet = CharSet.Auto, Callin ...

  6. c#:winform从一个toolstriptool上拖动一个图标到一个自定义usercontrol内。

    效果: 在一个winform工程中,添加一个ToolStrip然后给它添加一个ToolStripButton(tsbStart,它就是红色框圈选的图标) this.toolStripTools = n ...

  7. Winform自动更新组件分享

    作者:圣殿骑士 出处:http://www.cnblogs.com/KnightsWarrior/ 关于作者:专注于微软平台项目架构.管理和企业解决方案.自认在面向对象及面向服务领域有一定的造诣,熟悉 ...

  8. JavaScript自动生成博文目录导航

    转载于:JavaScript自动生成博文目录导航 我们在写博客的时候,如果博文里面有目录,会给人结构清晰.一种一目了然的感觉,看目录就知道这篇博文要讲解的内容,并且点击目录标题就可以跳转到 具体的内容 ...

  9. Eclipse自动生成作者、日期注释等功能设置

    我们在使用Eclipse 编写Java代码时,自动生成的注释信息都是按照预先设置好的格式生成的. 修改作者.日期注释格式:打开Windows->Preferences->Java-> ...

随机推荐

  1. linux C 9*9

    #include<stdio.h> #include<conio.h> #include <windows.h> void Gotoxy(int x, int y) ...

  2. 凸包---HDU 2202

    题意:给N个点,求着N个点中选择三个联的最大的三角形面积! 注意精度:不然OJ上面会超时的 #include<iostream> #include<cmath> #includ ...

  3. centos 6.3 搭建git/gitosis/gitweb

    1. git的安装和配置 (1)使用yum源安装git yum install git (2)创建git用户并设置密码 #useradd --home /home/git git #passwd gi ...

  4. 更换VS2012序列号的方法

    转自:http://blog.sina.com.cn/s/blog_58c506600101ja49.html 今天不小心把还在试用期内的VS2012 Ultimate填上盗版Key激活了……找遍了菜 ...

  5. Linux数据归档和解压缩tar,cpio,gzip,bzip,lzma,zip命令使用

    转载:http://www.1987.name/659.html 数据压缩归档和备份是系统管理的日常工作,定期备份不可小视,归档和压缩对于系统管理员或是普通用户来说都经常用到的操作,有很多中压缩格式, ...

  6. H - The Falling Leaves

    Description Each year, fall in the North Central region is accompanied by the brilliant colors of th ...

  7. Sum of divisors

    Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...

  8. 40个GitHub上最受欢迎的iOS开源项目

    40个GitHub上最受欢迎的iOS开源项目(一) http://www.weste.net/2013/8-1/92975.html 40个GitHub上最受欢迎的iOS开源项目(二) http:// ...

  9. git管理工具的使用教程

    Git入门教程 1.   概述     对于软件版本管理工具,为什么要选择Git?      你真正学会使用Git时, 你就会觉得这个问题的回答是非常自然的.然而当真正需要用文字来回答时,却觉得文字好 ...

  10. kindeditor在JavaWeb中的应用

    KindEditor 是一套开源的在线HTML编辑器,主要用于让用户在网站上获得所见即所得编辑效果,开发人员可以用 KindEditor 把传统的多行文本输入框textarea替换为可视化的富文本编辑 ...