简体   繁体   中英

Saving Controls in C# Windows Application

I am creating an application that creates a list of buttons from video files.

Each button is generated to open the file on click, and then I use an open api (omdb.com) to get the movie posters for each one. However, not only is doing this process each time you launch the application slow, but it is also an unnecessary load on the website.

What is the most efficient way to save a control after it is dynamically generated in the backend.

So far I have tried using Properties.Settings , but without any luck.

SettingsProperty newSetting = new SettingsProperty("Movie_Button");
newSetting.Name = "Movie_Button_" + *an int that I generate*.ToString();
newSetting.Attributes.Add(Width, 200);
//Carry on setting attributes

So far this process hasn't yielded any results, even when just trying to create a SettingsProperty that's just a simple string. And I have tried with and without Properties.Settings.Default.Save() .

Is there a way to save a control created at run time so it carries over to the next launch of the application?

If there is no way to do this, then can someone please help me create the new SettingsProperty to hold a string, or possibly an XML that I could use.

Since I couldn't find a way to save a control, I decided to instead save the images in a new folder and then create an XML containing the path to the image (and some additional information such as title, year, etc.).

To create the XML I used the XmlDocument doc = new XmlDocument(); method, downloaded the images to a folder at the exe path (using Application.ExecutablePath to get the path), then WebClient webclient = new WebClient(); and webclient.DownloadFile(netPath, localPath) to download each image.

Then on form load I regenerate the buttons using the info from the XML.

This method is much faster than my original method of making multiple web requests for the image url or calls to the api.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM