|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
刚刚打开这篇专题,猛然见到HAL9000发表的《对于大型公司项目平台选择j2ee的几层认识》系列,深受启发。在使用程序中,是经由过程处置一系列事务,如DragEnter,DragLeave和DragDrop事务来完成在Windows使用程序中的拖放操纵的。经由过程利用这些事务参数中的可用信息,能够轻松完成拖放操纵。
拖放操纵在代码中是经由过程三步完成的,起首是启动拖放操纵,在必要拖动数据的控件上完成MouseDown事务呼应代码,并挪用DoDragDrop()办法;其次是完成拖放效果,在方针控件上增加DragEnter事务呼应代码,利用DragDropEffects列举范例完成挪动或复制等拖动效果;最初是安排数据操纵,在方针控件上增加DragDrop呼应代码,把数据增加到方针控件中。
usingSystem;
usingSystem.Drawing;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Windows.Forms;
usingSystem.Data;
namespaceDragDrop
{
///<summary>
///Form1的择要申明。
///</summary>
publicclassForm1:System.Windows.Forms.Form
{
privateSystem.Windows.Forms.ListBoxlistBox1;
privateSystem.Windows.Forms.ListBoxlistBox2;
///<summary>
///必须的计划器变量。
///</summary>
privateSystem.ComponentModel.Containercomponents=null;
publicForm1()
{
//
//Windows窗体计划器撑持所必须的
//
InitializeComponent();
//
//TODO:在InitializeComponent挪用后增加任何机关函数代码
//
}
///<summary>
///清算一切正在利用的资本。
///</summary>
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#regionWindows窗体计划器天生的代码
///<summary>
///计划器撑持所需的办法-不要利用代码编纂器修正
///此办法的内容。
///</summary>
privatevoidInitializeComponent()
{
this.listBox1=newSystem.Windows.Forms.ListBox();
this.listBox2=newSystem.Windows.Forms.ListBox();
this.SuspendLayout();
//
//listBox1
//
this.listBox1.ItemHeight=12;
this.listBox1.Location=newSystem.Drawing.Point(32,24);
this.listBox1.Name="listBox1";
this.listBox1.Size=newSystem.Drawing.Size(120,280);
this.listBox1.TabIndex=0;
this.listBox1.MouseDown+=newSystem.Windows.Forms.MouseEventHandler(this.listBox1_MouseDown);
//
//listBox2
//
this.listBox2.ItemHeight=12;
this.listBox2.Location=newSystem.Drawing.Point(248,24);
this.listBox2.Name="listBox2";
this.listBox2.Size=newSystem.Drawing.Size(120,280);
this.listBox2.TabIndex=0;
this.listBox2.DragDrop+=newSystem.Windows.Forms.DragEventHandler(this.listBox2_DragDrop);
this.listBox2.DragEnter+=newSystem.Windows.Forms.DragEventHandler(this.listBox2_DragEnter);
//
//Form1
//
this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);
this.ClientSize=newSystem.Drawing.Size(408,333);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.listBox2);
this.Name="Form1";
this.Text="Form1";
this.Load+=newSystem.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
///<summary>
///使用程序的主出口点。
///</summary>
[STAThread]
staticvoidMain()
{
Application.Run(newForm1());
}
privatevoidForm1_Load(objectsender,System.EventArgse)
{
this.listBox1.AllowDrop=true;
this.listBox2.AllowDrop=true;
this.listBox1.Items.Add("a");
this.listBox1.Items.Add("b");
this.listBox1.Items.Add("c");
}
privatevoidlistBox1_MouseDown(objectsender,System.Windows.Forms.MouseEventArgse)
{
this.listBox1.DoDragDrop(this.listBox1.Items[this.listBox1.SelectedIndex],DragDropEffects.Move);
}
privatevoidlistBox2_DragEnter(objectsender,System.Windows.Forms.DragEventArgse)
{
if(e.Data.GetDataPresent("Text"))
{
e.Effect=DragDropEffects.Move;
}
}
privatevoidlistBox2_DragDrop(objectsender,System.Windows.Forms.DragEventArgse)
{
this.listBox2.Items.Add(e.Data.GetData("Text"));
this.listBox1.Items.Remove(e.Data.GetData("Text"));
}
}
}
也许唯一可以让世人留恋Java的理由就剩下它的王牌——跨平台。 |
|