i am using .net win forms i need to set some common properties globally to my win forms like css in web application
ex
form background color=red
button width =100
Text box width=200
font family=arial
how to do this?
i am using .net win forms i need to set some common properties globally to my win forms like css in web application
ex
form background color=red
button width =100
Text box width=200
font family=arial
how to do this?
Use the App.Config file or the Settings tab in project properties.
how about create a base form that all the other forms inherit. On the base form you can set the common look and feel. then if it is necessary to overwrite the common properties you can do so.
EDIT something like this for the base form.
public partial class BaseForm : Form
{
private Font _font = new Font("Arial", 10);
private Color _backColor = Color.Red;
public BaseForm()
{
InitializeComponent();
}
public override Font Font
{
get { return _font; }
set { _font = value; }
}
public override Color BackColor
{
get { return _backColor; }
set { _backColor = value; }
}
}
and this for the form that you want to display
public partial class Form1 : BaseForm
{
public Form1()
{
InitializeComponent();
}
}
You could create a static class to store them - maybe in a Dictionary perhaps.
Something like this could work:
public static class GlobalData
{
private static Dictionary<string, object> settings;
private static void SetDefaults()
{
settings = new Dictionary<string, object>();
settings.Add("BackgroundColour", "Red");
settings.Add("Width", 100);
}
public static Dictionary<string, object> FormSettings
{
get {
if (settings ==null)
{
SetDefaults();
}
return settings;
}
}
}
EDIT:
You could you use it like this:
this.Width = Convert.ToInt32(GlobalData.FormSettings["Width"].ToString());