Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C#

User-driven applications

Rate me:
Please Sign up or sign in to vote.
4.88/5 (24 votes)
10 Apr 2010CPOL136 min read 32.9K   5   78  
User-driven applications are the programs in which full control is given to the users. Designers of such programs are responsible only for developing an instrument for solving some task, but they do not enforce users to work with this instrument according with a predefined scenario.
using System;
using System .Collections .Generic;
using System .Drawing;
using System .IO;
using System .Windows .Forms;
using Microsoft .Win32;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public class ClosableInfo : TextM
    {
        int nCloseSide;
        Rectangle rcClose;
        SolidBrush brushClose = new SolidBrush (Color .OrangeRed);
        Pen penCross = new Pen (Color .White, 3);

        // -------------------------------------------------
        public ClosableInfo (Form form, Point ptAnchor, string txt, Font fnt, Color clr, bool show_frame, bool show_background, Color back)
            : base (form, ptAnchor, txt, fnt, clr, show_frame, show_background, back)
        {
            CalcSizes ();
        }
        // -------------------------------------------------
        public ClosableInfo (Form form, Point ptAnchor, string txt, Font fnt, Color clr)
            : this (form, ptAnchor, txt, fnt, clr, true, true, SystemColors .Control)
        {
        }
        // -------------------------------------------------
        public ClosableInfo (Form form, Point ptAnchor, string txt, Font fnt)
            : this (form, ptAnchor, txt, fnt, form .ForeColor)
        {
        }
        // -------------------------------------------------
        public ClosableInfo (Form form, Point ptAnchor, string txt, Color clr)
            : this (form, ptAnchor, txt, form .Font, clr)
        {
        }
        // -------------------------------------------------
        public ClosableInfo (Form form, Point ptAnchor, string txt)
            : this (form, ptAnchor, txt, form .Font, form .ForeColor)
        {
        }
        // -------------------------------------------------
        public ClosableInfo (Form form, TextM textm)
            : this (form, textm .Location, textm .Text, textm .Font, textm .Color, textm .ShowFrame, textm .ShowBackground, textm .BackColor)
        {
            Visible = textm .Visible;
        }
        // -------------------------------------------------        CalcSizes
        void CalcSizes () 
        {
            base .CalcSizes (ParentForm, Text, Font);
            nCloseSide = Math .Max (Auxi_Geometry .RoundMeasureString (ParentForm, "Text", Font) .Height, 20);
            nW += nCloseSide;
            rcClose = new Rectangle (Area .Right - (nCloseSide + wAdd / 3), Area .Top + hAdd / 2, nCloseSide, nCloseSide);
        }
        // -------------------------------------------------        Location
        new public Point Location
        {
            get { return (ptLT); }
            set { Move (value .X - ptLT .X, value .Y - ptLT .Y); }
        }
        // -------------------------------------------------        Text
        new public string Text
        {
            get { return (base .Text); }
            set
            {
                if (!(string .IsNullOrEmpty (value)))
                {
                    base .Text = value;
                    CalcSizes ();
                    DefineCover ();
                }
            }
        }
        // -------------------------------------------------        Font
        new public Font Font
        {
            get { return (base .Font); }
            set
            {
                base .Font = value;
                CalcSizes ();
                DefineCover ();
            }
        }
        // -------------------------------------------------        Draw
        new public void Draw (Graphics grfx)
        {
            if (visible)
            {
                if (ShowBackground)
                {
                    grfx .FillRectangle (new SolidBrush (BackColor), Area);
                }
                if (ShowFrame)
                {
                    ControlPaint .DrawBorder3D (grfx, Area, Border3DStyle .Sunken);
                }
                Auxi_Drawing .DrawText (grfx, Text, Font, 0, Color, new Point (Location .X + wAdd / 3, Location .Y + hAdd / 2), TextBasis .NW);
                grfx .FillRectangle (brushClose, rcClose);
                    
                Point ptC = Auxi_Geometry .Middle (rcClose);
                int cx0 = ptC .X;
                int cy0 = ptC .Y;
                int d = nCloseSide / 3 - 1;
                grfx .DrawLine (penCross, cx0 - d, cy0 - d, cx0 + d, cy0 + d);
                grfx .DrawLine (penCross, cx0 - d, cy0 + d, cx0 + d, cy0 - d);
            }
        }
        // -------------------------------------------------        DefineCover
        public override void DefineCover ()
        {
            CoverNode [] nodes = new CoverNode [] { new CoverNode (0, rcClose, MovementFreedom .Freeze, Cursors .Hand), 
                                                    new CoverNode (1, Area) };
            cover = new Cover (nodes);
        }
        // -------------------------------------------------        Move
        public override void Move (int dx, int dy)
        {
            ptLT += new Size (dx, dy);
            rcClose .X += dx;
            rcClose .Y += dy;
        }
        // -------------------------------------------------        MoveNode
        public override bool MoveNode (int i, int dx, int dy, Point ptMouse, MouseButtons catcher)
        {
            bool bRet = false;
            if (catcher == MouseButtons .Left)
            {
                if (i == 1)
                {
                    Move (dx, dy);
                    bRet = true;
                }
            }
            return (bRet);
        }
        // -------------------------------------------------
        new public static ClosableInfo FromRegistry (Form form, RegistryKey regkey, string name)
        {
            TextM textm = TextM .FromRegistry (form, regkey, name);
            if (textm != null)
            {
                ClosableInfo info = new ClosableInfo (form, textm); 
                return (info);
            }
            else
            {
                return (null);
            }
        }
        // -------------------------------------------------        FromFile
        new public static ClosableInfo FromFile (Form form, BinaryReader br)
        {
            TextM textm = TextM .FromFile (form, br);
            if (textm != null)
            {
                ClosableInfo info = new ClosableInfo (form, textm); 
                return (info);
            }
            else
            {
                return (null);
            }
        }

    }
}

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions