我所拥有的是一个搜索框和4个列表 列表是 banlists 取缔 有限 半限制
现在我要做的是当我从搜索框中拖动一个项目时将其写入一个文本文件旁边有一个数字,具体取决于它添加到哪个列表(完成) 现在我需要知道如何写入某一行 示例
文本文档的工作原理如下
#Built using DevPro card editor. !new
#forbidden
1 0
#limit
1027 1
#semi limit
12376 2
我现在的工作方式现在就像这样打印
#Built using DevPro card editor.
!new
#forbidden
#limit
#semi limit
1 0
1027 1
12376 2
我希望它像第一个例子一样写,所以如果我将一个项目拖到禁止列表中,它会将其写入#forbidden与其他2相同,这就是我目前用于拖放事件的代码
private void List_DragDrop(object sender, DragEventArgs e)
{
int cardid = Int32.Parse((string)e.Data.GetData(DataFormats.Text));
var list = (ListBox)sender;
int indexOfItemUnderMouseToDrop = list.IndexFromPoint(list.PointToClient(new Point(e.X, e.Y)));
if (e.Data.GetDataPresent(DataFormats.StringFormat))
{
if (!BannedList.Items.Contains(e.Data.GetData(DataFormats.Text)) && !LimitedList.Items.Contains(e.Data.GetData(DataFormats.Text))
&& !SemiLimitedList.Items.Contains(e.Data.GetData(DataFormats.Text)))
{
if (indexOfItemUnderMouseToDrop >= 0 && indexOfItemUnderMouseToDrop < list.Items.Count)
{
list.Items.Insert(indexOfItemUnderMouseToDrop, e.Data.GetData(DataFormats.Text));
}
else
{
list.Items.Add(e.Data.GetData(DataFormats.Text));
if (BannedList.Items.Contains(e.Data.GetData(DataFormats.Text)))
{
using (var writer = new StreamWriter("lflist.conf", true))
writer.WriteLine(Program.CardData[cardid].Id + " 0");
}
else if (LimitedList.Items.Contains(e.Data.GetData(DataFormats.Text)))
{
using (var writer = new StreamWriter("lflist.conf", true))
writer.WriteLine(Program.CardData[cardid].Id + " 1");
}
else if (SemiLimitedList.Items.Contains(e.Data.GetData(DataFormats.Text)))
{
using (var writer = new StreamWriter("lflist.conf", true))
writer.WriteLine(Program.CardData[cardid].Id + " 2");
}
}
}
else
{
if (BannedList.Items.Contains(e.Data.GetData(DataFormats.Text)))
MessageBox.Show(Program.CardData[cardid].Name + " is already contained in the Banned list.");
else if (LimitedList.Items.Contains(e.Data.GetData(DataFormats.Text)))
MessageBox.Show(Program.CardData[cardid].Name + " is already contained in the Limited list.");
else if (SemiLimitedList.Items.Contains(e.Data.GetData(DataFormats.Text)))
MessageBox.Show(Program.CardData[cardid].Name + " is already contained in the SemiLimited list.");
}
}
}
所以换句话说问题是我如何让流编写器找到一行并在其下面的行上写