C# Winform ListView实现单元格双击复制内容到剪贴板

        private void listView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListView listview = (ListView)sender;
            ListViewItem lstrow = listview.GetItemAt(e.X, e.Y);
            System.Windows.Forms.ListViewItem.ListViewSubItem lstcol = lstrow.GetSubItemAt(e.X, e.Y);
            string strText = lstcol.Text;
            try
            {
                Clipboard.SetDataObject(strText);
                notifyIcon1.Visible = true;
                string info = string.Format("内容【{0}】已经复制到剪贴板", strText);
                notifyIcon1.ShowBalloonTip(1500, "提示", info, ToolTipIcon.Info);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


图示:双击“塑胶工程师”单元格会将内容复制到剪贴板中,并在右下角冒泡提示(使用NotifyIcon时必须设置ICON属性,否则不显示)


posted @ 2017-02-18 17:41  网事  阅读(1332)  评论(0编辑  收藏  举报