Winfrom (1) Form transfer value connection (2) mouse Move window

Source: Internet
Author: User

Private voidButton1_Click (Objectsender, EventArgs e)//here is the case without a generic collection, using a DataTable{SqlConnection conn=NewSqlConnection ("server=.; Database=cml;user=sa;pwd=123"); SqlCommand cmd=Conn.            CreateCommand (); Cmd.commandtext="SELECT * FROM Student"; Conn.            Open (); SqlDataReader Dr=cmd.            ExecuteReader (); DataTable DT=NewDataTable (); if(Dr. HasRows) {//Start adding Columns                 for(inti =0; I < Dr. FieldCount; i++)//Dr. Number of columns in the FieldCount table{dt. Columns.Add (Dr. GetName (i)); //a column-by-column addition, for Loop loop is determined after a row for each column                }                //Start adding Rows                 while(Dr. Read ())//The while loop is the data for each row, a line of loops{DataRow DTW= dt. NewRow ();//Create a new line//start adding content to new lines below                     for(inti =0; I < Dr. FieldCount; i++) {Dtw[i]= Dr[i];//start assigning values to each column that determines a row, and the For loop once assigns a column value at a time                    }                       //Add the contents of each row after the while loop is complete to DTdt.                Rows.Add (DTW); }            }            //now there is content in the DataTable, and then the DATAGRIDVIEW1 data source is DTDatagridview1.datasource =DT; Cmd.            Dispose (); Conn.        Close (); Copy the Code

--Drag the form

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace_ June 11, 2015 wwz{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private BOOLisOK//to distinguish the mouse point down or release//Initial coordinates        Private intChushix;//Initial Horizontal        Private intChushiy;//Initial ordinate//the coordinates when the mouse points down        Private intShubiaodianx;//Mouse point down the horizontal axis        Private intShubiaodiany;//mouse dot down ordinate//coordinates in the move process        Private intYIDONGX;//the horizontal axis when the mouse point moves down        Private intYidongy;//the vertical axis when the mouse point moves down        Private voidForm1_mousedown (Objectsender, MouseEventArgs e)//Mouse dot down{isOK=true; Shubiaodianx= cursor.position.x;//give the mouse a point down the horizontal axis assignmentShubiaodiany = CURSOR.POSITION.Y;//give the mouse point down ordinate assignment//assigning values to the initial coordinatesChushix = This.            location.x; Chushiy= This.        LOCATION.Y; }        Private voidForm1_mouseup (Objectsender, MouseEventArgs e) {isOK=false; }        Private voidForm1_mousemove (Objectsender, MouseEventArgs e) {            if(isOK) {//assign a value to the coordinates when movingYIDONGX =cursor.position.x; Yidongy=CURSOR.POSITION.Y; //re-assign new coordinates to the form                 This. Location =NewPoint (chushix+yidongx-shubiaodianx,chushiy+yidongy-Shubiaodiany); }        }

Winfrom (1) Form transfer value connection (2) mouse Move window

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.