【发布时间】:2015-02-22 19:13:54
【问题描述】:
如何从文本文件中读取随机行并将标签中的文本更改为该随机行,然后在我已编码(如下)的拖放后,标签将更改文本。语言是c#。我是初学者,如果这是一个愚蠢的问题,我深表歉意。
private void txt_carbs_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = e.AllowedEffect;
// check if the held data format is text
// if it is text allow the effect
else
e.Effect = DragDropEffects.None;
// if it is not text do nothing
}
private void txt_protien_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = e.AllowedEffect;
// check if the held data format is text
// if it is text allow the effect
else
e.Effect = DragDropEffects.None;
// if it is not text do nothing
}
private void txt_fats_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = e.AllowedEffect;
// check if the held data format is text
// if it is text allow the effect
else
e.Effect = DragDropEffects.None;
// if it is not text do nothing
}
private void txt_fats_DragDrop(object sender, DragEventArgs e)
{
txt_fats.Text += e.Data.GetData(DataFormats.Text).ToString();
//add the text into the text box
}
private void txt_protien_DragDrop(object sender, DragEventArgs e)
{
txt_protien.Text += e.Data.GetData(DataFormats.Text).ToString();
//add the text into the text box
}
private void txt_carbs_DragDrop(object sender, DragEventArgs e)
{
txt_carbs.Text += e.Data.GetData(DataFormats.Text).ToString();
//add the text into the text box
}
private void lbl_term_MouseDown(object sender, MouseEventArgs e)
{
lbl_term.DoDragDrop(lbl_term.Text, DragDropEffects.Copy);
// get the text from the label
}
这也是我更改标签文本的方式,但这不是随机的
StreamReader score =
new StreamReader(file_location);
label10.Text = score.ReadLine();
【问题讨论】:
标签: c# random label text-files