Click here to Skip to main content
15,881,882 members
Articles / Multimedia / GDI+

100% Reflective Class Diagram Creation Tool

Rate me:
Please Sign up or sign in to vote.
4.98/5 (498 votes)
14 Jun 2011CPOL28 min read 1.8M   39.6K   1.2K  
100% Reflective Class Diagram Creation Tool
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

namespace AutoDiagramer
{
    #region frmSettings CLASS
    /// <summary>
    /// An settings form to allow the user to tailor how the diagram is created
    /// </summary>
    public partial class frmSettings : Form
    {
        #region Constructor 
        /// <summary>
        /// Creates a new frmSettings object
        /// </summary>
        public frmSettings()
        {
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw |
                     ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);
            pnlSettingsScroll.Focus();
        }
        #endregion
        #region Private Methods
        /// <summary>
        /// Custom painted panel
        /// </summary>
        /// <param name="sender">pnlSettingsBanner</param>
        /// <param name="e">the event args</param>   
        private void pnlSettingsBanner_Paint(object sender, PaintEventArgs e)
        {
            //call base class 
            base.OnPaint(e);
            //draw the rectangle
            Graphics g = e.Graphics;
            Pen p_Black = new Pen(Color.Black);
            Rectangle rBounds = new Rectangle(0, 0, pnlSettingsBanner.Size.Width, 
                pnlSettingsBanner.Size.Height);
            g.DrawRectangle(p_Black, rBounds);
            Brush b_Divot = new HatchBrush(HatchStyle.Divot, Color.Gray, Color.Black);
            g.FillRectangle(b_Divot, rBounds);
            //draw the text
            Brush b_White = new SolidBrush(Color.White);
            Font fnt = new Font("Tahoma", 8, FontStyle.Bold);
            // Draw string to screen.
            g.DrawString("Configure your settings here", fnt, b_White, new Point(5, 2));
        }

        /// <summary>
        /// Read the global vars within the <see cref="Program">Program</see>
        ///  class into the form values
        /// </summary>
        /// <param name="sender">frmSettings</param>
        /// <param name="e">the event args</param>        
        private void frmSettings_Load(object sender, EventArgs e)
        {
            //read the global vars into the form values
            chkInterfaces.Checked = Program._IncludeInterfaces;
            chkConstructors.Checked = Program._FullConstructorDescribe;
            chkFieldTypes.Checked = Program._IncludeFieldType;
            chkMethArgs.Checked = Program._IncludeMethodArgs;
            chkMethReturns.Checked = Program._IncludeMethodReturnType;
            chkMethPropGet.Checked = Program._ShowPropGetters;
            chkMethPropSet.Checked = Program._ShowPropSetters;
            chkPropTypes.Checked = Program._IncludePropValues;
            chkEvents.Checked = Program._IncludeEventType;
            chkEnums.Checked = Program._AllowEnumOnDiagram;
            chkDelegates.Checked = Program._AllowDelegatesOnDiagram;
            nudColumns.Value = Program._MAX_Columns;
            pnlClassStartCurrColor.BackColor = Program._ClassStartColor;
            pnlClassEndCurrColor.BackColor = Program._ClassEndColor;
            pnlClassBorderCurrColor.BackColor = Program._ClassBorderColor;
            cmbAccess.SelectedItem = Program._BindingFlags;

        }
        
        /// <summary>
        /// BtnOk clicked, save the settings
        /// </summary>
        /// <param name="sender">The btnOk button</param>
        /// <param name="e">the event args</param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            //apply the form values to the global vars
            Program._IncludeInterfaces = chkInterfaces.Checked;
            Program._FullConstructorDescribe = chkConstructors.Checked;
            Program._IncludeFieldType = chkFieldTypes.Checked;
            Program._IncludeMethodArgs = chkMethArgs.Checked;
            Program._IncludeMethodReturnType = chkMethReturns.Checked;
            Program._ShowPropGetters = chkMethPropGet.Checked;
            Program._ShowPropSetters = chkMethPropSet.Checked;
            Program._IncludePropValues = chkPropTypes.Checked;
            Program._IncludeEventType = chkEvents.Checked;
            Program._AllowEnumOnDiagram = chkEnums.Checked;
            Program._AllowDelegatesOnDiagram = chkDelegates.Checked;
            Program._MAX_Columns = (int)nudColumns.Value;
            Program._ClassStartColor = pnlClassStartCurrColor.BackColor;
            Program._ClassEndColor = pnlClassEndCurrColor.BackColor;
            Program._ClassBorderColor = pnlClassBorderCurrColor.BackColor;
            Program._BindingFlags = cmbAccess.SelectedItem.ToString();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        /// <summary>
        /// btnCancel clicked, Closes this form
        /// </summary>
        /// <param name="sender">the btnCancel button</param>
        /// <param name="e">the event args</param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        /// <summary>
        /// frmSettings shown, Set focus to the scrollable panel area
        /// </summary>
        /// <param name="sender">the frmSettings form</param>
        /// <param name="e">the event args</param>
        private void frmSettings_Shown(object sender, EventArgs e)
        {
           pnlInterfaces.Focus();
        }

        /// <summary>
        /// lnkClassStartColor clicked, so show a new class start color, color dialog
        /// and if user picks a new color assign it to be the color used to draw classes
        /// in the <see cref="Program">Program</see> class global variables
        /// </summary>
        /// <param name="sender">the lnkClassStartColor hyperlink</param>
        /// <param name="e">the event args</param>
        private void lnkClassStartColor_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ColorDialog cd = new ColorDialog();
            cd.Color = pnlClassStartCurrColor.BackColor;
            if (cd.ShowDialog(this) == DialogResult.OK)
            {
                pnlClassStartCurrColor.BackColor = cd.Color;
                pnlClassStartCurrColor.Invalidate();
            }
        }

        /// <summary>
        /// lnkClassEndColor clicked, so show a new class end color, color dialog
        /// and if user picks a new color assign it to be the color used to draw classes
        /// in the <see cref="Program">Program</see> class global variables
        /// </summary>
        /// <param name="sender">the lnkClassEndColor hyperlink</param>
        /// <param name="e">the event args</param>
        private void lnkClassEndColor_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ColorDialog cd = new ColorDialog();
            cd.Color = pnlClassEndCurrColor.BackColor;
            if (cd.ShowDialog(this) == DialogResult.OK)
            {
                pnlClassEndCurrColor.BackColor = cd.Color;
                pnlClassEndCurrColor.Invalidate();
            }
        }

        /// <summary>
        /// lnkClassBorderColor clicked, so show a new class border color, color dialog
        /// and if user picks a new color assign it to be the color used to draw classes
        /// in the <see cref="Program">Program</see> class global variables
        /// </summary>
        /// <param name="sender">the lnkClassBorderColor hyperlink</param>
        /// <param name="e">the event args</param>
        private void lnkClassBorderColor_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ColorDialog cd = new ColorDialog();
            cd.Color = pnlClassBorderCurrColor.BackColor;
            if (cd.ShowDialog(this) == DialogResult.OK)
            {
                pnlClassBorderCurrColor.BackColor = cd.Color;
                pnlClassBorderCurrColor.Invalidate();
            }
        }
        #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
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)

- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence

Both of these at Sussex University UK.

Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2016
  • Codeproject MVP 2016
  • Microsoft C# MVP 2015
  • Codeproject MVP 2015
  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Comments and Discussions