C# 如何在特定行中编写代码?
我需要帮助。我不知道如何通过双击项目从列表框中删除项目 我大约1小时前才开始,所以我没有代码可以帮助我 我在网上找不到任何可以帮助我的东西。如果你知道如何做这个或一个教程,请评论 更新1 这是我所有的代码:C# 如何在特定行中编写代码?,c#,.net,winforms,C#,.net,Winforms,我需要帮助。我不知道如何通过双击项目从列表框中删除项目 我大约1小时前才开始,所以我没有代码可以帮助我 我在网上找不到任何可以帮助我的东西。如果你知道如何做这个或一个教程,请评论 更新1 这是我所有的代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using Sys
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Scratch
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//close form
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
//btnWhenClicked
private void btnWhenStart_Click(object sender, EventArgs e)
{
ListItemsBox.Items.Add("When Start");
btnWhenStart.Hide();
string path = @"C:\Users\Estagio\Desktop\MyTest.txt";
//Create And Write File
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("using System;");
}
}
}
//delete ListItemsBox Selected Item
private void ListItemsBox_DoubleClick(object sender, EventArgs e)
{
}
我不知道这是否能帮助你:
更新2
我知道有一个双击事件,但我不知道双击时如何删除项目
更新3
我不能再问更多的问题了,所以我在这里问
我怎样才能像这样在特定的行中编写文本
经验:
然后我还有一个:
private void btnAnotherEdit_Click(object sender, EventArgs e)
{
ListItemsBox.Items.Add("When Start");
btnWhenStart.Hide();
string path = @"C:\MyTest.txt";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
//Here I want some code that put something //between line2 and line 4
}
}
}
我该怎么做?更新
private void ListItemsBox_DoubleClick(object sender, EventArgs e){
DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this item?",
"Warning", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,MessageBoxDefaultButton.Button2);
if (dialogResult == DialogResult.Yes)
{
ListItemsBox.Items.Remove(ListItemsBox.SelectedItem);
}
else if (dialogResult == DialogResult.No)
{
}
}
有人提出了类似的问题:
如果您只想在特定索引中删除一项,请使用:
listBox1.Items.RemoveAt(YOUR INDEX);
WPF、ASP.NET还是Winforms?还有,到目前为止你都做了些什么,你在哪里遇到了困难?添加一些相关的代码…@EJoshuaS标签上清楚地显示它是
c
好吧,从分解你想做的事情开始。看看列表框,你有什么选择。。如果你觉得有些方法听起来比其他方法对这项任务更有用,试一下,看看它们是怎么做的。。如果世界不按你希望的方式运转,它就不会内爆。当你有代码的时候,回到这里,问一些具体的问题。如果没有列表框双击事件,你可以挂接进去……检查你的解决方案
listBox1.Items.RemoveAt(YOUR INDEX);