Click here to Skip to main content
15,885,278 members
Articles / Mobile Apps

Windows Mobile Password Safe

Rate me:
Please Sign up or sign in to vote.
4.87/5 (58 votes)
12 Jan 2009CPOL16 min read 159.4K   3.1K   139  
A password safe with a touch screen UI introducing Fluid Controls.
using System;

using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Fluid.Controls.Classes;
using Fluid.Drawing;
using System.Windows.Forms;
using Fluid.Drawing.GdiPlus;

namespace Fluid.Controls
{
    public class FluidHeader : ControlContainer, ILayoutPanel
    {
        protected override void InitControl()
        {
            base.InitControl();
            backButton = defaultBackButton;
            Anchor = AnchorTLR;
            if (Bounds.Size.IsEmpty) bounds = new Rectangle(0, 0, 240, 32);
            ForeColor = Color.White;
            //       Bounds = new Rectangle(0, 0, 240, 28);
            rightButtons.Font = new Font(FontFamily.GenericSansSerif, 6f, FontStyle.Regular);
            Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Bold);
            BackColor = Color.SlateGray;
            int h = Height - 8;

            backButton.Visible = false;
            backButton.Font = new Font(FontFamily.GenericSansSerif, 6f, FontStyle.Regular);
            backButton.Bounds = new Rectangle(2, 4, 48, h);
            backButton.Shape = ButtonShape.Back;
            backButton.Anchor = AnchorLTB;
            backButton.BackColor = ColorConverter.OpaqueColor(Color.SlateGray);

            rightButtons.Bounds = new Rectangle(Width - 60 - 4, 4, 60, h);
            rightButtons.Anchor = AnchorRTB;
            titleLabel.Anchor |= AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Top;
            titleLabel.ForeColor = Color.Empty;
            titleLabel.ShadowColor = Color.Black;
            titleLabel.LineAlignment = StringAlignment.Center;
            titleLabel.Alignment = StringAlignment.Center;
            rightButtons.ButtonsChanged += new EventHandler(rightButtons_ButtonsChanged);
            rightButtons.Visible = false;
        //    InitTitleBounds();
            titleLabel.bounds = ClientRectangle;

            controls.Add(titleLabel);
            controls.Add(backButton);
            controls.Add(rightButtons);
        }


        public override void Dispose()
        {
            titleLabel.Dispose();
            backButton.Dispose();
            if (animLabel != null) animLabel.Dispose();
            base.Dispose();
        }

        protected override void OnForeColorChanged()
        {
            base.OnForeColorChanged();
            //    titleLabel.Text = ForeColor;
        }

        void rightButtons_ButtonsChanged(object sender, EventArgs e)
        {
            rightButtons.Visible = rightButtons.Buttons.Count > 0;
        }


        private int animOffset = 0;
        internal int AnimOffset
        {
            get { return animOffset; }
            set
            {
                if (animOffset != value)
                {
                    animOffset = value;
                    InitTitleBounds();
                    Invalidate(titleLabel.Bounds);
                    Invalidate(animLabel.Bounds);
                }
            }
        }

        private FluidButton animBackButton;
        private ButtonGroup animButtons;
        private FluidLabel animLabel;

        internal FluidLabel AnimLabel
        {
            get
            {
                EnsureAnimLabel();
                return animLabel;
            }
        }

        internal FluidButton AnimBackButton
        {
            get { return animBackButton; }
            set
            {
                if (animBackButton != value)
                {
                    animBackButton = value;
                    if (value != null)
                    {
                        if (animBackButton != null) controls.Remove(animBackButton);
                        animBackButton.Bounds = backButton.Bounds;
                        controls.Add(value);
                    }
                }
            }
        }

        internal ButtonGroup AnimButtons
        {
            get { return animButtons; }
            set
            {
                if (animButtons == null)
                {
                    animButtons = value;
                    if (value != null)
                    {
                        controls.Add(animButtons);
                        animButtons.Font = rightButtons.Font;
                        animButtons.Bounds = rightButtons.Bounds;
                    }
                }
            }
        }

        private void EnsureAnimLabel()
        {
            if (animLabel == null)
            {
                FluidLabel l = new FluidLabel("", Width, 0, Width, Height);
                animLabel = l;
                l.ShadowColor = Color.Black;
                l.LineAlignment = StringAlignment.Center;
                l.Alignment = StringAlignment.Center;
                l.Visible = false;
                controls.Insert(0, l);
            }
        }

        private void InitTitleBounds()
        {
            int w = Width;
            int h = Height - 8;
            int l = backButton.Visible ? 0 : backButton.Right;
            int r = w - (rightButtons.Visible ? w : rightButtons.Left);
            l = Math.Min(l, r);
            r = w + l;


            w = Width - l - l;
            int a = (animOffset * w / Width);

            titleLabel.Bounds = new Rectangle(l - a, 4, w, h);
            AnimLabel.Bounds = new Rectangle(l + w - a, 4, w, h);
        }

        public void SetDefaultBackButton()
        {
            BackButton = defaultBackButton;
        }




        private ButtonGroup rightButtons = new ButtonGroup();
        private FluidButton defaultBackButton = new FluidButton();
        private FluidLabel titleLabel = new FluidLabel();


        private FluidButton backButton;

        public bool IsDefaultBackButton { get { return backButton == defaultBackButton; } }

        public FluidButton BackButton 
        { 
            get { return backButton; }
            set
            {
                if (backButton != value)
                {
                    if (backButton != null)
                    {
                        controls.Remove(backButton);
                    }
                    backButton = value;
                    if (backButton != null)
                    {
                        if (backButton.Font == null)
                        {
                            backButton.Font = new Font(FontFamily.GenericSansSerif, 6f, FontStyle.Regular);
                        }
                        if (backButton.BackColor.IsEmpty)
                        {
                            backButton.BackColor = defaultBackButton.BackColor;
                        }
                        int h = UnscaleX(Height) - 8;
                        int w = Math.Min(backButton.Width, 32);
                        backButton.Bounds = new Rectangle(2, 4, w, h);
                        backButton.Anchor = AnchorLTB;
                        controls.Insert(2,backButton);
                    }
                    Invalidate();
                }
            }
        }

        public string Title
        {
            get { return titleLabel.Text; }
            set { titleLabel.Text = value; }
        }

        public ButtonCollection Buttons
        {
            get { return rightButtons.Buttons; }
        }

        public int ButtonsWidth
        {
            get { return rightButtons.Width; }
            set { rightButtons.Width = value; }
        }


        public RoundedCorners Corners
        {
            get { return rightButtons.Corners; }
            set { rightButtons.Corners = value; }
        }

        public ButtonShape RightShape
        {
            get { return backButton.Shape; }
            set { backButton.Shape = value; }
        }

        protected override void OnPaintBackground(FluidPaintEventArgs e)
        {
            PaintGradientBackground(e);
        }

        protected override void OnSizeChanged(Size oldSize, Size newSize)
        {
            base.OnSizeChanged(oldSize, newSize);
            InitTitleBounds();
        }


        internal int ButtonsAlpha { set { rightButtons.Alpha = value; } }
    }
}

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)


Written By
Software Developer (Senior)
Germany Germany
MCPD
Enterprise Application Developer 3.5
Windows Developer 3.5
.ASP.NET Developer 3.5
.NET 2.0 Windows Developer
.NET 2.0 Web Developer
.NET 2.0 Enterprise Application Developer


MCTS
.NET 3.5 Windows Forms Applications
.NET 3.5 ASP.NET Applications
.NET 3.5, ADO.NET Application Development
.NET 3.5 WCF
.NET 3.5 WPF
.NET 3.5 WF
Microsoft SQL Server 2008, Database Development
.NET 2.0 Windows Applications
.NET 2.0 Web Applications
.NET 2.0 Distributed Applications
SQL Server 2005
Sharepoint Services 3.0 Application Development
Windows Vista Client Configuration

Comments and Discussions