Click here to Skip to main content
15,896,118 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 161.5K   3.1K   139  
A password safe with a touch screen UI introducing Fluid Controls.
using System;

using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using System.Drawing;
using PasswordSafe.Classes;
using PasswordSafe.ListBoxes;
using PasswordSafe.Properties;

namespace PasswordSafe.Templates
{
    public class SelectCategoryTemplate : FluidTemplate
    {
        private FluidLabel titleLabel;
        private FluidButton removeBtn;
        private FluidButton addBtn;

        protected override void InitControl()
        {
            base.InitControl();
            const int w0 = 240;
            const int h0 = 64;
            const int bw1 = 24;
            const int bw2 = 24;
            this.Bounds = new Rectangle(0, 0, w0, h0);
            titleLabel = new FluidLabel("", bw1 + 4, 0, w0 - bw1 - bw2 - 8, h0);
            titleLabel.LineAlignment = StringAlignment.Center;
            titleLabel.Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Bold);
            Controls.Add(titleLabel);

            Font btnFont = new Font(FontFamily.GenericSansSerif, 6f, FontStyle.Regular);
            removeBtn = new FluidButton("", w0 - bw2 - 4, 4, bw2, 24);
            removeBtn.Image = Resources.minus;
            removeBtn.BackColor = Theme.Current.ItemButtonColor;
            removeBtn.ForeColor = Color.White;
            removeBtn.Font = btnFont;
            removeBtn.Visible = false;
            removeBtn.Click += new EventHandler(removeBtnClick);

            addBtn = new FluidButton("", 4, 4, bw1, 24);
            addBtn.Image = Resources.plus;
            addBtn.BackColor = Theme.Current.ItemButtonColor;
            addBtn.Font = btnFont;
            addBtn.ForeColor = Color.White;
            addBtn.Visible = true;
            addBtn.Click += new EventHandler(addBtnClick);

            Controls.Add(removeBtn);
            Controls.Add(addBtn);

            titleLabel.Anchor = AnchorAll;
            addBtn.Anchor = AnchorTL;
            removeBtn.Anchor = AnchorTR;
        }


        CategoryListBox ListBox { get { return Parent as CategoryListBox; } }

        void addBtnClick(object sender, EventArgs e)
        {
            AddItem();
        }

        void removeBtnClick(object sender, EventArgs e)
        {
            RemoveItem();

        }

        private void AddItem()
        {
            CategoryListBoxItem item = Item as CategoryListBoxItem;
            if (item != null)
            {
                item.IsUsed = true;
                InvalidateItem();
            }
        }

        private void RemoveItem()
        {
            CategoryListBoxItem item = Item as CategoryListBoxItem;
            if (item != null)
            {
                item.IsUsed = false;
                InvalidateItem();
            }
        }

        public void InvalidateItem()
        {
            ListBox.InvalidateItem(ItemIndex);
            //            ListBox.Invalidate();
        }


        protected override void OnItemUpdate(object value)
        {
            base.OnItemUpdate(value);
            CategoryListBoxItem item = value as CategoryListBoxItem;
            if (item != null)
            {
                titleLabel.Text = item.Title;
                removeBtn.Visible = item.IsUsed;
                addBtn.Visible = !item.IsUsed;
                titleLabel.ForeColor = !item.IsUsed ? Color.Empty : Theme.Current.GrayTextColor;
            }
            else
            {
                titleLabel.Text = "";
                removeBtn.Visible = false;
                addBtn.Visible = false;
            }
        }
    }
}

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