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_Main : Form
    {
        static public string strRegKey = "Software\\Applications_C#\\TheoryOfUserDrivenApplications\\";
        const string strAddRegKey = "Form_Main";
        Mover mover;
        Point ptMouse_Down, ptMouse_Up;
        LinkedRectangles lrTitle = null;
        ElasticGroup groupInfo = null;
        TextMR reminder = null;
        Font fntTitle;
        string [] strsTitle = new string [] {"World of Moveable Objects (part 2)", 
                                             "Part 1 - algorithm and samples of design of moveable objects from primitive to complicated", 
                                             "Part 2 - design of different applications on the basis of moveable / resizable objects" };
        string [] strsInfo = new string [] {"A simple sample to demonstrate the flexibility of forms' design on the basis of moveable / resizable " +
                                            "controls.  The only sample, using the Group class.  This is also the only form " +
                                            "in application without any tuning of the visual parameters.",

                                            "Use of the ElasticGroup class to organize very complicated forms with unlimited flexibility.", 

                                            "Construction of extremely complicated form, in which it is impossible to predict the users' " +
                                            "behaviour.  Thus they can do everything.", 

                                            "The task is well known; the implementations exist in different variants on all the computer " +
                                            "systems.  What can the moveable elements add to this theme?", 

                                            "World of functions is unlimited.  So the systems to analyze those functions must be also " +
                                            "stripped of all the limitations.", 

                                            "There are many different types of data visualization. Some of them are demonstrated here.", 

                                            "Build your own village; no limits for your imagination." };
        bool bRestore = false;
        Rectangle rcList, rcText;

        // -------------------------------------------------
        public Form_Main ()
        {
            InitializeComponent ();
            //Font = new Font ("Times New Roman", 14);
            mover = new Mover (this);
        }
        // -------------------------------------------------        OnLoad
        private void OnLoad (object sender, EventArgs e)
        {
            rcList = listForms .Bounds;
            rcText = textInfo .Bounds;

            RestoreFromRegistry ();
            if (!bRestore)
            {
                DefaultView ();
            }
            listForms .Items [0] .Selected = true;
            RenewMover ();
        }
        // -------------------------------------------------        OnFormClosing
        private void OnFormClosing (object sender, FormClosingEventArgs e)
        {
            SaveInfoToRegistry ();
        }
        // -------------------------------------------------        RenewMover
        private void RenewMover ()
        {
            mover .Clear ();
            mover .Insert (0, lrTitle);
            groupInfo .IntoMover (mover, 0);
            mover .Add (reminder);
        }
        // -------------------------------------------------        DefaultView
        private void DefaultView ()
        {
            if (groupInfo != null)
            {
                groupInfo .CloseAllTuningForms ();
            }
            ConstructTitle (30, 50);
            listForms .Font = Font;
            textInfo .Font = Font;
            listForms .Bounds = rcList;
            textInfo .Bounds = rcText;
            groupInfo = new ElasticGroup (this, new Control [] { listForms, textInfo }, 10, "What is inside");
            reminder = new TextMR (this, new Point (Auxi_Geometry .Middle (groupInfo .RectAround) .X, groupInfo .RectAround .Bottom + 40),
                                   "ALL objects in this application are moveable", Font, 0, Color .Blue);
            ClientSize = new Size (Math .Max (Math .Max (lrTitle .RectAround .Right, groupInfo .FrameArea .Right), reminder .RectAround .Right) + 50,
                                   reminder .RectAround .Bottom + 50);
        }
        // -------------------------------------------------        ConstructTitle
        private void ConstructTitle (int cxL, int cyT)
        {
            fntTitle = new Font ("Times New Roman", (float) (Font .SizeInPoints * 2.4));

            Size sizeTitle = Auxi_Geometry .RoundMeasureString (this, strsTitle [0], fntTitle);
            Rectangle rcTitle = new Rectangle (cxL, cyT, sizeTitle .Width, sizeTitle .Height);
            Size size_1 = Auxi_Geometry .RoundMeasureString (this, strsTitle [1], Font);
            Rectangle rc_1 = new Rectangle (rcTitle .Left + rcTitle .Width / 5, rcTitle .Bottom, size_1 .Width, size_1 .Height);
            Size size_2 = Auxi_Geometry .RoundMeasureString (this, strsTitle [2], Font);
            Rectangle rc_2 = new Rectangle (rc_1 .Left, rc_1 .Bottom, size_2 .Width, size_2 .Height);
            lrTitle = new LinkedRectangles (new Rectangle [] { rcTitle, rc_1, rc_2 });
        }
        // -------------------------------------------------        OnPaint
        private void OnPaint (object sender, PaintEventArgs e)
        {
            Graphics grfx = e .Graphics;

            reminder .Draw (grfx);
            Auxi_Drawing .DrawText (grfx, strsTitle [0], fntTitle, 0, Color .Blue, lrTitle .Rectangle (0) .Location, TextBasis .NW);
            Auxi_Drawing .DrawText (grfx, strsTitle [1], Font, 0, ForeColor, lrTitle .Rectangle (1) .Location, TextBasis .NW);
            Auxi_Drawing .DrawText (grfx, strsTitle [2], Font, 0, ForeColor, lrTitle .Rectangle (2) .Location, TextBasis .NW);

            groupInfo .Draw (grfx);
        }
        // -------------------------------------------------        OnMouseDown
        private void OnMouseDown (object sender, MouseEventArgs e)
        {
            ptMouse_Down = e .Location;
            mover .Catch (e .Location, e .Button, true);
            ContextMenuStrip = null;
        }
        // -------------------------------------------------        OnMouseUp
        private void OnMouseUp (object sender, MouseEventArgs e)
        {
            ptMouse_Up = e .Location;
            double dist = Auxi_Geometry .Distance (ptMouse_Down, ptMouse_Up);
            if (mover .Release ())
            {
                if (mover [mover .WasCaughtObject] .Source is ElasticGroup && e .Button == MouseButtons .Right && dist <= 3)
                {
                    ContextMenuStrip = menuOnGroup;
                }
            }
            else
            {
                if (e .Button == MouseButtons .Right && dist <= 3)
                {
                    ContextMenuStrip = menuOnEmpty;
                }
            }
        }
        // -------------------------------------------------        OnMouseMove
        private void OnMouseMove (object sender, MouseEventArgs e)
        {
            if (mover .Move (e .Location))
            {
                Invalidate ();
            }
        }
        // -------------------------------------------------        OnContextMenuChanged
        private void OnContextMenuChanged (object sender, EventArgs e)
        {
            if (ContextMenuStrip != null)
            {
                ContextMenuStrip .Show (PointToScreen (ptMouse_Up));
            }
        }
        // -------------------------------------------------        Click_miYearsSelection
        private void Click_miYearsSelection (object sender, EventArgs e)
        {
            Form_YearsSelection form = new Form_YearsSelection ();
            form .ShowDialog ();
        }
        // -------------------------------------------------        Click_miPersonalData
        private void Click_miPersonalData (object sender, EventArgs e)
        {
            Form_PersonalData form = new Form_PersonalData (PointToScreen (new Point (200, 70)));
            while (DialogResult .Retry == form .ShowDialog ())
            {
                form = new Form_PersonalData (form .Location);
            }
        }
        // -------------------------------------------------        Click_miDataWorld
        private void Click_miDataWorld (object sender, EventArgs e)
        {
            Form_DataWorld form = new Form_DataWorld ();
            form .ShowDialog ();
        }
        // -------------------------------------------------        Click_miCalculator
        private void Click_miCalculator (object sender, EventArgs e)
        {
            Form_Calculator form = new Form_Calculator (PointToScreen (new Point (100, 30)));
            while (DialogResult .Retry == form .ShowDialog ())
            {
                form = new Form_Calculator (form .Location);
            }
        }
        // -------------------------------------------------        Click_miFunctions
        private void Click_miFunctions (object sender, EventArgs e)
        {
            Form_Functions form = new Form_Functions ();
            form .ShowDialog ();
        }
        // -------------------------------------------------        Click_miFinancial
        private void Click_miFinancial (object sender, EventArgs e)
        {
            Form_PlotsVariety form = new Form_PlotsVariety ();
            form .ShowDialog ();
        }
        // -------------------------------------------------        Click_miVillage
        private void Click_miVillage (object sender, EventArgs e)
        {
            Form_Village form = new Form_Village ();
            form .ShowDialog ();
        }
        // -------------------------------------------------        Click_miAbout
        private void Click_miAbout (object sender, EventArgs e)
        {
            Form_About form = new Form_About ();
            form .ShowDialog ();
        }
        // -------------------------------------------------        SelectedIndexChanged_listForms
        private void SelectedIndexChanged_listForms (object sender, EventArgs e)
        {
            if (listForms .SelectedIndices .Count > 0)
            {
                textInfo .Text = strsInfo [listForms .SelectedIndices [0]];
            }
            else
            {
                textInfo .Text = "";
            }
        }
        // -------------------------------------------------        Click_miModifyGroup
        private void Click_miModifyGroup (object sender, EventArgs e)
        {
            groupInfo .ParametersDialog (this, PointToScreen (ptMouse_Up), ParametersChanged);
        }
        // -------------------------------------------------		ParametersChanged
        private void ParametersChanged (object sender, EventArgs ea)
        {
            groupInfo .Update ();
            Invalidate ();
        }
        // -------------------------------------------------        Click_miDefaultView
        private void Click_miDefaultView (object sender, EventArgs e)
        {
            DefaultView ();
            listForms .Items [0] .Selected = true;
            RenewMover ();
            Invalidate ();
        }

        const string nameSize = "Size";
        // -------------------------------------------------        SaveInfoToRegistry
        private void SaveInfoToRegistry ()
        {
            string strRegKey = Form_Main .strRegKey + strAddRegKey;

            RegistryKey regkey = null;
            try
            {
                regkey = Registry .CurrentUser .CreateSubKey (strRegKey);
                if (regkey != null)
                {
                    regkey .SetValue (nameSize, new string [] { ClientSize .Width .ToString (), 
                                                                ClientSize .Height .ToString (), 
                                                                lrTitle .RectAround .Left .ToString (), 
                                                                lrTitle .RectAround .Top .ToString (), 
                                                              },
                                      RegistryValueKind .MultiString);
                    groupInfo .IntoRegistry (regkey, "Group");
                    reminder .IntoRegistry (regkey, "Reminder");
                }
            }
            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 [] strs = (string []) regkey .GetValue (nameSize);
                    if (strs != null && strs .Length == 4)
                    {
                        ClientSize = Auxi_Convert .ToSize (strs, 0);
                    }
                    else
                    {
                        return;
                    }
                    ConstructTitle (Convert .ToInt32 (strs [2]), Convert .ToInt32 (strs [3]));
                    groupInfo = ElasticGroup .FromRegistry (this, regkey, "Group", new Control [] {listForms, textInfo });
                    reminder = TextMR .FromRegistry (this, regkey, "Reminder");
                    if (lrTitle == null || groupInfo == null || reminder == null)
                    {
                        return;
                    }
                    bRestore = 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
Web01 | 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