Click here to Skip to main content
12,397,610 members (60,503 online)
Click here to Skip to main content

Stats

21.4K views
77 bookmarked
Posted

User-driven applications

, 10 Apr 2010 CPOL
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.
TheoryOfUserDrivenApplications
TheoryOfUserDrivenApplications
bin
Debug
TheoryOfUserDrivenApplications.vshost.exe
Release
MoveGraphLibrary.dll
TheoryOfUserDrivenApplications.bin
TheoryOfUserDrivenApplications.exe
TheoryOfUserDrivenApplications.vshost.exe
Properties
Resources
ArrowDown.bmp
ArrowUp.bmp
DELETE.BMP
Hangar.bmp
Lock.bmp
palette_.bmp
RuralHouse.bmp
RuralLeftPlus.bmp
RuralRightPlus.bmp
SimpleHouse.bmp
User_driven_applications.doc
User_driven_applications.pdf
using System;
using System .Collections .Generic;
using System .Drawing;
using System .Windows .Forms;
using System .IO;
using Microsoft .Win32;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public class DotNest : GraphicalObject
    {
        int version = 606;
        Form formParent;
        RectangleF rc, rcNest, rcText;
        PointF ptDot, ptDotNest, ptReleased;
        string strIdle = "Press and place";
        string strShow;
        Font font;
        Color clrText;
        bool bFrame;
        Border3DStyle borderstyle = Border3DStyle .RaisedInner;
        SolidBrush brushBack;
        Color clrDot = Color .Red;
        int nDotRadius = 5;

        int wAdd = 4;      // for frame and more; extra pixels on the sides
        int hAdd = 4;

        // -------------------------------------------------
        public DotNest (Form form, PointF ptLT, Font fnt, Color clr, bool show_frame, Color clrBack)
        {
            formParent = form;
            if (fnt != null)
            {
                font = fnt;
            }
            else
            {
                font = new Font ("Times New Roman", 8);
            }
            Size sizeInfo = Auxi_Geometry .RoundMeasureString (formParent, strIdle, font);
            sizeInfo .Width += wAdd;
            sizeInfo .Height += hAdd;
            rcNest = new RectangleF (ptLT .X, ptLT .Y, sizeInfo .Height, sizeInfo .Height);
            rcText = new RectangleF (rcNest .Right, rcNest .Top, sizeInfo .Width, sizeInfo .Height);
            rc = new RectangleF (rcNest .Left, rcNest .Top, rcNest .Width + rcText .Width, rcNest .Height);
            ptDotNest = Auxi_Geometry .Middle (rcNest);
            ptDot = Auxi_Geometry .Middle (rcNest);
            clrText = clr;
            bFrame = show_frame;
            brushBack = new SolidBrush (clrBack);
            strShow = strIdle;
        }
        // -------------------------------------------------        DotReturnHome
        public void DotReturnHome ()
        {
            ptReleased = ptDot;
            ptDot = ptDotNest;
            strShow = strIdle;
        }
        // -------------------------------------------------        PointOfRelease
        public PointF PointOfRelease
        {
            get { return (ptReleased); }
        }
        // -------------------------------------------------        TextToShow
        public string TextToShow
        {
            set { strShow = value; }
        }
        // -------------------------------------------------        Font
        public Font Font
        {
            get { return (font); }
            set
            {
                if (value != null)
                {
                    font = value;
                    Size sizeInfo = Auxi_Geometry .RoundMeasureString (formParent, strIdle, font);
                    sizeInfo .Width += wAdd;
                    sizeInfo .Height += hAdd;
                    rcNest .Width = rcNest .Height = sizeInfo .Height;
                    rcText = new RectangleF (rcNest .Right, rcNest .Top, sizeInfo .Width, sizeInfo .Height);
                    rc = new RectangleF (rcNest .Left, rcNest .Top, rcNest .Width + rcText .Width, rcNest .Height);
                    ptDotNest = Auxi_Geometry .Middle (rcNest);
                    ptDot = Auxi_Geometry .Middle (rcNest);
                    DefineCover ();
                }
            }
        }
        // -------------------------------------------------        TextColor
        public Color TextColor
        {
            get { return (clrText); }
            set { clrText = value; }
        }
        // -------------------------------------------------        ShowFrame
        public bool ShowFrame
        {
            get { return (bFrame); }
            set { bFrame = value; }
        }
        // -------------------------------------------------        BorderStyle
        public Border3DStyle BorderStyle
        {
            get { return (borderstyle); }
            set { borderstyle = value; }
        }
        // -------------------------------------------------        BackColor
        public Color BackColor
        {
            get { return (brushBack .Color); }
            set { brushBack = new SolidBrush (value); }
        }
        // -------------------------------------------------        DotColor
        public Color DotColor
        {
            get { return (clrDot); }
            set { clrDot = value; }
        }
        // -------------------------------------------------        DotRadius
        public int DotRadius
        {
            get { return (nDotRadius); }
            set { nDotRadius = value; }
        }
        // -------------------------------------------------        RectAround
        new public Rectangle RectAround
        {
            get { return (Rectangle .Round (rc)); }
        }
        // -------------------------------------------------        Draw
        public void Draw (Graphics grfx)
        {
            if (visible)
            {
                grfx .FillRectangle (brushBack, rc);
                if (bFrame == true)
                {
                    ControlPaint .DrawBorder3D (grfx, Rectangle .Round (rc), borderstyle);
                }
                Auxi_Drawing .DrawText (grfx, strShow, font, 0, clrText, Point .Round (rcText .Location), TextBasis .NW);
                Auxi_Drawing .FillEllipse (grfx, ptDot, nDotRadius, clrDot);
            }
        }
        // -------------------------------------------------        DefineCover
        public override void DefineCover ()
        {
            CoverNode [] nodes = new CoverNode [] { new CoverNode (0, ptDot, nDotRadius, Cursors.Hand), 
                                                    new CoverNode (1, rc)};
            cover = new Cover (nodes);
        }
        // -------------------------------------------------        Move
        public override void Move (int dx, int dy)
        {
            rc .X += dx;
            rc .Y += dy;
            rcNest .X += dx;
            rcNest .Y += dy;
            rcText .X += dx;
            rcText .Y += dy;
            ptDot .X += dx;
            ptDot .Y += dy;
            ptDotNest .X += dx;
            ptDotNest .Y += dy;
        }
        // -------------------------------------------------        MoveNode
        public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons catcher)
        {
            bool bRet = false;
            if (catcher == MouseButtons .Left)
            {
                switch (i)
                {
                    case 0:
                        ptDot = ptM;
                        bRet = true;
                        break;
                    case 1:
                        Move (dx, dy);
                        break;
                }
            }
            return (bRet);
        }

        const string nameMain = "DotNest_";
        // -------------------------------------------------        IntoRegistry
        public void IntoRegistry (RegistryKey regkey, string strAdd)
        {
            try
            {
                regkey .SetValue (nameMain + strAdd, new string [] {version .ToString (),   // 0
                                                                    rc .X .ToString (),         // 1
                                                                    rc .Y .ToString (),         // 2
                                                                    font .Name .ToString (),             // 3
                                                                    font .SizeInPoints .ToString (),     // 4
                                                                    ((int) font .Style) .ToString (),    // 5
                                                                    ((int) clrText .A) .ToString (),    // 6 
                                                                    ((int) clrText .R) .ToString (),    // 7 
                                                                    ((int) clrText .G) .ToString (),    // 8 
                                                                    ((int) clrText .B) .ToString (),    // 9 
                                                                    bFrame .ToString (),             // 10
                                                                    ((int) brushBack .Color .A) .ToString (),   // 11 
                                                                    ((int) brushBack .Color .R) .ToString (),   // 12 
                                                                    ((int) brushBack .Color .G) .ToString (),   // 13 
                                                                    ((int) brushBack .Color .B) .ToString (),   // 14 
                                                                    ((int) borderstyle) .ToString (),           // 15
                                                                    ((int) clrDot .A) .ToString (),     // 16 
                                                                    ((int) clrDot .R) .ToString (),     // 17 
                                                                    ((int) clrDot .G) .ToString (),     // 18 
                                                                    ((int) clrDot .B) .ToString (),     // 19 
                                                                    visible .ToString (),  // 20 
                                                                   },
                                                     RegistryValueKind .MultiString);
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------
        public static DotNest FromRegistry (Form form, RegistryKey regkey, string strAdd)
        {
            try
            {
                string [] strs = (string []) regkey .GetValue (nameMain + strAdd);

                if (strs == null ||
                    strs .Length < 21 ||
                    Convert .ToInt32 (strs [0]) != 606) 
                {
                    return (null);
                }
                PointF pt = Auxi_Convert .ToPointF (strs, 1);
                Font fnt = Auxi_Convert .ToFont (strs, 3);
                Color clr = Auxi_Convert .ToColor (strs, 6);
                bool show_frame = Convert .ToBoolean (strs [10]);
                Color clrBack = Auxi_Convert .ToColor (strs, 11);
                DotNest dotnest = new DotNest (form, pt, fnt, clr, show_frame, clrBack);
                if (dotnest != null)
                {
                    dotnest .BorderStyle = (Border3DStyle) Convert .ToInt32 (strs [15]);
                    dotnest .DotColor = Auxi_Convert .ToColor (strs, 16);
                    dotnest .Visible = Convert .ToBoolean (strs [20]);
                }
                return (dotnest);
            }
            catch
            {
                return (null);
            }
            finally
            {
            }
        }
        // -------------------------------------------------        IntoFile
        public void IntoFile (BinaryWriter bw)
        {
            try
            {
                bw .Write (version);                // 0

                Auxi_IO .Write_PointF (bw, rc .Location);   // 1, 2
                Auxi_IO .Write_Font (bw, font);             // 3 - 5
                Auxi_IO .Write_Color (bw, clrText);         // 6 - 9
                bw .Write (bFrame);                             // 10
                Auxi_IO .Write_Color (bw, brushBack .Color);    // 11 - 14
                bw .Write ((int) borderstyle);              // 15
                Auxi_IO .Write_Color (bw, clrDot);          // 16 - 19
                bw .Write (visible);                        // 20
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromFile
        public static DotNest FromFile (Form form, BinaryReader br)
        {
            try
            {
                int ver = br .ReadInt32 ();
                if (ver < 606)
                {
                    return (null);
                }
                PointF pt = Auxi_IO .Read_PointF (br);      // 1, 2
                Font fnt = Auxi_IO .Read_Font (br);         // 3 - 5
                Color clr = Auxi_IO .Read_Color (br);       // 6 - 9
                bool show_frame = br .ReadBoolean ();       // 10
                Color clrBack = Auxi_IO .Read_Color (br);   // 11 - 14
                DotNest dotnest = new DotNest (form, pt, fnt, clr, show_frame, clrBack);
                if (dotnest != null)
                {
                    dotnest .BorderStyle = (Border3DStyle) br .ReadInt32 ();    // 15
                    dotnest .DotColor = Auxi_IO .Read_Color (br);               // 16 - 19
                    dotnest .Visible = br .ReadBoolean ();          // 20
                }
                return (dotnest);
            }
            catch
            {
                return (null);
            }
            finally
            {
            }
        }
    }
}

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)

Share

About the Author

SergeyAndreyev
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 10 Apr 2010
Article Copyright 2010 by SergeyAndreyev
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid