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 CPOL
A password safe with a touch screen UI introducing Fluid Controls.
PasswordSafeExe.zip
Fluid.dll
passwords.pws
PasswordSafe.exe
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 System.Drawing;
using System.Windows.Forms;
using Fluid.Classes;

namespace Fluid.Controls
{
    /// <summary>
    /// An ok-cancel dialog.
    /// When one of the buttons is pressed, the dialog closes and raises the Result event.
    /// </summary>
    /// <example>
    /// You can create a MessageDialog, open it modal and decide what to do on the Result event:
    /// MessageDialog dlg = new MessageDlg():
    /// 
    /// dlg.Text = "Hello";
    /// dlg.Result += new EventHandler<DialogEventArgs>(dialog_Result);
    /// dlg.ShowModal(ShowAnimation.FromBottom);
    /// </example>
    public class MessageDialog : FluidPanel
    {
        protected override void InitControl()
        {
            base.InitControl();
            Bounds = new Rectangle(0, 0, 240, 100);
            BackColor = Color.Black;
            ForeColor = Color.White;
            GradientFill = true;
            GradientFillOffset = 24;
            EnableDoubleBuffer = true;
            FluidButton okBtn = new FluidButton("OK", 8, 68, 100, 24);
            okBtn.ForeColor = Color.White;
            okBtn.Anchor = AnchorBL;
            this.okBtn = okBtn;
            okBtn.BackColor = Color.Green;
            okBtn.Click += new EventHandler(okBtn_Click);

            FluidButton cancelBtn = new FluidButton("Cancel", 240 - 100 - 8, 68, 100, 24);
            this.cancelBtn = cancelBtn;
            cancelBtn.ForeColor = Color.White;
            cancelBtn.Anchor = AnchorBR;
            cancelBtn.BackColor = Color.Red;
            cancelBtn.Click += new EventHandler(cancelBtn_Click);
            Visible = false;

            FluidLabel textLabel = new FluidLabel("", 4, 12, Width - 8, 68 - 12 - 4);
            textLabel.Format.FormatFlags = 0;
            textLabel.Anchor = AnchorAll;
            textLabel.LineAlignment = StringAlignment.Center;
            textLabel.Alignment = StringAlignment.Center;
            this.textLabel = textLabel;

            Controls.Add(textLabel);
            Controls.Add(okBtn);
            Controls.Add(cancelBtn);
        }

        FluidLabel textLabel;
        FluidButton okBtn;
        FluidButton cancelBtn;

        /// <summary>
        /// Gets or sets the Alignment for the dialog text.
        /// </summary>
        public StringAlignment Alignment
        {
            get { return textLabel.Alignment; }
            set { textLabel.Alignment = value; }
        }

        /// <summary>
        /// Gets or sets the Line Alignment for the dialog text.
        /// </summary>
        public StringAlignment LineAlignment
        {
            get { return textLabel.LineAlignment; }
            set { textLabel.LineAlignment = value; }
        }

        /// <summary>
        /// Gets or sets the text for the dialog.
        /// </summary>
        public string Message
        {
            get { return textLabel.Text; }
            set
            {
                textLabel.Text = value;
                if (value != null && value.IndexOf('\n') >= 0)
                {
                    textLabel.LineAlignment = StringAlignment.Near;
                }
                else
                {
                    textLabel.LineAlignment = StringAlignment.Center;
                }
            }
        }

        /// <summary>
        /// Gets or sets the text for the OK button.
        /// </summary>
        public string OkText
        {
            get { return okBtn.Text; }
            set
            {
                if (value != null)
                {
                    if (value == string.Empty) value = "OK";
                    okBtn.Text = value;
                    okBtn.Visible = true;
                }
                else
                {
                    okBtn.Visible = false;
                }
            }
        }

        /// <summary>
        /// Gets or sets the text for the Cancel button.
        /// </summary>
        public string CancelText
        {
            get { return cancelBtn.Text; }
            set
            {
                if (value != null)
                {
                    if (value == string.Empty) value = "Cancel";
                    cancelBtn.Text = value;
                    cancelBtn.Visible = true;
                }
                else
                {
                    cancelBtn.Visible = false;
                }
            }
        }

        void okBtn_Click(object sender, EventArgs e)
        {
            Close(ShowTransition.FromBottom);
            OnResult(DialogResult.OK);
        }

        void cancelBtn_Click(object sender, EventArgs e)
        {
            Close(ShowTransition.FromBottom);
            OnResult(DialogResult.Cancel);
        }

        protected virtual void OnResult(DialogResult result)
        {
            if (Result != null)
            {
                dialogEventArgs.Result = result;
                Result(this, dialogEventArgs);
            }
        }



        /// <summary>
        /// Occurs when the either the ok or cancel button was pressed and the dialog is closed.
        /// </summary>
        private DialogEventArgs dialogEventArgs = new DialogEventArgs();

        /// <summary>
        /// Occurs when the either the ok or cancel button was pressed and the dialog is closed.
        /// </summary>
        public event EventHandler<DialogEventArgs> Result;

        public static void Show(string message, string okText, string cancelText)
        {
            Show(message, okText, cancelText, Color.Empty);
        }

        public static void Show(string message, string okText, string cancelText, Color backColor)
        {
            MessageDialog dialog = new MessageDialog();
            if (!backColor.IsEmpty) dialog.BackColor = backColor;
            dialog.Message = message;
            dialog.OkText = okText;
            dialog.CancelText = cancelText;
            dialog.ShowModal(ShowTransition.FromBottom);
        }

        public override void Show(ShowTransition transition)
        {
            CenterButtonIfSingle();
            base.Show(transition);
        }

        private void CenterButtonIfSingle()
        {
            if (okBtn.Visible || cancelBtn.Visible)
            {
                if (cancelBtn.Visible == false)
                {
                    okBtn.Left = (Width - okBtn.Width) / 2;
                }
                else
                {
                    okBtn.Left = ScaleX(8);
                }
                if (okBtn.Visible == false)
                {
                    cancelBtn.Left = (Width - cancelBtn.Width) / 2;
                }
                else
                {
                    cancelBtn.Left = Width - cancelBtn.Width - ScaleX(8);
                }
            }
        }

    }
}

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 | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 12 Jan 2009
Article Copyright 2009 by Thomas Gerber
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid