アニメ『武装少女マキャヴェリズム』
学園を治めるのは5人の帯剣した女子生徒。男子生徒は全員矯正されます。矯正後の男子はマツコデラのように男を捨てる道を選びます。しかし、転入生の男子は従いません。バトルが始まります。
ファイルのドラッグドロップの次は、コントールのドラッグドロップをします。
ではサンプルプログラムです。
using System;
using System.Drawing;
using System.Windows.Forms;
class Test : Form{
Button bt;
Test(){
this.Size = new Size(600,300);
TextBox tb = new TextBox();
tb.Parent = this;
tb.Location = new Point(0,0);
tb.Size = new Size(300,300);
tb.Multiline = true;
tb.AcceptsReturn = true;
tb.MouseDown += new MouseEventHandler(MouseDown);
bt = new Button();
bt.Parent = this;
bt.Location = new Point(300,0);
bt.Size = new Size(300,300);
bt.AllowDrop = true;
bt.DragEnter += new DragEventHandler(DragEnter);
bt.DragDrop += new DragEventHandler(DragDrop);
}
new void MouseDown(object sender, MouseEventArgs e){
TextBox t = (TextBox)sender;
string data = t.Text;
t.DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Move);
}
new void DragEnter(object sender, DragEventArgs e){
if (e.Data.GetDataPresent(typeof(String)))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
new void DragDrop(object sender, DragEventArgs e){
bt.Text=(string)e.Data.GetData(typeof(String));
}
[STAThread]
public static void Main(){
Application.Run(new Test());
}
}

実行するとこのような画面が起動しますので、左のテキストボックスに適当に文字列を入力します。
左のテキストボックスをマウスでドラッグして右のボタンにドロップすると、テキストボックス内文字列がボタン上に表示されます。

コメント