📄 newaccountform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MvmMoney
{
/// <summary>
/// Summary description for NewAccountForm.
/// </summary>
public class NewAccountForm : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem_Done;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.MenuItem menuItem_Cancel;
public NewAccountForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.SetInputMode(this.textBox1,InputMode.Text);
this.SetInputMode(this.textBox2,InputMode.Numbers);
this.textBox1.Focus();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem_Done = new System.Windows.Forms.MenuItem();
this.menuItem_Cancel = new System.Windows.Forms.MenuItem();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
//
// mainMenu1
//
this.mainMenu1.MenuItems.Add(this.menuItem_Done);
this.mainMenu1.MenuItems.Add(this.menuItem_Cancel);
//
// menuItem_Done
//
this.menuItem_Done.Text = "Done";
this.menuItem_Done.Click += new System.EventHandler(this.menuItem_Done_Click);
//
// menuItem_Cancel
//
this.menuItem_Cancel.Text = "Cancel";
this.menuItem_Cancel.Click += new System.EventHandler(this.menuItem_Cancel_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Size = new System.Drawing.Size(152, 22);
this.label1.Text = "Account Name";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 32);
this.textBox1.Size = new System.Drawing.Size(152, 25);
this.textBox1.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 64);
this.label2.Size = new System.Drawing.Size(152, 22);
this.label2.Text = "Initial Balance";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(8, 88);
this.textBox2.Size = new System.Drawing.Size(152, 25);
this.textBox2.Text = "0";
this.textBox2.LostFocus += new System.EventHandler(this.textBox2_LostFocus);
//
// NewAccountForm
//
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label2);
this.Menu = this.mainMenu1;
this.Text = "Create Account";
}
#endregion
// Interop declarations
[DllImport("coredll.dll", EntryPoint="GetCapture")]
private static extern IntPtr GetCapture();
[DllImport("coredll.dll", EntryPoint="GetWindow")]
private static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
[DllImport("coredll.dll", EntryPoint="SendMessage")]
private static extern uint SendMessage(IntPtr hWnd, uint msg, uint wParam,
uint lParam);
// Constants required for interop
const int GW_CHILD = 5;
const uint EM_SETINPUTMODE = 0x00DE;
public void SetInputMode(Control ctrl, InputMode mode)
{
// Get the handle for the current control
ctrl.Capture = true;
IntPtr h = GetCapture();
ctrl.Capture = false;
// Get the child window for the control
IntPtr hEditbox = GetWindow(h, GW_CHILD);
// Set the input mode
SendMessage(hEditbox, EM_SETINPUTMODE, 0, (uint)mode);
}
// Input mode enumeration
public enum InputMode
{
Spell = 0,
T9 = 1,
Numbers = 2,
Text = 3
}
private void menuItem_Cancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void menuItem_Done_Click(object sender, System.EventArgs e)
{
double initBalance=0;
if(this.textBox1.Text.Trim().Length==0)
{
MessageBox.Show("Please input account name.","Error",MessageBoxButtons.OK,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
return;
}
if(Form1.db.GetAccountId(this.textBox1.Text)!=-1)
{
MessageBox.Show("The account name \""+this.textBox1.Text+"\" has existed. Input another one.","Error",MessageBoxButtons.OK,MessageBoxIcon.Hand,MessageBoxDefaultButton.Button1);
return;
}
try
{
initBalance=System.Double.Parse(this.textBox2.Text);
initBalance= (System.Math.Ceiling(initBalance*100))/100;
}
catch(Exception)
{
MessageBox.Show("Invalid initial balance value.","Error",MessageBoxButtons.OK,MessageBoxIcon.Hand,MessageBoxDefaultButton.Button1);
return;
}
Form1.db.NewAccount(this.textBox1.Text,initBalance);
this.Close();
}
private void textBox2_LostFocus(object sender, System.EventArgs e)
{
double amount;
try
{
amount=System.Double.Parse(this.textBox2.Text);
amount=(System.Math.Ceiling(amount*100))/100;
this.textBox2.Text=amount+"";
}
catch(Exception)
{
return;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -