How to pass the textBox file to the variable in another class.



  • введите сюда описание изображения

    Like, TextBox transfer the path to another layer to the variable path?

    public partial class Form1 : Form
    {    
    private void button2_Click(object sender, EventArgs e)
                {
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Title = "Выберите файл";
                    ofd.Filter = "Текстовые файлы|*.txt";
                    if (ofd.ShowDialog() == DialogResult.OK)
                        textBox1.Text = ofd.FileName;
                }
    }
    

    public class text
    {
    public void SplitAndQuery()
    {
    string path = @"D:\text\text.txt";
    char[] separatorLines = { '\n' };
    char[] separatorWords = { ';' };
    string[] lines = File.ReadAllText(path, Encoding.Default).Split(separatorLines, StringSplitOptions.RemoveEmptyEntries);
    for (int i = 0; i <= lines.Length - 1; i++)
    {
    //code
    }
    }
    }



  • public class text
    {
      public void SplitAndQuery(string path)
      {
        char[] separatorLines = { '\n' };
        char[] separatorWords = { ';' };
        string[] lines = File.ReadAllText(path, Encoding.Default).Split(separatorLines, StringSplitOptions.RemoveEmptyEntries);
        for (int i = 0; i <= lines.Length - 1; i++)
        {
          //code
        }
      }
    }
    
    public partial class Form1 : Form
    {    
      ...
      private void button3_Click(object sender, EventArgs e)
      {
        text t = new text();
        t.SplitAndQuery(textBox1.Text);
      }
    }
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2