问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

C#ListView拖动如何才能像windows一样有个透明图标跟随鼠标

发布网友 发布时间:2022-04-24 23:18

我来回答

2个回答

热心网友 时间:2022-04-22 07:22

用javascript可以实现,鼠标移动触发事件,在鼠标的坐标出显示一个DIV就可以。

热心网友 时间:2022-04-22 08:40

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ODLV
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.ListView listView2;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
bool lv1_mdown = false ;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader5;
bool lv2_mdown = false;

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()
{
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.splitter1 = new System.Windows.Forms.Splitter();
this.listView2 = new System.Windows.Forms.ListView();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
//
// listView1
//
this.listView1.AllowDrop = true;
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader3});
this.listView1.Dock = System.Windows.Forms.DockStyle.Top;
this.listView1.FullRowSelect = true;
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(232, 176);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDown);
this.listView1.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView1_DragDrop);
this.listView1.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView1_DragEnter);
this.listView1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseMove);
//
// columnHeader1
//
this.columnHeader1.Text = "COL1";
this.columnHeader1.Width = 100;
//
// columnHeader3
//
this.columnHeader3.Text = "COL2";
this.columnHeader3.Width = 100;
//
// splitter1
//
this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter1.Location = new System.Drawing.Point(0, 176);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(232, 3);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
//
// listView2
//
this.listView2.AllowDrop = true;
this.listView2.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader2,
this.columnHeader5});
this.listView2.Cursor = System.Windows.Forms.Cursors.Arrow;
this.listView2.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView2.FullRowSelect = true;
this.listView2.Location = new System.Drawing.Point(0, 179);
this.listView2.MultiSelect = false;
this.listView2.Name = "listView2";
this.listView2.Size = new System.Drawing.Size(232, 226);
this.listView2.TabIndex = 2;
this.listView2.View = System.Windows.Forms.View.Details;
this.listView2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.listView2_MouseDown);
this.listView2.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView2_DragDrop);
this.listView2.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView2_DragEnter);
this.listView2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.listView2_MouseMove);
//
// columnHeader2
//
this.columnHeader2.Text = "COL1";
this.columnHeader2.Width = 100;
//
// columnHeader5
//
this.columnHeader5.Text = "COL2";
this.columnHeader5.Width = 100;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(232, 405);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.listView2,
this.splitter1,
this.listView1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
ImageList il = new ImageList();
il.Images.Add(new System.Drawing.Icon("E:\\林APP\\WinFormCollection\\DragDropListView \\TICK.ico"));//D:\\smk\\odlv\\tick.ico
listView1.SmallImageList = il ;

ImageList i2 = new ImageList();
i2.Images.Add(new System.Drawing.Icon("E:\\林APP\\WinFormCollection\\DragDropListView \\KEY04.ICO"));//D:\\smk\\odlv\\key04.ico
listView2.SmallImageList = i2 ;

string[] items = new string[2];
items[0] = "LA" ; items[1] = "Los Angeles";
listView1.Items.Add(new ListViewItem(items,0));
items[0] = "WA" ; items[1] = "Seattle";
listView1.Items.Add(new ListViewItem(items,0));
items[0] = "IL" ; items[1] = "Chicago";
listView1.Items.Add(new ListViewItem(items,0));

items[0] = "FR" ; items[1] = "Paris";
listView2.Items.Add(new ListViewItem(items,0));
items[0] = "BR" ; items[1] = "London";
listView2.Items.Add(new ListViewItem(items,0));
items[0] = "IN" ; items[1] = "Mum";
listView2.Items.Add(new ListViewItem(items,0));

}

private void listView1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
string textBox1 = e.Data.GetData(DataFormats.Text).ToString();
string[] items = textBox1.Split(',');
listView1.Items.Add(new ListViewItem(items,0));
lv1_mdown = false ;
lv2_mdown = false ;
}
private void listView2_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
string textBox1 = e.Data.GetData(DataFormats.Text).ToString();
string[] items = textBox1.Split(',');
listView2.Items.Add(new ListViewItem(items,0));
lv2_mdown = false ;
lv1_mdown = false ;
}

private void listView2_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void listView1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void listView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ( ! lv1_mdown ) return ;
if ( e.Button == MouseButtons.Right ) return ;

string str = GetItemText(listView1) ;
if ( str == "" ) return ;

listView1.DoDragDrop(str , DragDropEffects.Copy | DragDropEffects.Move ) ;
}

private void listView2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ( ! lv2_mdown ) return ;
if ( e.Button == MouseButtons.Right ) return ;

string str = GetItemText(listView2) ;
if ( str == "" ) return ;

listView2.DoDragDrop(str, DragDropEffects.Copy | DragDropEffects.Move ) ;
}

private void listView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
lv1_mdown = true ;
}

private void listView2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
lv2_mdown = true ;
}

public string GetItemText(ListView LVIEW)
{
int nTotalSelected = LVIEW.SelectedIndices.Count;
if ( nTotalSelected <= 0 ) return "";
IEnumerator selCol = LVIEW.SelectedItems.GetEnumerator();
selCol.MoveNext() ;
ListViewItem lvi = (ListViewItem)selCol.Current;
string mDir = "";
for ( int i=0; i < lvi.SubItems.Count;i++)
mDir += lvi.SubItems[i].Text +",";

mDir = mDir.Substring(0,mDir.Length-1);
return mDir ;
}
}
}
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
怎样写小说比较容易被发掘? 笔记本独显有黄色叹号,不能工作,n卡控制面板消失重下驱动也不管用,求助... ...我的独立显卡怎么显示一个黄色的小叹号。怎么解决啊? 去了怎么造句 跑到怎么造句 临床医学可不可以报考执业药师 中秋和双节公司都发放了什么礼物啊? 请问川藏线自驾旅游可以携带医用氧气瓶吗 个人家庭如何租医用氧气瓶 fell过去式和过去分词形式 鼠标拖动图标会有透明效果 透明玻璃鼠标指针主题包 蓝色的鼠标图标,正常是浅蓝色有点透明,繁忙是浅*,很繁忙是红色 我的鼠标箭头变成透明的了,怎么弄回来?请哪位好友帮我一下吧。 鼠标指针的半透明效果是怎样做出来的? 请问十字黄色透明鼠标指针怎么弄得 求一款淡蓝色透明鼠标指针。 二手车平台上车源和价格都是真实的吗?谢谢了。 二手车来源渠道? 二手车车源编号查询 二手车商如何找车源 怎么找二手车 源呢? 如何获取二手车车源,现在收车越来越难了 收购二手车的方法与思路有哪些? 二手车源,哪里多相对真实? 一般的二手车来源是来自于哪些途径? 购买二手车的途径有哪些? 二手车市场的车源是从哪来的? 二手车如何找车源 二手车主要来源于哪里? 求蓝绿色透明玻璃效果鼠标指针 - 信息提示 鼠标指针 隐藏消失 送杜少府之任蜀州原文及翻译 送杜少府之任蜀州是王勃写给谁的? 赵子健的荣誉 《乐队的夏天》中刺猬乐队主唱与鼓手的爱情你怎么看? 刺猬乐队鼓手石璐直言青春用来抗争,其乐队的发展有哪些心酸困境?_百度... 黄埔军校 董必武 感恩家书 感恩家书 600字以上 五年级感恩家书400字 怎么写感恩家书?各位高手快回答啊!!! 有关感恩父母的道德家书 感恩家书 800字 感恩家书怎么写 什么是感恩家书? 求一篇“感恩家书”,专门写感谢母亲养育之恩的文章 感恩家书二百字 一封家书话感恩