Reputation: 21
As you know we don't have session in WinForm. I have several forms (Customer, Service, Operator, ...) in my project, and I take from Operator some values ( operator Name, Operator LastName and Profile Picture address). I want to store this values somewhere in run-time and whenever I need it, I can fetch it from where I stored it.
Is there an easy way to do this ?
Upvotes: 0
Views: 288
Reputation: 188
also you can use project properties like this:
//write
Properties.Setting.Default["key"] = value;
Properties.Setting.Default.Save();
//read
value = Properties.Setting.Default["key"];
Upvotes: 0
Reputation: 5571
I believe that the simplest way to do this is to create a class
that can be accessed from your forms which contains the data you want
Example
// Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace myNameSpace
{
class Class1
{
public static string Name = "";
public static string LastName = "";
public static string ProfilePictureaddress = "";
}
}
Using this, whenever you would like to store or retrieve data, you may use myNameSpace.Class1
. For example, if you would like to store into the Name
, you may use myNameSpace.Class1.Name = "value";
. This will set Name
to value
.
Thanks,
Happy Holidays! :)
Upvotes: 1
Reputation: 3383
I think these are the words of a long time web developer. I hear you my friend. I've been there...
Session object of web programming is just a workaround to work around the problem of saving state in a stateless environment. On the other hand winforms programming does not have this problem. Your application has objects that all keep their state information.
As for passing information from one form to another:
Which one is best? Depends entirely on your business case and application logic.
Upvotes: 1