I use This to create a Config file generator, in other C# Form project I add the ini Class of the Config file generator project, create 2 not visible textboxes and use the ReadValue of the Config generator project to read the urls created by the Config file gen previously; This project uses a Uri to download a file and I want that Uri to be the not visible textbox text (That is a url in the config file) but when I do
IniFile ini = new IniFile("C:\\Config.ini");
TextBox1.Text= ini.IniReadValue("Config","Patch URL");
to write the Uri (private Uri PatchLocation = new Uri(TextBox1.Text);)
Says “A field initializer cannot reference the non-static field, method, or property ‘Downloader.Form1.TextBox1′”.
What I need to do for make the Uri be the TextBox text then?
Hope someone could help me, because I really need to do that. Thanks in advance.
Instead of
private Uri PatchLocation = new Uri(TextBox1.Text);tryBasically, the code you have currently is saying “when I initialize this Form1 object, set PatchLocation to what I get from Textbox1” which isn’t what you want – and the compiler won’t let you do it anyway.
The code I’ve given is a property, which means it won’t read the contents of Textbox1 until you try to read
PatchLocation. Every time you try to readPathLocation, it will parse the value out fromTextBox1.Text. It will throw an exception if that value isn’t a valid URI at the time.Edit: Actually, having fully read your question, you’d be much better off at least removing the hidden textbox and using
unless you have a really compelling reason to be using a hidden textbox.