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

Windows Mobile Password Safe

, 12 Jan 2009
A password safe with a touch screen UI introducing Fluid Controls.
PasswordSafeExe.zip
PasswordSafeSource.zip
PasswordSafe
Fluditity
bin
Classes
vssver2.scc
Controls
enums
vssver2.scc
Events
vssver2.scc
Interfaces
vssver2.scc
vssver2.scc
Fluid.csproj.user
GdiPlus
mssccprj.scc
NativeMethods
vssver2.scc
vssver2.scc
Native
vssver2.scc
obj
Properties
vssver2.scc
vssver2.scc
PasswordSafe
bin
Release
Fluid.dll
passwords.pws
PasswordSafe.exe
Classes
vssver2.scc
Encryption
vssver2.scc
EventArgs
vssver2.scc
ListBoxes
vssver2.scc
PasswordSafe.csproj.user
Properties
vssver2.scc
Resources
lock.bmp
minus.png
props.bmp
save.bmp
saved.bmp
search.bmp
searchd.bmp
undo24.bmp
undo24_d.bmp
Untitled.png
vssver2.scc
security.ico
Templates
vssver2.scc
Themes
vssver2.scc
vssver2.scc
Xml
vssver2.scc
vssver2.scc
using System;

using System.Collections.Generic;
using System.Text;
using Fluid.Controls.Classes;
using System.Drawing;
using Fluid.Drawing;

namespace Fluid.Controls
{
    public class ButtonGroup : ControlContainer, ICommandContainer,ILayoutPanel
    {
        public ButtonGroup()
            : base()
        {
        }

        public ButtonGroup(int x, int y, int width, int height)
            : base(x, y, width, height)
        {
        }

        protected override void InitControl()
        {
            buttons = new ButtonCollection(this);
            base.InitControl();
        }


        private RoundedCorners corners = RoundedCorners.All;
        public RoundedCorners Corners
        {
            get { return corners; }
            set
            {
                if (corners != value)
                {
                    corners = value;
                    Render();
                }
            }
        }


        private ButtonCollection buttons;

        public ButtonCollection Buttons
        {
            get { return buttons; }
        }

        public void Add(FluidButton button)
        {
            buttons.Add(button);
        }

        public void RemoveAt(int index)
        {
            buttons.RemoveAt(index);
        }

        public void Clear()
        {
            buttons.Clear();
        }

        private int buttonWidth = 0;

        /// <summary>
        /// Gets or sets the width for all but the last button. if set to 0, the width is determined automatically.
        /// </summary>
        public int ButtonWidth
        {
            get { return buttonWidth; }
            set
            {
                if (buttonWidth != value)
                {
                    buttonWidth = value;
                    Render();
                    Invalidate();
                }
            }
        }

        protected override void OnPaintBackground(FluidPaintEventArgs e)
        {
            // do nothing!
        }

        /// <summary>
        /// Renders the buttons;
        /// </summary>
        public void Render()
        {
            if (buttons == null) return;
            int c = buttons.Count;
            controls.Clear();
            int index = 0;
            int x = 0;
            int y = 0;
            int h = Bounds.Height;
            int w0 = c > 0 ? Bounds.Width / c : 0;

            if (buttonWidth > 0) w0 = Math.Min(buttonWidth, Width);

            c--;
            RoundedCorners corners = c == 0 ? RoundedCorners.All : RoundedCorners.Left;
            foreach (FluidButton btn in buttons)
            {
                btn.BeginInit();
                int w = (index != c) ? w0 : (Bounds.Width - x);
                if (btn.BackColor == Color.Transparent || btn.BackColor.IsEmpty)
                {
                    btn.BackColor = this.BackColor;
                }
                btn.Bounds = new Rectangle(x, y, w + ((index != c) ? (int)ScaleFactor.Width : 0), h);
                btn.ScaleFactor = ScaleFactor;
                btn.Corners = corners & Corners;
                btn.Command = index.ToString();
                //btn.Alpha = alpha;
                btn.Anchor = System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom;
                btn.EndInit();
                index++;
                controls.Add(btn);
                x += w;
                corners = index == c ? RoundedCorners.Right : RoundedCorners.None;
            }
            Invalidate();
            OnButtonsChanged();
        }

        private int alpha = 255;
        public int Alpha
        {
            get { return alpha; }
            set
            {
                if (alpha != value)
                {
                    alpha = value;
                    ModifyAlpha(alpha);
                }
            }
        }

        private void ModifyAlpha(int alpha)
        {
            foreach (FluidControl c in controls)
            {
                FluidButton btn = (FluidButton)c;
                btn.Alpha = alpha;
            }
        }

        protected virtual void OnButtonsChanged()
        {
            if (ButtonsChanged != null) ButtonsChanged(this, EventArgs.Empty);
        }

        public event EventHandler ButtonsChanged;


        private ButtonGroupEventArgs clickEvent;
        public override void RaiseCommand(CommandEventArgs e)
        {
            // base.RaiseCommand(e); // do not fire to parent containers!
            if (ButtonClick != null)
            {
                if (clickEvent == null) clickEvent = new ButtonGroupEventArgs();
                int index = int.Parse(e.Command);
                clickEvent.Index = index;
                clickEvent.Button = buttons[index];
                ButtonClick(this, clickEvent);
            }

        }

        protected override void OnSizeChanged(Size oldSize, Size newSize)
        {
            base.OnSizeChanged(oldSize, newSize);
            if (!oldSize.IsEmpty)
            {
                Render();
            }
        }

        /// <summary>
        /// Occurs when a button was clicked.
        /// </summary>
        public event EventHandler<ButtonGroupEventArgs> ButtonClick;

        public override void Scale(SizeF scaleFactor)
        {
            base.Scale(scaleFactor);
            ButtonWidth = (int)(ButtonWidth * scaleFactor.Width);
        }
    }
}

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

Thomas Gerber
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

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 12 Jan 2009
Article Copyright 2009 by Thomas Gerber
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid