Solved

Saving fontname and fontsize to the settings-file.

Posted on 2011-09-02
4
290 Views
Last Modified: 2013-12-17
Dear Experts,

I have a fontDialog1 on my form that can be called by pressing on a button.
The user than can choose his/her favorite fontname and fontsize.
What I would like is to save the fontname and size to the settings-file
when the OK-button of the fontdialog1 is pressed.

How can I do that?

private void btnLetType_Click(object sender, EventArgs e)
        {
            if (fontDialog1.ShowDialog() == DialogResult.OK)
            {
                  //
            }
        }

peter
0
Comment
Question by:peterkiers
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
x77 earned 500 total points
ID: 36474494
You can Create a Settings  variable of Type Font (System.Drawing.font)

Go Project Properties, Settings Tab.
Add a new  entry
   Name  - MyFont
   Type    - System.Drawing.font
    Value (using ...), Select a Font on DialogFont (Sample: Microsoft Sans Serif; 11,25pt; style=Bold)

Now you can use:

   My.Settings.MyFont = fontDialog1.Font
   My.Settings.Save


value is save like:

       <WindowsApplication1.My.MySettings>
            <setting name="MyFont" serializeAs="String">
                <value>Microsoft Sans Serif, 11.25pt, style=Bold</value>
            </setting>
        </WindowsApplication1.My.MySettings>
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36474511
How is this question different than your previous question?
0
 
LVL 1

Author Comment

by:peterkiers
ID: 36474553
I have this:

        private void button1_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.MyFont = fontDialog1.Font;
          Properties.Settings.Default.Save();
        }
        //*-----------------------------------------------------------*//
        private void Settings_Load(object sender, EventArgs e)
        {
            fontDialog1.Font = Properties.Settings.Default.MyFont;
        }
        //*-----------------------------------------------------------*//

and it works. Thank you.

Peter
0
 
LVL 15

Expert Comment

by:x77
ID: 36474590
Csharp:

            Properties.Settings.Default.MyFont = fontDialog1.Font;
            Properties.Settings.Default.Save();
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question