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

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 .ComponentModel;
using System .Drawing;
using System .Windows .Forms;
using Microsoft .Win32;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public partial class Form_BtnsPlacement_Operations : Form
    {
        int version = 606;
        const string strAddRegKey = "Form_BtnsPlacement_Operations";

        int nView;
        Mover mover;
        ElasticGroup group;
        List<ButtonsSketch> sketches = new List<ButtonsSketch> ();
        SolidBrush brushBtns;

        Calculator_OperationsGroupView viewSelected;
        int [] places = null;
        bool bRestored = false;

        // -------------------------------------------------
        public Form_BtnsPlacement_Operations (int iSelectedVew, int horspace, int verspace)
        {
            InitializeComponent ();
            mover = new Mover (this);

            nView = iSelectedVew;
            brushBtns = new SolidBrush (ControlPaint .Dark (this .BackColor));
            numericUD_HorSpaces .Value = horspace;
            numericUD_VerSpaces .Value = verspace;
        }
        // -------------------------------------------------        OnLoad
        private void OnLoad (object sender, EventArgs e)
        {
            RestoreFromRegistry ();
            if (!bRestored)
            {
                Rectangle rect;
                int nCode;

                nCode = (int) Calculator_OperationsGroupView .OneRow;
                ButtonsSketch sketchRow = new ButtonsSketch (nCode, false, new Point (20, 20),
                                                             new int [] { 0, 1, 2, 3, 4, 5 }, brushBtns);
                sketches .Add (sketchRow);
                rect = sketchRow .RectAround;

                nCode = (int) Calculator_OperationsGroupView .TwoRowsUneven;
                ButtonsSketch sketch_5_1 = new ButtonsSketch (nCode, false, new Point (rect .Left, rect .Bottom + 20),
                                                              new int [] { 0, 1, 2, 3, 4, 6 }, brushBtns);
                sketches .Add (sketch_5_1);
                rect = sketch_5_1 .RectAround;

                nCode = (int) Calculator_OperationsGroupView .ThreeRows;
                ButtonsSketch sketch_3rows = new ButtonsSketch (nCode, false, new Point (rect .Left, rect .Bottom + 20),
                                                                new int [] { 0, 1, 6, 7, 12, 13 }, brushBtns);
                sketches .Add (sketch_3rows);
                rect = sketchRow .RectAround;

                nCode = (int) Calculator_OperationsGroupView .OneCol;
                ButtonsSketch sketchCol = new ButtonsSketch (nCode, false, new Point (rect .Right + 20, rect .Top),
                                                             new int [] { 0, 6, 12, 18, 24, 30 }, brushBtns);
                sketches .Add (sketchCol);
                rect = sketchCol .RectAround;

                nCode = (int) Calculator_OperationsGroupView .TwoColsUneven;
                ButtonsSketch sketch_5and1 = new ButtonsSketch (nCode, false, new Point (rect .Right + 20, rect .Top),
                                                                new int [] { 0, 6, 12, 18, 24, 1 }, brushBtns);
                sketches .Add (sketch_5and1);
                rect = sketch_5and1 .RectAround;

                nCode = (int) Calculator_OperationsGroupView .ThreeCols;
                ButtonsSketch sketch_3cols = new ButtonsSketch (nCode, false, new Point (rect .Right + 20, rect .Top),
                                                                new int [] { 0, 6, 1, 7, 2, 8 }, brushBtns);
                sketches .Add (sketch_3cols);

                CommentedControl [] ccs = new CommentedControl [] { new CommentedControl (this, numericUD_HorSpaces, Side.E, 0.5, "Horizontal"),
                                                                    new CommentedControl (this, numericUD_VerSpaces, Side.E, 0.5, "Vertical") };
                group = new ElasticGroup (this, ccs, "Spaces between buttons");
                group .SideSpaces = new int [] { 10, 6, 10, 10 };
                group .Location = new Point (sketch_3rows .RectAround .Right + 20, sketchCol .RectAround .Bottom + 20);

                btnOK .Location = new Point (group .FrameArea .Right + 16, group .FrameArea .Bottom - btnOK .Height);
                ClientSize = new Size (Math .Max (sketch_3cols .RectAround .Right, btnOK .Right) + 16, btnOK .Bottom + 12);
            }
            if (0 <= nView && nView < sketches .Count)
            {
                places = sketches [nView] .Places;
                viewSelected = (Calculator_OperationsGroupView) nView;
            }
            else
            {
                places = null;
                viewSelected = Calculator_OperationsGroupView .Arbitrary;
            }
            for (int i = 0; i < sketches .Count; i++)
            {
                sketches [i] .Selected = sketches [i] .Code == nView;
            }

            group .IntoMover (mover, 0);
            for (int i = 0; i < sketches .Count; i++)
            {
                mover .Add (sketches [i]);
            }
            mover .Insert (0, btnOK);
        }
        // -------------------------------------------------        OnFormClosing
        private void OnFormClosing (object sender, FormClosingEventArgs e)
        {
            SaveInfoToRegistry ();
        }
        // -------------------------------------------------        OnPaint
        private void OnPaint (object sender, PaintEventArgs e)
        {
            Graphics grfx = e .Graphics;

            for (int i = sketches .Count - 1; i >= 0; i--)
            {
                sketches [i] .Draw (grfx);
            }
            group .Draw (grfx);
        }
        // -------------------------------------------------        OnMouseDown
        private void OnMouseDown (object sender, MouseEventArgs e)
        {
            mover .Catch (e .Location, e .Button);
        }
        // -------------------------------------------------        OnMouseUp
        private void OnMouseUp (object sender, MouseEventArgs e)
        {
            int iObject, iNode;
            if (mover .Release (out iObject, out iNode))
            {
                if (mover [iObject] .Source is ButtonsSketch && iNode == 0)
                {
                    ButtonsSketch sketch = mover [iObject] .Source as ButtonsSketch;
                    for (int i = 0; i < sketches .Count; i++)
                    {
                        sketches [i] .Selected = false;
                    }
                    sketch .Selected = true;
                    viewSelected = (Calculator_OperationsGroupView) (sketch .Code);
                    places = sketch .Places;
                    Invalidate ();
                }
            }
        }
        // -------------------------------------------------        OnMouseMove
        private void OnMouseMove (object sender, MouseEventArgs e)
        {
            if (mover .Move (e .Location))
            {
                Invalidate ();
            }
        }
        // -------------------------------------------------        SelectedView
        public Calculator_OperationsGroupView SelectedView
        {
            get { return (viewSelected); }
        }
        // -------------------------------------------------        HorSpaces
        public int HorSpaces
        {
            get { return (Convert .ToInt32 (numericUD_HorSpaces .Value)); }
        }
        // -------------------------------------------------        VerSpaces
        public int VerSpaces
        {
            get { return (Convert .ToInt32 (numericUD_VerSpaces .Value)); }  
        }
        // -------------------------------------------------        Places
        public int [] Places
        {
            get { return (places); }
        }

        const string nameAuxi = "Auxi";
        // -------------------------------------------------        SaveInfoToRegistry
        private void SaveInfoToRegistry ()
        {
            string strkey = Form_Main .strRegKey + strAddRegKey;

            RegistryKey regkey = null;
            try
            {
                regkey = Registry .CurrentUser .CreateSubKey (strkey);
                if (regkey != null)
                {
                    string [] strAuxi = {version .ToString (),          // 0
                                         ClientSize .Width .ToString (),    // 1
                                         ClientSize .Height .ToString (),   // 2
                                         btnOK .Left .ToString (),      // 3
                                         btnOK .Top .ToString (),       // 4
                                         btnOK .Width .ToString (),     // 5
                                         btnOK .Height .ToString (),    // 6
                                         sketches .Count .ToString (),      // 7
                                        };
                    regkey .SetValue (nameAuxi, strAuxi, RegistryValueKind .MultiString);

                    group .IntoRegistry (regkey, "Group");
                    for (int i = 0; i < sketches .Count; i++)
                    {
                        sketches [i] .IntoRegistry (regkey, i .ToString ());
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (regkey != null) regkey .Close ();
            }
        }
        // -------------------------------------------------        RestoreFromRegistry
        private void RestoreFromRegistry ()
        {
            string strkey = Form_Main .strRegKey + strAddRegKey;

            RegistryKey regkey = null;
            try
            {
                regkey = Registry .CurrentUser .OpenSubKey (strkey);
                if (regkey != null)
                {
                    string [] strAuxi = (string []) regkey .GetValue (nameAuxi);
                    if (strAuxi != null && strAuxi .Length == 8 && Convert .ToInt32 (strAuxi [0]) == 606)
                    {
                        ClientSize = Auxi_Convert .ToSize (strAuxi, 1);
                        btnOK .Bounds = Auxi_Convert .ToRectangle (strAuxi, 3);
                        int nSketch = Convert .ToInt32 (strAuxi [7]);
                        sketches .Clear ();
                        for (int i = 0; i < nSketch; i++)
                        {
                            ButtonsSketch sketch = ButtonsSketch .FromRegistry (regkey, i .ToString ());
                            if (sketch != null)
                            {
                                sketches .Add (sketch);
                            }
                        }
                        group = ElasticGroup .FromRegistry (this, regkey, "Group", new Control [] { numericUD_HorSpaces, numericUD_VerSpaces });
                        bRestored = true;
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (regkey != null) regkey .Close ();
            }
        }

    }
}

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)

About the Author

SergeyAndreyev

United States United States
No Biography provided

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