listview中item与label交互使用

这个博客介绍了如何在ListView控件中实现Item与Label的交互操作,特别是双击编辑功能。通过创建一个自定义的EnhanceListView类,扩展了ListView的功能,包括允许编辑、跟踪鼠标位置、获取编辑框位置等。当用户双击ListView项的某个子项时,会弹出一个TextBox用于编辑文字,完成编辑后更新ListView中的内容。
摘要由CSDN通过智能技术生成

listview中item与label交互使用方法

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

namespace EnhanceListView
{
    public partial class EnhanceListView : ListView
    {
        private TextBox inputBox = new TextBox();   // 输入编辑框
        private bool allowEdit = false;             // 是否允许编辑
        private Point mousePt = new Point(0,0);     // 当前鼠标的位置
        private int selectIndex = -1;               // 当前选中的行
        private int subIndex = -1;                  // 当前选择子项的索引
        private int Offset = 4;                     // 偏移量
        private int itemHeight = 13;

        private const Int32 WM_VSCROLL = 0x115;
        private const Int32 WM_HSCROLL = 0x114;

   
        public EnhanceListView ()
        {
            InitializeComponent();
            this.LabelEdit = false;

            inputBox.BorderStyle = BorderStyle.None;
            inputBox.Multiline = true;
            inputBox.BackColor = Color.LightGray;

            inputBox.LostFocus += new EventHandler( inputBox_LostFocus );
           
        }

        void inputB

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值