How to save Back color in windows form application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kamalmahdavi
    New Member
    • Sep 2012
    • 1

    How to save Back color in windows form application

    I wrote this code behind a button
    Code:
    "
    colordialog.showdialog();
    File.WriteAllText("dlg.txt",this.BackColor.Name);
    "
    And I wrote this code in Form Load as well
    "
    this.BackColor = Color.FromName(File.ReadAllText("dlg.txt"));
    "
    but I got an error and I dont know what is this... Any one knows "Control does not support transparent background colors"
    Last edited by Rabbit; Oct 16 '12, 04:27 PM. Reason: Please use code tags when posting code.
  • akshaymahajan
    New Member
    • Sep 2009
    • 12

    #2
    Color bgColor = this.BackGround Color;

    Comment

    • rupali
      New Member
      • Aug 2012
      • 25

      #3
      Hi kamalmahdavi,

      You can try using RGB color as follows:
      on button click
      Code:
       colordialog.ShowDialog();
      File.WriteAllText("dlg.txt", colordialog.Color.ToArgb().ToString());
      this.BackColor = Color.FromArgb(colordialog.Color.ToArgb());
      and on form load
      Code:
      if (File.Exists("dlg.txt"))
      {
          int nARGB = 0;
          int.TryParse(File.ReadAllText("dlg.txt"), out nARGB);
          this.BackColor = Color.FromArgb(nARGB); 
      }
      Last edited by PsychoCoder; Oct 18 '12, 04:48 PM. Reason: Please use code tags <code/> around your code

      Comment

      Working...