20150506-winform Auto-Generate button & button drag

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacexiaojian2{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }                Private voidForm1_Load (Objectsender, EventArgs e) {        }        Private voidButton1_Click (Objectsender, EventArgs e) {             This. SplitContainer1.Panel2.Controls.Clear ();             for(inti =0; I < -; i++)            {                //Form1 xx = new Form1 (); //xx. Show ();Button BTN =NewButton () {Name ="btn"+ I, Text ="Test"+ I, Size =NewSize ( -, -) }; Btn. Location=NewPoint ( -* (i%Ten), -* (I/Ten)); Btn. MouseDown+=Button1_mousedown; Btn. MouseMove+=Button1_mousemove;  This. SPLITCONTAINER1.PANEL2.CONTROLS.ADD (BTN);//Add the generated button to the foreground page,}} Point pt; Private voidButton1_mousedown (Objectsender, MouseEventArgs e) {PT=cursor.position; }        Private voidButton1_mousemove (Objectsender, MouseEventArgs e) {                        if(MouseButtons = =mousebuttons.left) {intpx = cursor.position.x-Pt.                X intPY = CURSOR.POSITION.Y-Pt.                Y Button Butt= (Button) sender;//gets which button is, and convertsButt. Location=NewPoint (Butt. location.x + px, butt. LOCATION.Y +py); PT=cursor.position; }        }    }}

20150506-winform Auto-Generate button & button drag

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.