Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

User-driven applications

, 10 Apr 2010
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.zip
TheoryOfUserDrivenApplications
TheoryOfUserDrivenApplications
bin
Debug
TheoryOfUserDrivenApplications.vshost.exe
Release
MoveGraphLibrary.dll
TheoryOfUserDrivenApplications.bin
TheoryOfUserDrivenApplications.exe
TheoryOfUserDrivenApplications.vshost.exe
Properties
Settings.settings
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 .Drawing .Drawing2D;
using System .IO;
using System .Windows .Forms;
using Microsoft .Win32;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public class GroupEditABArray : GraphicalObject
    {
        // elements:    CommentedControl (textArray_Xrange)
        //              CommentedControl (textArray_Yrange)
        //              CommentedControl (textArray_Comment)
        //              FramedControl (btnArrayFromFile)
        //              FramedControl (datagridXY)
        //              MSPlot
        //              DotsOnPlot
        //              DotNest
        //
        int version = 606;
        Form formParent;
        int [] sidespace = new int [4];       // Left, Top, Right, Bottom
        List<ElasticGroupElement> elemsWithControls = new List<ElasticGroupElement> ();
        MSPlot plot;
        DotsOnPlot dots;
        MarkedLine line;
        DotNest dotNest;

        Rectangle rcFrame;  // only through calculation
        GroupVisibleParameters visparams;

        SolidBrush brushBack;
        bool bShowFrame;
        Pen penFrame;
        string title;
        StringAlignment alignment;
        int titlespace;
        Font fontTitle;
        Color clrTitle;

        Size sizeTitle;
        int minFrameSpace = 6;  // min space on three sides; at the top it is a min addition to hStr / 2

        // -------------------------------------------------        
        public GroupEditABArray (Form form, List<ElasticGroupElement> elems, int [] framespaces, MarkedLine mkline,
                                 string str, StringAlignment align, int strspace, Font fntTitle, Color clrStr)
        {
            formParent = form;
            elemsWithControls = elems;
            for (int i = 0; i < elemsWithControls .Count; i++)
            {
                elemsWithControls [i] .ParentID = id;
            }
            line = mkline;
            if (!string .IsNullOrEmpty (str))
            {
                title = str;
            }
            else
            {
                title = "";
            }
            fontTitle = fntTitle;
            for (int i = 0; i < 4; i++)
            {
                sidespace [i] = Math .Max (minFrameSpace, framespaces [i]);
            }
            // before calling the FrameArea () three objects must be constructed
            Control grid = elemsWithControls [4] .FramedControl .Control;
            plot = new MSPlot (formParent, new Rectangle (grid .Right + 30, grid .Top, 250, 150));
            dotNest = new DotNest (formParent, new Point (plot .MainArea .Area .Left + 10, plot .MainArea .Area .Top + 10),
                                   formParent .Font, Color .Blue, true, Color .FromArgb (204, Color .LightYellow));
            dots = new DotsOnPlot (plot, null, null);
            plot .ParentID = id;
            dotNest .ParentID = id;
            dots .ParentID = id;
            FrameArea ();

            brushBack = new SolidBrush (form .BackColor);
            bShowFrame = true;
            penFrame = Auxi_Colours .DefaultFramePen (form);   
            alignment = align;
            titlespace = Math .Abs (strspace);
            clrTitle = clrStr;

            MeasureTitleSize ();
            visparams = new GroupVisibleParameters ("EditArrays", this .ID, form .BackColor,
                                                    false,                              // groups inside
                                                    false,                              // spread back color inside
                                                    true,                               // show frame
                                                    Auxi_Colours .DefaultFrameColor (form),     // frame's color
                                                    sidespace,                          // side spaces
                                                    !string .IsNullOrEmpty (title),     // show title
                                                    fntTitle, clrTitle, 0, Math .Abs (strspace),
                                                    form .Font, form .ForeColor);
        }
        // -------------------------------------------------        
        public GroupEditABArray (Form form, Control [] ctrls, int [] framespaces, MarkedLine mkline,
                                 string str, StringAlignment align, int strspace, Font fntTitle, Color clrStr)
            : this (form, GroupEditABArray .DefaultElems (form, ctrls), framespaces, mkline, str, align, strspace, fntTitle, clrStr)
        {
        }
        // -------------------------------------------------        
        private static List<ElasticGroupElement> DefaultElems (Form form, Control [] ctrls)
        {
            List<ElasticGroupElement> elems = new List<ElasticGroupElement> ();
            elems .Add (new ElasticGroupElement (new CommentedControl (form, ctrls [0], Resizing .WE, Side .W, "X range")));
            elems .Add (new ElasticGroupElement (new CommentedControl (form, ctrls [1], Resizing .WE, Side .W, "Y range")));
            elems .Add (new ElasticGroupElement (new CommentedControl (form, ctrls [2], Resizing .WE, Side .W, "Comment")));
            elems .Add (new ElasticGroupElement (ctrls [3]));
            elems .Add (new ElasticGroupElement (ctrls [4]));
            return (elems);
        }
        // -------------------------------------------------        
        public GroupEditABArray (Form form, Control [] ctrls)
            : this (form, GroupEditABArray .DefaultElems (form, ctrls), (new Spaces (form)) .FrameSpaces,
                    new MarkedLine (MarkedLineType .LinePlusMarkers, new Pen (Color .Blue), new Marker (MarkerType .Circle_Filled, Color .Red, 3)),
                    "", StringAlignment .Near, 2, form .Font, form .ForeColor)
        {
        }
        // -------------------------------------------------        ElementsWithControls
        public List<ElasticGroupElement> ElementsWithControls
        {
            get { return (elemsWithControls); }
        }
        // -------------------------------------------------        Controls
        public List<Control> Controls
        {
            get
            {
                List<Control> ctrls = new List<Control> ();
                for (int i = 0; i < elemsWithControls .Count; i++)
                {
                    ctrls .AddRange (elemsWithControls [i] .Controls);
                }
                return (ctrls);
            }
        }
        // -------------------------------------------------        MSPlot
        public MSPlot MSPlot
        {
            get { return (plot); }
            set { plot = value; }
        }
        // -------------------------------------------------        Line
        public MarkedLine Line
        {
            get { return (line); }
            set { line = value; }
        }
        // -------------------------------------------------        Dots
        public DotsOnPlot Dots
        {
            get { return (dots); }
            set { dots = value; }
        }
        // -------------------------------------------------        DotNest
        public DotNest DotNest
        {
            get { return (dotNest); }
            set { dotNest = value; }
        }
        // -------------------------------------------------        MeasureTitleSize
        private void MeasureTitleSize ()
        {
            if (!string .IsNullOrEmpty (title))
            {
                sizeTitle = Auxi_Geometry .RoundMeasureString (formParent, title, fontTitle);
            }
        }
        // -------------------------------------------------        FrameArea
        private void FrameArea ()
        {
            Rectangle unionArea = elemsWithControls [0] .Bounds;    // CommentedControl with textArray_Name is always visible
            for (int i = 1; i < elemsWithControls .Count; i++)
            {
                if (elemsWithControls [i] .Visible)
                {
                    unionArea = Rectangle .Union (unionArea, elemsWithControls [i] .Bounds);
                }
            }
            if (plot .Visible)
            {
                unionArea = Rectangle .Union (unionArea, plot .RectAround);
            }
            if (dotNest .Visible)
            {
                unionArea = Rectangle .Union (unionArea, dotNest .RectAround);
            }
            int spaceOnTop = sidespace [1];
            if (!string .IsNullOrEmpty (title))
            {
                spaceOnTop += Auxi_Geometry .RoundMeasureString (formParent, title, fontTitle) .Height / 2;
            }
            unionArea .X -= sidespace [0];
            unionArea .Y -= spaceOnTop;
            unionArea .Width += sidespace [0] + sidespace [2];
            unionArea .Height += spaceOnTop + sidespace [3];
            rcFrame = unionArea;
        }
        // -------------------------------------------------        RectAround
        new public Rectangle RectAround
        {
            get
            {
                FrameArea ();
                return (rcFrame);
            }
        }
        // -------------------------------------------------        Update
        public void Update ()
        {
            FrameArea ();
            DefineCover ();
        }
        // -------------------------------------------------        ID
        new public long ID
        {
            get { return (id); }
            set
            {
                id = value;
                foreach (ElasticGroupElement elem in elemsWithControls)
                {
                    elem .ParentID = id;
                }
                plot .ParentID = id;
                dotNest .ParentID = id;
                dots .ParentID = id;
            }
        }
        // -------------------------------------------------        Visible
        new public bool Visible
        {
            get { return (visible); }
            set
            {
                visible = value;
                for (int i = elemsWithControls .Count - 1; i >= 0; i--)
                {
                    elemsWithControls [i] .Visible = value;
                }
                plot .Visible = value;
                dotNest .Visible = value;
                dots .Visible = value;
                if (visible)
                {
                    Update ();
                }
            }
        }
        // -------------------------------------------------        VisibleElements
        public int VisibleElements
        {
            get
            {
                int k = 0;
                for (int i = 0; i < elemsWithControls .Count; i++)
                {
                    if (elemsWithControls [i] .Visible)
                    {
                        k++;
                    }
                }
                if (plot .Visible) k++;
                if (dotNest .Visible) k++;
                return (k);
            }
        }
        // -------------------------------------------------        HiddenElements
        public int HiddenElements
        {
            get { return (elemsWithControls .Count + 2 - VisibleElements); }
        }
        // -------------------------------------------------        HideElement
        public bool HideElement (long idHide)
        {
            bool bRet = false;
            if (VisibleElements > 1)
            {
                for (int i = 0; i < elemsWithControls .Count; i++)
                {
                    if (elemsWithControls [i] .Visible)
                    {
                        if (elemsWithControls [i] .ID == idHide)
                        {
                            if (i != 0)
                            {
                                elemsWithControls [i] .Visible = false;
                                bRet = true;
                            }
                            return (bRet);
                        }
                    }
                }
                if (idHide == dotNest .ID)
                {
                    dotNest .Visible = false;
                    bRet = true;
                }
                else if (idHide == plot .ID || idHide == dots .ID)
                {
                    plot .Visible = false;
                    dots .Visible = false;
                    bRet = true;
                }
            }
            return (bRet);
        }
        // -------------------------------------------------        SideSpaces
        public int [] SideSpaces
        {
            get { return (sidespace); }
        }
        // -------------------------------------------------        ShowFrame
        public bool ShowFrame
        {
            get { return (visparams .ShowFrame); }  
            set { visparams .ShowFrame = value; }
        }
        // -------------------------------------------------        FrameColor
        public Color FrameColor
        {
            get { return (penFrame .Color); }
            set { penFrame .Color = value; }
        }
        // -------------------------------------------------        BackColor
        public Color BackColor
        {
            get { return (brushBack .Color); }
            set { brushBack = new SolidBrush (value); }
        }
        // -------------------------------------------------        Pen
        public Pen Pen
        {
            get { return (penFrame); }
            set { penFrame = value; }
        }
        // -------------------------------------------------        HasTitle
        public bool HasTitle
        {
            get { return (!string .IsNullOrEmpty (title)); }
        }
        // -------------------------------------------------        Title
        public string Title
        {
            get { return (title); }
            set
            {
                title = value;
                MeasureTitleSize ();
                Update ();
            }
        }
        // -------------------------------------------------        TitleAlignment
        public StringAlignment TitleAlignment
        {
            get { return (alignment); }
            set
            {
                alignment = value;
                DefineCover ();
            }
        }
        // -------------------------------------------------        TitleSpace
        public int TitleSpace
        {
            get { return (titlespace); }
        }
        // -------------------------------------------------        Font
        public Font Font
        {
            set
            {
                TitleFont = value;
                ElementsFont = value;
                MeasureTitleSize ();
                Update ();
            }
        }
        // -------------------------------------------------        ElementsFont
        public Font ElementsFont
        {
            set
            {
                for (int i = 0; i < elemsWithControls .Count; i++)
                {
                    elemsWithControls [i] .Font = value;
                }
                dotNest .Font = value;
                Update ();
            }
        }
        // -------------------------------------------------        ElementsColor
        public Color ElementsColor
        {
            set
            {
                for (int i = 0; i < elemsWithControls .Count; i++)
                {
                    elemsWithControls [i] .Color = value;
                }
            }
        }
        // -------------------------------------------------        ControlsBackColor
        public Color ControlsBackColor
        {
            set
            {
                for (int i = 0; i < elemsWithControls .Count; i++)
                {
                    switch (elemsWithControls [i] .ElementType)
                    {
                        case ElementType_ElasticGroup .Control:
                            elemsWithControls [i] .FramedControl .ControlColor = value;
                            break;
                        case ElementType_ElasticGroup .CommentedControl:
                            elemsWithControls [i] .CommentedControl .ControlColor = value;
                            break;
                        case ElementType_ElasticGroup .Group:
                            elemsWithControls [i] .Group .ControlsBackColor = value;
                            break;
                    }
                }
            }
        }
        // -------------------------------------------------        TitleFont
        public Font TitleFont
        {
            get { return (fontTitle); }
            set
            {
                fontTitle = value;
                if (!string .IsNullOrEmpty (title))
                {
                    sidespace [1] = Math .Max (Auxi_Geometry .RoundMeasureString (formParent, title, fontTitle) .Height / 2 + minFrameSpace,
                                               sidespace [1]);
                }
                MeasureTitleSize ();
                Update ();
            }
        }
        // -------------------------------------------------        TitleColor
        public Color TitleColor
        {
            get { return (clrTitle); }
            set { clrTitle = value; }
        }
        // -------------------------------------------------        Draw
        public void Draw (Graphics grfx)
        {
            if (visible)
            {
                FillArea (grfx, brushBack);
                Auxi_Drawing .CurvedFrameWithTitle (grfx, rcFrame, penFrame, title, alignment, titlespace, fontTitle, clrTitle, visparams .ShowFrame);
                if (plot .Visible)
                {
                    plot .Draw (grfx);
                    dots .Draw (grfx, line);
                }
                if (dotNest .Visible)
                {
                    dotNest .Draw (grfx);
                }
                for (int i = elemsWithControls .Count - 1; i >= 0; i--)
                {
                    if (elemsWithControls [i] .Visible)
                    {
                        elemsWithControls [i] .Draw (grfx);
                    }
                }
            }
        }
        // -------------------------------------------------        IntoMover
        new public void IntoMover (Mover mover, int iPos)
        {
            if (visible)
            {
                if (iPos < 0 || mover .Count < iPos)
                {
                    return;
                }
                mover .Insert (iPos, this);
                if (plot .Visible)
                {
                    plot .IntoMover (mover, iPos);
                    mover .Insert (iPos, dots);
                }
                if (dotNest .Visible)
                {
                    mover .Insert (iPos, dotNest);
                }
                for (int i = elemsWithControls .Count - 1; i >= 0; i--)
                {
                    if (elemsWithControls [i] .Visible)
                    {
                        elemsWithControls [i] .IntoMover (mover, iPos);
                    }
                }
            }
        }
        // -------------------------------------------------        PositionsInMover
        new public int PositionsInMover
        {
            get
            {
                int nPos = 1;
                if (plot .Visible)
                {
                    nPos += plot .PositionsInMover;
                    nPos += dots .PositionsInMover;
                }
                if (dotNest .Visible)
                {
                    nPos += dotNest .PositionsInMover;
                }
                for (int i = elemsWithControls .Count - 1; i >= 0; i--)
                {
                    if (elemsWithControls [i] .Visible)
                    {
                        nPos += elemsWithControls [i] .PositionsInMover;
                    }
                }
                return (nPos);
            }
        }
        // -------------------------------------------------        DefineCover
        public override void DefineCover ()
        {
            Rectangle rc = rcFrame;
            rc .Inflate (3, 3);
            if (string .IsNullOrEmpty (title))
            {
                cover = new Cover (rc, Resizing .None);
            }
            else
            {
                Rectangle [] rcs = new Rectangle [] { rc, Auxi_Geometry .CurvedFrameTitleArea (sizeTitle, rcFrame, alignment, titlespace) };
                CoverNode [] nodes = new CoverNode [] { new CoverNode (0, rcs [0]), new CoverNode (1, rcs [1]) };
                cover = new Cover (nodes);
            }
            cover .SetCursor (Cursors .Hand);
        }
        // -------------------------------------------------        Move
        public override void Move (int dx, int dy)
        {
            rcFrame .X += dx;
            rcFrame .Y += dy;
            plot .Move (dx, dy);
            dots .PlotChanged ();
            dotNest .Move (dx, dy);
            foreach (ElasticGroupElement elem in elemsWithControls)
            {
                elem .Move (dx, dy);
            }
        }
        // -------------------------------------------------        MoveNode
        public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons mb)
        {
            bool bRet = false;

            if (mb == MouseButtons .Left)
            {
                Move (dx, dy);
                bRet = true;
            }
            return (bRet);
        }

        // -------------------------------------------------        IntoRegistry
        public void IntoRegistry (RegistryKey regkey, string name)
        {
            try
            {
                // elemsWithControls
                for (int i = 0; i < 3; i++)
                {
                    elemsWithControls [i] .CommentedControl .IntoRegistry (regkey, name + "_ElemCC_" + i .ToString ());
                }
                for (int i = 3; i < 5; i++)
                {
                    elemsWithControls [i] .FramedControl .IntoRegistry (regkey, name + "_ElemFC_" + i .ToString ());
                }
                regkey .SetValue (name, new string [] { version .ToString (),           // 0
                                                        id .ToString (),                // 1
                                                        sidespace [0] .ToString (),     // 2
                                                        sidespace [1] .ToString (),     // 3
                                                        sidespace [2] .ToString (),     // 4
                                                        sidespace [3] .ToString (),     // 5

                                                        ((int) (penFrame .Color .A)) .ToString (),      // 6
                                                        ((int) (penFrame .Color .R)) .ToString (),      // 7
                                                        ((int) (penFrame .Color .G)) .ToString (),      // 8
                                                        ((int) (penFrame .Color .B)) .ToString (),      // 9
                                                        penFrame .Width .ToString (),                   // 10
                                                        ((int) (penFrame .DashStyle)) .ToString (),     // 11

                                                        title,                              // 12 
                                                        ((int) alignment) .ToString (),     // 13
                                                        titlespace .ToString (),            // 14 
                                                        fontTitle .Name .ToString (),            // 15
                                                        fontTitle .SizeInPoints .ToString (),    // 16
                                                        ((int) (fontTitle .Style)) .ToString (), // 17
                                                        ((int) clrTitle .A) .ToString (),   // 18 
                                                        ((int) clrTitle .R) .ToString (),   // 19 
                                                        ((int) clrTitle .G) .ToString (),   // 20 
                                                        ((int) clrTitle .B) .ToString (),   // 21 

                                                        idParent .ToString (),          // 22
                                                        ((int) BackColor .A) .ToString (),  // 23 
                                                        ((int) BackColor .R) .ToString (),  // 24 
                                                        ((int) BackColor .G) .ToString (),  // 25 
                                                        ((int) BackColor .B) .ToString (),  // 26 
                                                        bShowFrame .ToString (),            // 27
                                                        visible .ToString (),       // 28
                                                      },
                                         RegistryValueKind .MultiString);
                visparams .IntoRegistry (regkey, "Group_ArrayEditParams");
                plot .IntoRegistry (regkey, name + "_Plot");
                line .IntoRegistry (regkey, name + "_Line");
                dotNest .IntoRegistry (regkey, name + "_DN");
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromRegistry
        public static GroupEditABArray FromRegistry (Form form, RegistryKey regkey, string name, Control [] ctrls)
        {
            try
            {
                // elemsWithControls
                List<ElasticGroupElement> elems = new List<ElasticGroupElement> ();
                for (int i = 0; i < 3; i++)
                {
                    CommentedControl cc = CommentedControl .FromRegistry (form, regkey, name + "_ElemCC_" + i .ToString (), ctrls [i]);
                    if (cc != null)
                    {
                        elems .Add (new ElasticGroupElement (cc));
                    }
                }
                for (int i = 3; i < 5; i++)
                {
                    FramedControl fc = FramedControl .FromRegistry (regkey, name + "_ElemFC_" + i .ToString (), ctrls [i]);
                    if (fc != null)
                    {
                        elems .Add (new ElasticGroupElement (fc));
                    }
                }

                string [] strs = (string []) regkey .GetValue (name);

                if (strs != null &&
                    strs .Length >= 29 &&
                    Convert .ToInt32 (strs [0]) == 606)
                {
                    long idRead = Convert .ToInt64 (strs [1]);
                    GroupVisibleParameters pars = GroupVisibleParameters .FromRegistry (regkey, "Group_ArrayEditParams");
                    GroupEditABArray group = new GroupEditABArray (form, elems,
                                                                    new int [] {Convert .ToInt32 (strs [2]), Convert .ToInt32 (strs [3]), 
                                                                                Convert .ToInt32 (strs [4]), Convert .ToInt32 (strs [5]) },
                                                                    MarkedLine .FromRegistry (regkey, name + "_Line"),
                                                                    strs [12],                                       // title
                                                                    (StringAlignment) Convert .ToInt32 (strs [13]),  // alignment
                                                                    Convert .ToInt32 (strs [14]),                    // title space
                                                                    Auxi_Convert .ToFont (strs, 15),                 // title font
                                                                    Auxi_Convert .ToColor (strs, 18));               // title color
                    MSPlot plotRead = MSPlot .FromRegistry (form, regkey, name + "_Plot");
                    DotsOnPlot dts = null;
                    if (plotRead != null)
                    {
                        plotRead .ParentID = idRead;
                        dts = new DotsOnPlot (plotRead, null, null);
                        if (dts != null)
                        {
                            dts .ParentID = idRead;
                        }
                    }
                    DotNest nestRead = DotNest .FromRegistry (form, regkey, name + "_DN");
                    if (nestRead != null)
                    {
                        nestRead .ParentID = idRead;
                    }
                    if (group != null && plotRead != null && dts != null && nestRead != null)
                    {
                        group .ID = idRead;
                        group .Pen = Auxi_Convert .ToPen (strs, 6);
                        group .ParentID = Convert .ToInt64 (strs [22]);
                        group .BackColor = Auxi_Convert .ToColor (strs, 23);
                        group .ShowFrame = Convert .ToBoolean (strs [27]);
                        group .MSPlot = plotRead;
                        group .Dots = dts;
                        group .Visible = Convert .ToBoolean (strs [28]);
                        group .DotNest = nestRead;                          // after .Visisble !!!  as it can be hidden in the visible group !!!
                        return (group);
                    }
                }
                return (null);
            }
            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

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