首页 新闻 会员 周边

多屏输出

0
[已关闭问题]

请教下. 程序控制多屏幕输出要如何控制呢,一个系统有两个界面要同时输出到两个屏幕上 
 前提是 有多张显卡,程序可以获取到显卡属性信息.

马克的主页 马克 | 初学一级 | 园豆:200
提问于:2010-03-03 08:57
< >
分享
其他回答(1)
0

基本思路:先你需要知道一个屏幕是如何分割成多个显示器显示的,即每个显示器显示多大region。  
  而在初始化picturebox的时候,你可以通过  
  Screen.PrimaryScreen.Bounds  
  来获得屏幕大小,至于控件的位置,你可以先转换到屏幕坐标,然后按照前面获得比例尺寸(一个屏幕是如何分割成多个显示器显示的,即每个显示器显示多大region),最后进行判断处理。

代码
1 测试代码如下:
2 using System;
3 using System.Drawing;
4 using System.Collections;
5 using System.ComponentModel;
6 using System.Windows.Forms;
7 using System.Data;
8
9 namespace WindowsApplication12
10 {
11 /// <summary>
12 /// Summary description for Form1.
13 /// </summary>
14 public class Form1 : System.Windows.Forms.Form
15 {
16 private int tmpx = 0;
17 private int tmpy = 0;
18 private System.Windows.Forms.PictureBox pictureBox1;
19 /// <summary>
20 /// Required designer variable.
21 /// </summary>
22 private System.ComponentModel.Container components = null;
23
24 System.Drawing.Rectangle[] ScreensRect;
25
26 public Form1()
27 {
28 //
29 // Required for Windows Form Designer support
30 //
31 InitializeComponent();
32
33 //
34 // TODO: Add any constructor code after InitializeComponent call
35 //
36 }
37
38 /// <summary>
39 /// Clean up any resources being used.
40 /// </summary>
41 protected override void Dispose( bool disposing )
42 {
43 if( disposing )
44 {
45 if (components != null)
46 {
47 components.Dispose();
48 }
49 }
50 base.Dispose( disposing );
51 }
52
53 #region Windows Form Designer generated code
54 /// <summary>
55 /// Required method for Designer support - do not modify
56 /// the contents of this method with the code editor.
57 /// </summary>
58 private void InitializeComponent()
59 {
60 this.pictureBox1 = new System.Windows.Forms.PictureBox();
61 this.SuspendLayout();
62 //
63 // pictureBox1
64 //
65 this.pictureBox1.BackColor = System.Drawing.SystemColors.HotTrack;
66 this.pictureBox1.Location = new System.Drawing.Point(120, 88);
67 this.pictureBox1.Name = "pictureBox1";
68 this.pictureBox1.Size = new System.Drawing.Size(248, 176);
69 this.pictureBox1.TabIndex = 0;
70 this.pictureBox1.TabStop = false;
71 //
72 // Form1
73 //
74 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
75 this.ClientSize = new System.Drawing.Size(504, 357);
76 this.Controls.Add(this.pictureBox1);
77 this.Name = "Form1";
78 this.Text = "Form1";
79 this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
80 this.Load += new System.EventHandler(this.Form1_Load);
81 this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
82 this.ResumeLayout(false);
83
84 }
85 #endregion
86
87 /// <summary>
88 /// The main entry point for the application.
89 /// </summary>
90 [STAThread]
91 static void Main()
92 {
93 Application.Run(new Form1());
94 }
95
96 private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
97 {
98 this.tmpx = e.X;
99 this.tmpy = e.Y;
100 this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.form1_MouseMove);
101
102 }
103
104 private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
105 {
106 this.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.form1_MouseMove);
107
108 System.Drawing.Rectangle pictureBox1Rect=Screen.GetWorkingArea(pictureBox1);
109
110 for(int i=0;i<ScreensRect.Length;i++)
111 {
112 if(ScreensRect[i].X==pictureBox1Rect.X && ScreensRect[i].Y==pictureBox1Rect.Y)
113 this.Location=new Point(ScreensRect[i].X,pictureBox1Rect.Y);
114 }
115 //MessageBox.Show(" WorkingArea:" + re.ToString());
116 }
117 private void form1_MouseMove(object sender, MouseEventArgs e)
118 {
119 this.Location = new System.Drawing.Point(this.Location.X + e.X - this.tmpx, this.Location.Y + e.Y - this.tmpy);
120 }
121
122 private void Form1_Load(object sender, System.EventArgs e)
123 {
124 Screen[] s=Screen.AllScreens;
125 ScreensRect=new Rectangle[s.Length];
126 for(int i=0;i<s.Length;i++)
127 {
128 ScreensRect[i]= s[i].WorkingArea;
129 }
130 }
131 }
132 }
133
参考文章:http://topic.csdn.net/t/20060511/10/4743664.html
风影极光 | 园豆:1573 (小虾三级) | 2010-03-03 09:18
0

我认为程序来处理就复杂了,底层的事情交给底层去完成,操作系统本身支持多监视器,只要你在显示卡设置里设置为第二个监视器为扩展桌面就好了

你的程序完全可以开两个窗口,一个显示在监视器1里,一个拖到监视器2,就可以解决你的问题了,简单省力,而且不用考虑分辨率的问题

查尔斯 | 园豆:3832 (老鸟四级) | 2010-03-03 12:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册