时间:2021-05-20
在窗口的中间有一个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; } } } }声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
外接显示器分辨率调不上去的解决方法如下: 1、打开电脑,右键点击桌面空白处,选择“屏幕分辨率”。 2、在更改显示器外观里找“多显示器”,选择复制这些显示。
笔记本电脑和投影仪连接后投影仪不能显示电脑内容,是因为多显示器设置没有设置成复制显示模式。需要在屏幕分辨率中修改多显示器的显示模式。 以联想G450笔记本为例
C#动态创建button按钮的方法实例详解C#编程中经常需要动态创建,本文主要介绍C#动态创建button按钮的方法,涉及C#按钮属性动态设置的相关技巧,以供借
本文实例分析了C#中登录窗体和欢迎窗体关闭方法。分享给大家供大家参考。具体分析如下:在c#的winform编程中,我们经常会做登录窗体或欢迎窗体,并把他们作为启
显示器灯管坏了的症状有: 1、屏幕亮度不均。现在的显示器都是多灯管显示器,一般都是四支灯管,有的也最少是两支,损坏某个灯管后表现为图像亮度不均匀,比如上方暗淡