So I'm making a plugin for Visual Studio that opens Internet Explorer and goes to a specified website.
How can I make it so that you can right click the button or something and bring up options and enter in a new URL that is then saved? Not sure how I can do this!
Thanks for any help
You can create a new setting at design time by using the Settings designer. The Settings designer is a grid-style interface that allows you to create new settings and specify properties for those settings. You must specify Name, Value, Type and Scope for your new settings. Once a setting is created, it is accessible in code.
In Solution Explorer, expand the Properties node of your project.
Double-click the .settings file in which you want to add a new setting. The default name for this file is Settings.settings. In the Settings designer, set the Name, Value, Type, and Scope for your setting. Each row represents a single setting.
How to read settings
Via the Properties.Settings.Default member.
The following example shows how to assign myName setting to a string Name property.
this.Name = Properties.Settings.Default.myName;
How to write settings
Properties.Settings.Default.myName = "Robert"
If you want to persist the changes to the settings between application sessions, call the Save method, as shown below:
Properties.Settings.Default.Save();
Related
Whenever we update some user setting by calling the following code (Here the property name is given as 'SomeProperty').The following code runs on a button click eventHandler.
Settings.Default.SomeProperty = TextBox1.Text;
And save it by calling the save method like the following code
Settings.Default.Save();
[N.B: I am not leaving the TextBox1 empty, (i.e. initially I had initialized, SomeProperty's value as 'simple' and type as 'String' and obviously UserScope)
And before I click the saving button I am writing 'Complex'- in TextBox1]
The value of 'SomeProperty' is changed, and I can see it as I load that value in a label in next run of the application. But when I try to manually find the updated value of 'SomeProperty' from the 'app.config'
or 'app.exe.config' file I find that the value assigned to 'SomeProperty' while creating it is there(Not updated).
Can anyone please tell me where is the updated version of the .config file is saved?
What I have tried:
I have no idea about why this is happening, and what is the remedy..
According to the documentation:
Settings that are application-scoped are read-only, and can only be changed at design time or by altering the .config file in between application sessions. Settings that are user-scoped, however, can be written at run time just as you would change any property value. The new value persists for the duration of the application session. You can persist the changes to the settings between application sessions by calling the Save method.
When I create a win-form project and add some components to the form by drag them from the tool box, everything works nice, binding codes are generated but components' names are given by default, like button1, button2... I think they are not appropriate for code maintenance.
So I want to name them like button_add, button_del and some name like that, more meaningful, so I change the name in the attribute box of the component, but I don't see any change in the code.
Can some one show me how to do this?
Usually such changes should be performed automatically by Visual Studio when you change the control's name. The only thing not being renamed are event handlers.
For example: If you add a Click handler to a button named button1 the method will be named button1_Click by Visual Studio. The method name will not change if you rename the button to button_add. This is probably because you can name the method yourself, for example ItWasPressed - how should Visual Studio handle this? If it renamed the method, you'd complain that Visual Studio turned your nicely named method into button_add_Click automatically :-)
You can simplify this refactoring-step by modifying the method name, then pressing Shift+Alt+F10 and selecting the respective option to rename all occurrances.
However, all other references in code will be changed, like for example button1.Enabled = false; will be changed to button_add.Enabled = false;.
Problem:
WPF application, no database.
It has main window, ribbon and there a button which opens new window, which has few checkboxes, textboxes which allows to set up parameteres how the job is gonna be done.
Now, how is the best way/best practice to store/save those parameteres and use them?
Settings class with properties and then creating global object when application starts? Then I could access this object in child window, save settings, then I could use such setting in MainWindow?
I guess it's a problem with OOP understanding.
Once I create Settings setting = new Settings(); in ChildWindow it is not accessible once window is closed.
But then, I've read somewhere to never set global objects and share them between windows.
Should I create Settings setting = new Settings() in MainWindow and then pass it in the constructor of ChildWindow? It could be like:
Settings setting = new Settings();
ChildWindow child = newChildWindow(setting);
Then in the new ChildWindow I could set up setting properties. As far as I know if you pass an object as a parameter it has reference to original object, so setting up properties in ChildWindow would affect MainWindow Settings object?
I know, the question is a bit messy, not sure if it's right place to ask such questions
If you just have a small number of fields to store, then using the built in User scoped Settings would be the easiest way. They are stored in XML files and each user will have their own settings file in a hidden data folder. You can set them up in a dialog window in Visual Studio and then refer to them simply in your code like this:
this.BackColor = Properties.Settings.Default.myColor;
Saving them is just as easy:
Properties.Settings.Default.Save();
These examples are from the following linked page... to find out full details, take a look at the Using Settings in C# page on MSDN.
I am using Devexpress and WPF. There are different themes user can apply provided by devexpress.
ThemeManager.ApplicationThemeName = Theme.MetropolisDarkName; //MetropolisDarkName is name of a Theme.
In my application user can select any theme to apply. But if he closes application and opens it again, Themes changes doesn't same. I want that these changes should be saved so if user after applying theme will open it again, changes should be saved and apply.
Should i have to save name of Theme in database or is there any other way to solve this. I need your suggestions.
Thank you.
The super easy way to do this in Visual Studio is to add a new .settings file to your project, and define a setting of ThemeName. You can find the settings template under General in the C# project Templates. The settings file itself is just a designer with an underlying class of type System.Configuration.ApplicationSettingsBase.
The class created saves setting values to the app.config. The neat thing is you can define settings as application or user, so different users using the application on the same machine can have their own custom settings.
The following assumes that you created the file Settings.settings with an entry called ThemeName of type string.
Get the theme from Settings
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ThemeManager.ApplicationThemeName = Properties.Settings.Default.ThemeName;
}
Save the Theme
public void SetTheme(string themeName) {
ThemeManager.ApplicationThemeName = themeName;
Properties.Settings.Default.ThemeName = themeName;
Properties.Settings.Default.Save();
}
Settings on MSDN
I have a C# Dialog based app. I want to save the preferences/settings the user choose, so that I could reload them in the next run.
I am new to C#, may be this is something quite basic but I do not know.
Do I have to explicitly write them to a file like ini or something ? or is there a built in way to do that.
The kind of config data is like checkboxes selelected, numericUpDOwn, checkedListbox - checked items etc
Select the control in the designer. Scroll all the way up in the Properties window and expand (ApplicationSettings). Click the indicated button to open a dialog. Select the property whose value should be persisted (like Checked for a check box) and click New in the dropdown.
Be a bit careful, not all properties are suitable to be persisted like this. An example is the form's Size. You don't want to store the size when the form is minimized or maximized, that size won't restore well. You need to do this by adding the setting in the Settings designer an only write it when the control is in the right state. In the case of Size, that's when the Resize event runs and the WindowState is Normal.
After you create the application settings as the other answers suggest, make sure you don't forget to call Properties.Settings.Default.Save(), for example:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Properties.Settings.Default.Save()
}
To Create a New Setting at Design Time
In Solution Explorer, expand the Properties node of your project.
In Solution Explorer, double-click the .settings file in which you want to add a new setting. The default name for this file is Settings.settings.
In the Settings designer, set the Name, Type, Scope, and Value for your setting. Each row represents a single settings
For more info you can refer here
You should use application settings. These will persist their values after you close your application, and you will be able to read from them when the program starts back up again.