I would like to make a C# application that displays a message when the program starts up, with a button that says "Don't show this message again".
When they click that button, how do I make it not display again the next time the program is ran.
Any and all help would be greatly appreciated.
Also, I'm unsure on how to show a message with a button in it (new to c#) so help on that would be appreciated also.
You could save this choice in the user settings.
You just need to record that setting somewhere that lives beyond the current life of the program.
You can use the Settings part of your project for this.
As for adding such a checkbox or whatever, you probably have to create a new form that looks like a message box.
You will have to store a value indicating the whether the user has clicked the box or not in an xml file, database, etc.
Assuming this is WinForms the message will be a MessageBox or a new Form.
As an alternative to user settings, both the registry and isolated storage provide valid places to store your data. One appeal of isolated storage is that you have a whole mini-file-system at your disposal, which can be convenient for very complex storage. In this specific case, however, either user settings or registry settings will provide maximum simplicity, IMO.
Related
When should I really call the Reload method of the Properties.Settings.Default? Every time when I want to access properties from the persistent storage? Is it really necessary?
Thanks in advance.
The documentation for ApplicationSettingsBase.Reload states:
Refreshes the application settings property values from persistent storage.
So yes, you should call it whenever you want to access properties from the persistent storage. What you didn't ask was:
Do I need to load settings from persistent storage every time I want the value?
The answer to that is no. The value will be cached in the application settings object, so you do not need to reload if you just want the cached value.
The real answer for me is I can't think of a reason to call it at all. I'll tell you why:
There are two types of settings. User settings and application settings. The user settings are changed on a per-user basis and most probably through a UI that belongs to your application itself. If you change the settings within your application, it already knows they have been changed - reload unnecessary.
The application settings should not change after the application has been installed. How should they? Only admins have access to the program files folders at all.
Applications that run outside user space (services) have no GUI and there's no good reason to use user settings for services. Normally you'll change the config file and then restart the service.
The settings are loaded once when the application is started. Should you re-read them every time before you access a setting? No - for the reasons I gave above.
Here is an example of when to use Reload() method:
I have built an editor for those property settings. It is a propertygrid control with a few buttons on a dialog form.
When the user clicks to invoke that editor then key/values from Properties.Settings.Default are shown in the propertygrid.
Now, users can change many properties but if they decide NOT to save those changes, settings have to be reloaded because they are now invalid!
And that is when I use:
((ApplicationSettingsBase)propertyGrid.SelectedObject).Reload();
I am working on a project in C# Winforms and one of the requirements is to allow the user to save various settings versions and give a name for each of them. The idea is to have a form, the user press the button Save Setting, enter a string in the text box for the name for that setting. Later the user can select from a comboBox which settings to use. I already created a standard setting which saves automatically when the user closes the form. Can you please direct me on how to that?
EDIT:
The following forms demonstrate what I would like to achieve.
The user enter some data in the textBoxes (form Main), then save the details giving to this setting the name of setting01 (form Save setting). Then enter some other details and give the name of setting02.
Now the user can use setting01 or setting02, which contain different values for the same textBox.
Can please someone help me with this adventure?
Microsoft Developer Network has a nice tutorial on how to create a database and using it to store and retrieve data here
Hope it helps.
EDIT:
When the data is collected, do:
combobox1.items.add(data_that_was_collected);
I'm trying to help save time at work with for a lot of tedious copy/paste tasks we have.
So, we have a propitiatory CRM (with proper HTML ID's, etc for accessing elements) and I'd like to copy those vales from the CRM to textboxes on other web pages (outside of the CRM, so sites like Twitter, Facebook, Google, etc)
I'm aware browsers limit this for security and I'm open to anything, it can be a C#/C++ application, Adobe AIR, etc. We only use Firefox at work so even an extension would work. (We do have GreaseMonkey installed so if that's usable too, sweet).
So, any ideas on how to copy values from one web page to another? Ideally, I'm looking to click a button and have it auto-populate fields. If that button has to launch the web pages that need to be copied over to, that's fine.
Example: Copy customers Username from our CRM, paste it in Facebook's Username field when creating a new account.
UPDATE: To answer a user below, the HTML elements on each domain have specific HTML ID's. The data won't need to be manipulated or cleaned up, just a simple copy from ourCRM.com to facebook.com / twitter.com
Ruby Mechanize is a good bet for scraping the data. Then you can store it and post it however you please.
First, I'd suggest that you more clearly define exactly what it is you're looking to do. I read this as you're trying to take some unstructured data from Point A and copy it to Point B. Do the names of these fields remain constant every time you do the operation? Do you need to simply pull any textbox elements from the page and copy them all over? Do some sort of filtering of this data before writing it over?
Once you've got a clear idea of the requirements, if you go the C# route, I'd use something like SimpleBrowser. Judging by the example on their Github page, you could give it the URL of the page you're looking to copy, then name each of the fields you're looking to obtain the value of, perhaps store these in an IDictionary, then open a new URL and copy those values back into the page (and submit the form).
Alternatively, if you don't know the names of the fields, perhaps there's a provided function in that or a similar project that will allow you to simply enumerate all the text fields on the page and retrieve the values for all of them. Then you'd simply apply some logic of your own to filter those options down to whatever is on the destination form.
SO we thought of an easier way to do this (in case anyone else runs into this issue).
1) From our CRM, we added a "Sign up for Facebook" button
2) The button opens a new window with GET variables in the URL
3) Use a greasemonkey script to read those GET variables and fill in textbox values
4) SUCCESS!
Simple, took about 10 minutes to get working. Thanks for you suggestions.
I'd like to give the users of my ASP.NET website the possibility to write/change texts on the start site.
The texts are constantly changing and are therefore not static.
The texts are on the start page of the site, so saving it to the database wouldn't be the best choice, right? Because there would be a database access at every page call.
So my question is: What is the best practice to save this texts? Should I save it in the database? In a text file? xml file? In the web.config?
Edit: An example for the usage:
There is a "contact" area on the start page, the admin should be able to modifiy the content of this contact area. So this data not static, it should be editable.
you can, of course, do many different things, but the normal thing is to just store it in a database and use a caching mechanism if you are concerned about round trips to database.
When a user clicks the submit, button it has to go to the database. Edits and small changing will happen normally. Once the submition, is clicked, it has to go somewhere and a database call needs to happen. You can save it in session, but that will go away if the user goes away.
If it is not a permanent data why not store it in Session?
I have a simple WinForms GUI with multiple TextBoxes, CheckBoxes, and RadioButtons for the user to enter / modify data. Everything is loaded / saved from a SQL Server database. How do I warn the user when he wants to close the GUI? Do I query SQL to get data and compare it with what is in the GUI and if there are any differences I simply warn the user? Or is there a better way? Also it's possible that during that time the user had a window open someone came in and changed something from another computer and the SQL Data would be different than what was orginally loaded into WinForms.
Regarding local changes:
Keep a local flag that you set to true on any changes for a general message.
You could have a dictionary if you want to keep track of specific changes.
To prevent other users from overwriting the data, you could use locking, and prevent others from opening that record, or only allow them to open in read only.
You can use a time stamp on that record, and check if it has changed since you last read it, then warn the user that the data is no longer the same.