This article mainly introduces C # WinForm multi-screen multiple display programming skills examples, this article directly gives code examples, the need for friends can refer to the
In the middle of the window there is a System.Windows.Forms.PictureBox control (the area of the control area is 1/4 of the window), and when most of the control's area falls on one of the monitors, the control is not displayed on the other monitor ( The PictureBox control is moved to the window area where the primary display is located.
Implementation method:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
Using System; Using System.Drawing; Using System.Collections; Using System.ComponentModel; Using System.Windows.Forms; Using System.Data; namespace WindowsApplication12 {///<summary>///Summary description for FORM1.///</summary> public class Form1:System.Windows.Forms.Form {private int tmpx = 0; private int tmpy = 0; Private System.Windows.Forms.PictureBox pi CtureBox1; <summary>///Required designer variable. </summary> private System.ComponentModel.Container components = null; System.drawing.rectangle[] Screensrect; Public Form1 () {////Required for Windows Form Designer Support//InitializeComponent ();////Todo:add any Constructo R code after the InitializeComponent call//}///<summary>///clean up any resources being used. </summary> protected override void Dispose (bool disposing) {if (disposing) {if (components!= null) {compo Nents. Dispose (); } base. Dispose (disposing); } #region Windows Form Designer GenerateD-code///<summary>///Required method for Designer support-do not modify///the contents of it with T He code Editor. </summary> private void InitializeComponent () {this.picturebox1 = new System.Windows.Forms.PictureBox (); . SuspendLayout (); PictureBox1//This.pictureBox1.BackColor = System.Drawing.SystemColors.HotTrack; This.pictureBox1.Location = new System.Drawing.Point (120, 88); This.pictureBox1.Name = "PictureBox1"; This.pictureBox1.Size = new System.Drawing.Size (248, 176); This.pictureBox1.TabIndex = 0; This.pictureBox1.TabStop = false; Form1//this. AutoScaleBaseSize = new System.Drawing.Size (5, 13); This. ClientSize = new System.Drawing.Size (504, 357); This. Controls.Add (This.picturebox1); This. Name = "Form1"; This. Text = "Form1"; This. MouseDown + = new System.Windows.Forms.MouseEventHandler (this. Form1_mousedown); This. Load + = new System.EventHandler (this. Form1_Load); This. MouseUp + = new System.Windows.Forms.MouseEventHandler (this. ForM1_mouseup); This. ResumeLayout (FALSE); #endregion///<summary>///The main entry point for the application. </summary> [STAThread] static void Main () {Application.Run (New Form1 ());} private void Form1_mousedown (object sender, System.Windows.Forms.MouseEventArgs e) {this.tmpx = e.x; this.tmpy = e.y; MouseMove + = new System.Windows.Forms.MouseEventHandler (this.form1_mousemove); } private void Form1_mouseup (object sender, System.Windows.Forms.MouseEventArgs e) {this. MouseMove-= new System.Windows.Forms.MouseEventHandler (this.form1_mousemove); System.Drawing.Rectangle Picturebox1rect=screen.getworkingarea (PictureBox1); for (int i=0;i<screensrect.length;i++) {if (Screensrect[i]. X==picturebox1rect.x && Screensrect[i]. Y==PICTUREBOX1RECT.Y) this. Location=new Point (Screensrect[i]. X,PICTUREBOX1RECT.Y); }//messagebox.show ("Workingarea:" + Re. ToString ()); } private void Form1_mousemove (object sender, MouseEventArgs e) {this. Location = new SYSTEM.DRAWING.POint (this. Location.x + e.x-this.tmpx, this. LOCATION.Y + e.y-this.tmpy); } private void Form1_Load (object sender, System.EventArgs e) {screen[] s=screen.allscreens; Screensrect=new Rectangle[s.length]; for (int i=0;i<s.length;i++) {screensrect[i]= s[i]. Workingarea; } } } } |