Save with the controls of the form - c#

I have a windows application developed in c sharp with setup file generated. For that file I need to save the form with the controls and text with in controls. This application don't have any database. Can you suggest an extension method and also how to save the form?

There is no way to save controls. What you can do is create a serializable class to keep Form's data. You can serialize those settings and save. When you load the application next time you can deserialize and load those values to the form controls. This is one of the ways of doing it if you don't use a database to store data.

Related

Dynamic Forms Builder, CRUD Submissions, Multiple Files Upload Using ASP.NET MVC

In our current application there is a new requirement of our client.As they told that they need n numbers of forms at different stages of their business and those are changing time to time. Even a new forms can be added. Their requirement is once the product is delivered to them they will not come back to us again and again for each change and will create those form by their own.
Simply they want a user interface where they can create the form by drag and drop manner.
What they want :
In our application there will be a form building section where a non technical person can be able to create a form.
Mapping the controls with existing data of their existing database so that the form is populated with the corresponding data ( data will be inserted into the database using another user interface).
Once the data is populated they will take the print out of the filled up form and will proceed as per their business flow.
As they introduce new form time to time we can't provide any predefined template to them and they are not agree to design the form in HTML.
Is there any way of doing this in Asp.Net MVC (without using any CMS ).
there are a number of asp.net forms builders. And I been wanting to build my own for years. (you store the control, the location etc in a database, or even as xml, and then on page load, read the xml, and crank out the controls and layout into the page. We all built these for desktop, and you can do the same for the web.
The open source evolutility project has a FANTASTIC system for this, but it does NOT include the GUI part. But, it would be a good start. You would have to build the GUI part, but the rendering part, and save of the forms layout is all done for you. So, your forms builder would offer a set of controls to drop and move around in the form. When you save, you would have a corresponding "xml" markup bit that you save to the one "forms layout" file. On forms load, you read that xml file and produce the form (that's the part evolutility does for you). So, you need the part that has each control in a tool box (along with the xml for that control). you drop control into form, and add the xml to the "form layout in xml".
As I stated, evolutility has all the parts to render forms and layout and place controls on the final finished form for display - it just don't have a GUI for doing this part.
You can look at the project here:
http://evolutility.com/
there are others. But, it really depends on how complex of a form builder or content builder you wish to make.
But, a xml, or json based layout and definition of the controls placed on a page is a good start. You could store such "layout" information in a database. Heck have a classic master to child table, and thus save each control in evolutiity format, and simple append then all together, and then have evolutility render that xml into a working form for you.
I don't know of a open source project that combines both the "layout" and "define" of the controls AND ALSO has a GUI to build the forms. But, to be fair, the hard part (how to layout, and how to have each control defined in some json (or xml) is done for you.

Best practices with saving settings data

I've got a main class which on user event shows the settings window. There are some textboxes, radiobuttons etc. After pressing the Save button, I want to store the data to some file.
I think that the saving process should be inside the main class and settings window only takes care of displaying the current config data, validate the new data and then send them back to the main class. Is this right?
How can I "send" the current config data from main class (which knows where the config file is etc.) to the window and then "send" the new data from window to main class to be stored?
Thanks
In WPF you can use Properties.Settings (Best solution for storing any application settings). See this.
Or you can create your own settings file, as an example, you may create xml file, and store your data into it.
See:
XmlSerializer
DataContractSerializer

What is the better way to save state of checkboxes/textboxes? Saving these in ".settings" file is better?

I want to save state of lot of CheckBoxes (checked/unchecked) and some TextBoxes on a WPF screen in .settings file (As I do not want to use database/filing).
Whether I have to save all these checkboxes and textboxes in setings file or there is a better way to do it?
If this is to remember the state of controls in an application, I would definitely use user settings to store this. Creating a separate setting for each control can be time consuming initially, but it makes life a little easier later. However, if you don't want to do this, you can simply create a custom settings class with a public property for each control and then simply use an instance of that class as your one savable setting.

To get a list of all control text/caption of a Visual Studio solution

I have a VS Solution in that my project contains something around 160 Forms. Now I want to get the Control's text property from all the forms.
Why I want to do is my application is in English Language. My client asked me to convert the whole software into other languages also. Now he wants me to provide him list of all menu and other controls in a Excel or XML sheet from where he will translate everything.
SO is there any mechanism available which can read all of my forms and its control and save text/caption of every item in a external file or may be in any medium.
Is it possible. Looking for fellow support. Regards.
ADD1:
Like I have a MDI form and its designer contains this.mnu_recycle.Text = "Recycle";
Likeways we have n number of .Text items. I just want a list of all of them.
Create some code that creates an instance of each form then loops through all the controls getting the text and name of the control. Write the info (Form name, control name, control text) to a csv file or generate a resource file which can be translated. You can then write a small app to change the form code files to use resource files.
Programmatically creating a resource file
http://msdn.microsoft.com/en-us/library/gg418542.aspx
Resource files will make your application be easier to translate to other languages take a look at these
C#: How to bind the text of a winforms button to a resource
What would be the easiest way to generate new localized resource files?
How to load C# winform strings from resource file without rebuild

Storing a DockPanel in a settings file

I am attempting to store a DevExpress DockPanel in a settings file. Everything appears to work in the save function, but when I go to load it upon starting the application, The Settings.Default.WebLayoutPanel variable is null: here is the save:
Settings.Default.VisibilitySwitchesPanel = _visibilitySwitchesPanel;
and here is the load
if (Settings.Default.WebLayoutPanel != null)
{
_webLayoutPanel = Settings.Default.WebLayoutPanel;
}
Any Ideas as to why it is null?
You should not save the Control instances directly into the application settings. It's a wrong way. You should save the specific settings of these controls using custom serializable wrapper and then restore these settings. Here is a useful links:
Windows Forms - Creating and Persisting Custom User Settings in C#
Using Application Settings and User Settings
As for DevExpress DockPanels, when you want to save/restore the docking layout you should use the embedded save/restore functionality: Saving and Restoring the Layout of Dock Panels

Categories

Resources