2015-09-19 116 views
0

我有一个按钮,路径保存到一个文件夹中的一个文本框中的文本,我想将它保存在C#中的设置文件,但我不断收到错误:将路径转换为字符串?

Cannot implicitly convert type "System.windows.type.textbox" to String

现在代码我使用设置文本框的路径是:

folderBrowserDialog1.ShowDialog(); 
textBox1.Text = folderBrowserDialog1.SelectedPath; 

而且我使用它保存到设置文件的代码是:

string pathh = textBox1; 
Properties.Settings.Default.Path = textBox1; 

即使我更换

Properties.Settings.Default.Path = textBox1 
Properties.Settings.Default.Path = pathh 

我得到了同样的错误。有人能告诉我如何解决这个问题吗?

回答

2

你的路径不是文本,但文本框的文字,所以更改

Properties.Settings.Default.Path = textBox1; 

Properties.Settings.Default.Path = textBox1.Text; 
1

使用TextBox控制的Text属性类,这是String类型的像下面。你正在尝试的是将一个控件实例分配给字符串,因此接收错误的原因是它们的类型不同。

string pathh = textBox1.Text;