(以TreeView底下的拖曳作業)
1.拖出來
void treeView_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
{
DoDragDrop(e.Item, DragDropEffects.Move);
}
2.拖過去
void treeView_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
3.放進去,並刪原本的
void treeView_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
TreeNode NewNode;
if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
{
Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
TreeNode DestinationNode = ((TreeView)sender).GetNodeAt(pt);
NewNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
if (DestinationNode.TreeView != NewNode.TreeView)
{
DestinationNode.Nodes.Add((TreeNode)NewNode.Clone());
DestinationNode.Expand();
//Remove Original Node
NewNode.Remove();
}
}
}
2009年11月29日 星期日
keydown&button&label範例
namespace KEY事件
{
public partial class Form1 : Form
{
public Label Label1;
public Button button1;
public Form1()
{
Label1 = new Label();
Label1.Location = new Point(30, 30);
Label1.Text = "1";
Controls.Add(Label1);
//////////////////////////////////////////////////////////////////////
button1 = new Button();
button1.Location = new Point(60, 60);
button1.Size = new Size(60, 60);
button1.Text = "2";
Controls.Add(button1);
button1.Enabled = false;
/////////////////////////////////////////////////////////////////////////
KeyDown += new KeyEventHandler(Form1_KeyDown);
button1.Click += new System.EventHandler(Button1_Click);
}
void Button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("button_click");
}
void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
}
}
}
{
public partial class Form1 : Form
{
public Label Label1;
public Button button1;
public Form1()
{
Label1 = new Label();
Label1.Location = new Point(30, 30);
Label1.Text = "1";
Controls.Add(Label1);
//////////////////////////////////////////////////////////////////////
button1 = new Button();
button1.Location = new Point(60, 60);
button1.Size = new Size(60, 60);
button1.Text = "2";
Controls.Add(button1);
button1.Enabled = false;
/////////////////////////////////////////////////////////////////////////
KeyDown += new KeyEventHandler(Form1_KeyDown);
button1.Click += new System.EventHandler(Button1_Click);
}
void Button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("button_click");
}
void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
}
}
}
訂閱:
文章 (Atom)