程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C# Winform多屏幕多顯示器編程技能實例

C# Winform多屏幕多顯示器編程技能實例

編輯:C#入門知識

C# Winform多屏幕多顯示器編程技能實例。本站提示廣大學習愛好者:(C# Winform多屏幕多顯示器編程技能實例)文章只能為提供參考,不一定能成為您想要的結果。以下是C# Winform多屏幕多顯示器編程技能實例正文


在窗口的中央有一個System.Windows.Forms.PictureBox控件(該控件區域的面積為地點窗口的1/4),當該控件的年夜部門區域落在個中一台顯示器時,在另外一台顯示器將不顯示該控件,(該PictureBox控件將挪動到主顯示器地點的窗口區域)。 

完成辦法:

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 pictureBox1; 
/// <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 constructor code after InitializeComponent call 
// 
} 
/// <summary> 
/// Clean up any resources being used. 
/// </summary> 
protected override void Dispose( bool disposing ) 
{ 
if( disposing ) 
{ 
if (components != null) 
{ 
components.Dispose(); 
} 
} 
base.Dispose( disposing ); 
} 
#region Windows Form Designer generated code 
/// <summary> 
/// Required method for Designer support - do not modify 
/// the contents of this method with the code editor. 
/// </summary> 
private void InitializeComponent() 
{ 
this.pictureBox1 = new System.Windows.Forms.PictureBox(); 
this.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; 
this.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; 
} 
} 
} 
} 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved