-2

complete noob here, i thought i'd follow a tutorial for a web browser to help teach me some stuff. i've done that, and it works, but now i want to get more advanced with it.

Ive got a tab page control, one tab is browser, and one is bookmarks. i want the bookmarks section to be interactive. so, to add in subtabs for the bookmarks tab page. i want to give the user control, to add/remove tabs. but most importantly, add bookmark buttons.

so my thought was to call an If function, to check a variable on any button clicked.

String UrlCheck; If (UrlCheck => "")

But im stuck. i need this variable remembered the next time this application is executed so setting UrlCheck to "" won't work.

Any ideas how i would go about this? please?

Jack Smith
  • 33
  • 6
  • Hi, what you are using. Is it wpf? winforms? something else? – Tim Rutter Oct 27 '19 at 07:11
  • apologies, yes, VS Windows Form C# i've no idea how to go about this, but eager to learn. :-) – Jack Smith Oct 27 '19 at 07:13
  • thanks not that it matters that much in this case but the more information you give the more help you may get. – Tim Rutter Oct 27 '19 at 07:16
  • It doesn't really matter what you're doing it in, the answer will be the same. You save the data to a form of persistent storage that the app loads the next time it runs. This can be a text file, a config file, a database file, a key-value pair file. It can be stored in the same folder as the program, in the documents folder, in the registry, in the cloud via an API. It can be plain text, XML, JSON, YAML, or CSV. All these lists go on and on. There are a thousand and one ways on specifically how to do it, and which one you choose depends on your needs, capabilities, and personal preference. – Abion47 Oct 27 '19 at 07:17
  • I think you just want to store a value in settings, see the item I linked – Tim Rutter Oct 27 '19 at 07:17
  • Thanks Tim i'll take a read, on another note, how would i allow the user to add/remove buttons and tab pages? obviously i can add them in design mode, but presumably there is code to allow this functionality once compiled? – Jack Smith Oct 27 '19 at 07:20
  • that's actually really helpful, i love facts like this! thanks Abion47 – Jack Smith Oct 27 '19 at 07:21
  • If you're literally saving bookmarks, look into how other browsers do it. You might want to do it the same way. It is trivially easy to share bookmarks with IE, for example, because they are just shortcuts in a folder. – John Wu Oct 27 '19 at 07:56

1 Answers1

0

You can use application settings behavior provided by the Framework and Visual Studio designer using the settings.settings file in the properties section of the project in the solution explorer.

You create a parameter of string type for example MyStringParameter and you read and write access it like that:

  • Settings are automatically loaded at the program startup.

  • Somewhere to modify or read the value:

    strValueYouNeed = Properties.Settings.Default.MyStringParameter;
    // ...
    Properties.Settings.Default.MyStringParameter = strValueYouWant;
    
  • Somewhere just after the parameter modified or at the program end or form closed event:

    Properties.Settings.Default.Save();
    

Or you can use a hand-made application settings file where you can put what you want by code as well as control the folder location:

How to create a hand-made application settings file

How to initialize user app data and document path

You can also use a simple text file to store a collection.

If it is a string list you simply write:

var list = new List<string>();

// ...

File.WriteAllLines(strPath, list.ToArray());

WriteAllLines takes in fact a string[] as second argument.

To read it, you write:

var list = File.ReadAllLines(strPath)/*.ToList()*/;