Click here to Skip to main content
15,897,226 members
Articles / Programming Languages / Visual Basic

AGE, Another Graphic Engine in .NET

Rate me:
Please Sign up or sign in to vote.
4.96/5 (36 votes)
10 May 2007CPOL8 min read 136.6K   5.9K   170  
A library that allows some GDI+ manipulation at runtime in an easy way
/////////////////////////////////////////////////////////////////////////////////
// NeoDataType Another Graphic Engine
// --------------------
// Project Copyright (C)    : Fabio Zanetta, email: support@neodatatype.net
// Portions Copyright (C)   : Microsoft Corporation. All Rights Reserved.
// License                  : docs/license.txt
// ------------------------------------------------------------------------------
// File created by          : Fabio Zanetta, email: support@neodatatype.net
// ------------------------------------------------------------------------------
// Please, if you modify some parts of this file mark them as described in
// docs/modify_guidelines.txt
/////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using System.Globalization;
using System.Reflection;

namespace NeoDataType.Documents
{

    #region ColorFormatter
    /// <summary>
    /// Used to format a System.Drawing.Color into a string
    /// and vice-versa
    /// </summary>
    public class ColorFormatter : IObjectFormatter
    {
        #region IObjectFormatter Membri di

        public string ToString(object value)
        {
            return ((System.Drawing.Color)value).ToArgb().ToString();
        }

        public object Parse(string value)
        {
            return System.Drawing.Color.FromArgb((int)Converter.FromString(value, typeof(int)));
        }

        #endregion
    }
    #endregion

    #region FontFormatter
    /// <summary>
    /// Used to format a System.Drawing.Font into a string
    /// and vice-versa
    /// </summary>
    public class FontFormatter : IObjectFormatter
    {
        #region IObjectFormatter Membri di

        public string ToString(object value)
        {
            System.Drawing.Font f = (System.Drawing.Font)value;
            return f.FontFamily.Name + ";" +
                   Converter.ToString(f.Size) + ";" +
                   f.Style.ToString() + ";" +
				   f.Unit.ToString();
        }

        public object Parse(string value)
        {
            string[] fp = value.Split(new char[] { ';' });
            float size = (float)Converter.FromString(fp[1], typeof(float));
            System.Drawing.FontStyle fs = (System.Drawing.FontStyle)Enum.Parse(typeof(System.Drawing.FontStyle), fp[2]);
            System.Drawing.GraphicsUnit gu;
			if (fp.Length > 3)
                gu = (System.Drawing.GraphicsUnit)Enum.Parse(typeof(System.Drawing.GraphicsUnit), fp[3]);
			else
                gu = System.Drawing.GraphicsUnit.Point;
            return new System.Drawing.Font(fp[0], size, fs, gu); 
        }

        #endregion
    }
    #endregion

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions