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 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.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 .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)

Share

About the Author

SergeyAndreyev

United States United States
No Biography provided

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