📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace CH13_6
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ListView listView2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("List 2 Item 1");
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("List 2 Item 2");
System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem(" List 2 Item 3");
System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("Item 1");
System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem("Item 2");
System.Windows.Forms.ListViewItem listViewItem6 = new System.Windows.Forms.ListViewItem("Item 3");
this.listView2 = new System.Windows.Forms.ListView();
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// listView2
//
this.listView2.AllowDrop = true;
listViewItem1.UseItemStyleForSubItems = false;
listViewItem2.UseItemStyleForSubItems = false;
listViewItem3.UseItemStyleForSubItems = false;
this.listView2.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1,
listViewItem2,
listViewItem3});
this.listView2.Location = new System.Drawing.Point(320, 24);
this.listView2.Name = "listView2";
this.listView2.Size = new System.Drawing.Size(200, 216);
this.listView2.TabIndex = 1;
this.listView2.View = System.Windows.Forms.View.List;
this.listView2.DragDrop += new System.Windows.Forms.DragEventHandler(this.OnDragDrop);
this.listView2.DragEnter += new System.Windows.Forms.DragEventHandler(this.OnDragEnter);
//
// listView1
//
this.listView1.AllowDrop = true;
listViewItem4.UseItemStyleForSubItems = false;
listViewItem5.UseItemStyleForSubItems = false;
listViewItem6.UseItemStyleForSubItems = false;
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem4,
listViewItem5,
listViewItem6});
this.listView1.Location = new System.Drawing.Point(40, 24);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(200, 216);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.List;
this.listView1.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.OnItemDrag);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(576, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.listView2,
this.listView1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void OnItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
{
string s = e.Item.ToString();
// Start the Drag Operation
DoDragDrop(s, DragDropEffects.Copy | DragDropEffects.Move);
}
private void OnDragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void OnDragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
string typestring = "Type";
string s = e.Data.GetData(typestring.GetType()).ToString();
string orig_string = s;
// Parse out the type information
s = s.Substring(s.IndexOf(":")+1).Trim();
s = s.Substring(1,s.Length-2);
// First, add it to our list box
this.listView2.Items.Add( s );
// Find it in the first list box
IEnumerator enumerator = listView1.Items.GetEnumerator();
int whichIdx = -1;
int idx = 0;
while ( enumerator.MoveNext() )
{
string s2 = enumerator.Current.ToString();
if ( s2.Equals(orig_string) )
{
whichIdx = idx;
break;
}
idx ++;
}
this.listView1.Items.RemoveAt( whichIdx );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -