Winforms列表框

时间:2017-02-28 08:24:54

标签: c# winforms listbox

我有两种形式。在2形式中,我在textbox中添加mp3文件。关闭2表单后,我想在1表单的列表框中显示文件信息。

2表格:

    private void buttonChooseSong_Click(object sender, EventArgs e)
    {
        OpenFileDialog openfile = new OpenFileDialog();
        openfile.FileName = String.Empty;
        openfile.InitialDirectory = "C:\\";
        openfile.Filter = "MP3 File(*.mp3)|*.mp3";
        openfile.FilterIndex = 2;
        openfile.Multiselect = false;
        if (openfile.ShowDialog() == DialogResult.OK)
        {
            song.Name = openfile.SafeFileName;
            song.Path = openfile.FileName;
            textBoxSongName.Text = openfile.SafeFileName;
            buttonAddSong.Visible = true;
            Song nsong = new Song();
        }
    }
    private void buttonAddSong_Click(object sender, EventArgs e)
    {
        DialogResult = DialogResult.OK;
    }

如何在1表单中显示mp3中的listbox文件信息?

1 个答案:

答案 0 :(得分:0)

我之前遇到过同样的问题。只需转到Form1并右键单击并转到设计器,然后创建 Form1 对象public

像这样:

public System.Windows.Forms.TextBox textBoxSongName;
  

请按照

进行操作

Just follow this