简体   繁体   English

C#Visual Studio文本框转换为文本文件

[英]c# visual studio textbox into textfile

I'm new with visual studio c#. 我是Visual Studio C#的新手。 This is maybe a stupid question but I find no solution for next code. 这可能是一个愚蠢的问题,但是我找不到下一个代码的解决方案。 I'm trying to import a textbox (this works) and I want to import these into a text file. 我正在尝试导入文本框(这可行),并且我想将它们导入文本文件。

    private void Rbalast_TextChanged(object sender, EventArgs e)
    {
        string balastR = Rbalast.Text;

    }
    private void EXPORT_Click(object sender, EventArgs e)
    {

    System.IO.StreamWriter file = new System.IO.StreamWriter("d:/VAR/200_runSheet_Tests/.txt");
    file.Write(balastR);
    file.Close();
}

I think it is because of the private void but I find no solution to change this. 我认为这是因为存在私人空白,但我找不到解决此问题的解决方案。

Your problem here is the lack of knowledge in variable scope. 您的问题是在可变范围内缺乏知识。

To solve this, you have two options. 要解决此问题,您有两个选择。

1) place the variable balastR above the method Rbalast_TextChanged in the class scope, which will allow you to use it in the EXPORT_Click as you are currently doing. 1)放置可变balastR上述方法Rbalast_TextChanged在类范围内,这将允许你在使用它EXPORT_Click你现在正在做。

2) Go by PoweredByOrange suggestion, and just replace file.Write(balastR); 2)遵循PoweredByOrange建议,只替换file.Write(balastR); with file.Write(Rbalast.Text); file.Write(Rbalast.Text);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM