gpt4 book ai didi

c# - 如何将鼠标从文本框中选择的文本添加到列表

转载 作者:行者123 更新时间:2023-11-30 22:15:23 26 4
gpt4 key购买 nike

我有一个多行 TextBox,我希望我通过鼠标从 TextBox 中选择的文本应该添加到 List一旦松开鼠标左键。

列表定义为

 public List<string> PtagName = new List<string>();

我附上了关于这个问题的图片 enter image description here

如图所示,无论我通过鼠标左键单击 TextBox 选择什么,它都应该添加到列表中

最佳答案

到此为止:希望对您有所帮助。

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace TextBoxLines
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public List<string> PtagName = new List<string>();

private void textBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (textBox1.SelectedText.Length > 0)
{
string[] lines = textBox1.SelectedText.Split('\n');
foreach (var line in lines)
{
PtagName.Add(line);
}
}
foreach (var line in PtagName)
MessageBox.Show(line);

PtagName.Clear();
}
}
}
}

关于c# - 如何将鼠标从文本框中选择的文本添加到列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17987548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com