OCRソフトで情報処理

【ドラッグアンドドロップ】に関する知恵袋

【質問】
C#で複数のフォームを扱う時のプログラムについてフォーム1またはフォーム2をドラッグアンドドロップで移動させた時、もう片方のフォームも同時に移動させるにはどうしたらよいでしょうか?
【解答】
Form1 の右隣に Form2 を並べる例です。Form1.cs==================================================================using System;using System.Drawing;using System.Windows.Forms;namespace WindowsFormsApplication1{ public partial class Form1 : Form { private Form2 _f2; private bool _active; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { _f2 = new Form2(this); _f2.Show(); _f2.Left = this.Left + this.Width; } private void Form1_Move(object sender, EventArgs e) { if( _active ) { if( _f2 != null ) { _f2.Left = this.Left + this.Width; } } } private void Form1_Activated(object sender, EventArgs e) { _active = true; } private void Form1_Deactivate(object sender, EventArgs e) { _active = false; } }}Form2.cs==================================================================using System;using System.Drawing;using System.Windows.Forms;namespace WindowsFormsApplication1{ public partial class Form2 : Form { private Form1 _f1; private bool _active; public Form2() { InitializeComponent(); } public Form2(Form1 f1) { InitializeComponent(); _f1 = f1; this.Left = _f1.Left + _f1.Width; } private void Form2_Move(object sender, EventArgs e) { if (_active) { _f1.Left = this.Left - _f1.Width; } } private void Form2_Activated(object sender, EventArgs e) { _active = true; } private void Form2_Deactivate(object sender, EventArgs e) { _active = false; } }}
http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1373538433
Webサービス by Yahoo! JAPAN

その他関連ワード