いつも大変お世話になっております。
マルチディスプレイ使用時の動作でお聞きしたいことがあります。
例えば、ディスプレイA・ディスプレイB があります。
以下のプログラムですと、
ディスプレイA に最大化された Form1 が表示され、ボタン1 をクリックすると、座標(100,100)の位置に、サイズ(800,800)の Form2 が表示されます。
この状態から少し操作を変えます。
ディスプレイA に最大化された Form1 をマウスで動かし、ディスプレイBに最大化し配置します。その状態で ボタン1 をクリックしますと、ディスプレイAの 座標(100,100)の位置に、サイズ(800,800)の Form2 が表示されてしまいます。
ディスプレイB を認識させ、ディスプレイBにForm2を配置するにはどうすればよろしいでしょうか?
ご指導ご鞭撻の程よろしくお願い致します。
● Form1
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Test_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int h; int w; private Button bt = new Button(); private void Form1_Load(object sender, EventArgs e) { SetControl(sender,e); //現在フォームが存在しているディスプレイの高さと幅を取得 //現在フォームが存在しているディスプレイを取得 System.Windows.Forms.Screen s = System.Windows.Forms.Screen.FromControl(this); //ディスプレイの高さと幅を取得 h = s.Bounds.Height; w = s.Bounds.Width; this.Location = new Point(0,0); this.Size = new Size(w, h); } private void SetControl(object sender, EventArgs e) { bt = new Button(); bt.Size = new Size(100, 100); bt.Location = new Point(200, 200); bt.Font = new Font("Arial", 16); bt.Text = "ボタン1"; bt.Click += new System.EventHandler(ButtonClick); this.Controls.Add(bt); } private void ButtonClick(object sender, EventArgs e) { Form2 fm = new Form2(); DialogResult drret = fm.ShowDialog(); } } }
● Form2
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Test_1 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { this.Location = new Point(100,100); this.Size = new Size(800, 800); } } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/05 06:49