99 lines
2.9 KiB
C#
99 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Project.Dialog
|
|
{
|
|
public partial class fInput : Form
|
|
{
|
|
public fInput(string value,string title="")
|
|
{
|
|
InitializeComponent();
|
|
|
|
if (title.isEmpty() == false) this.Text = title;
|
|
this.tbInput.KeyDown += (s1, e1) => { if (e1.KeyCode == Keys.Enter) Confirm(); };
|
|
this.KeyPreview = true;
|
|
this.KeyDown += (s1, e1) => {
|
|
if (e1.KeyCode == Keys.Escape) this.Close();
|
|
};
|
|
this.tbInput.Text = value;
|
|
}
|
|
|
|
private void Confirm()
|
|
{
|
|
string id = tbInput.Text.Trim();
|
|
if (id.isEmpty())
|
|
{
|
|
tbInput.Focus();
|
|
return;
|
|
}
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
|
|
private void touchKey1_keyClick(string key)
|
|
{
|
|
if (key == "BACK" || key == "◁")
|
|
{
|
|
if (!tbInput.Text.isEmpty())
|
|
{
|
|
if (tbInput.Text.Length == 1) tbInput.Text = "";
|
|
else tbInput.Text = tbInput.Text.Substring(0, tbInput.Text.Length - 1);
|
|
}
|
|
//if (tbInput.Text == "") tbInput.Text = "0";
|
|
}
|
|
else if(key == "-")
|
|
{
|
|
if (tbInput.Text.StartsWith("-") == false)
|
|
tbInput.Text = "-" + tbInput.Text;
|
|
else tbInput.Text = tbInput.Text.Substring(1);
|
|
}
|
|
else if (key == "CLEAR" || key == "RESET" || key == "◀")
|
|
{
|
|
tbInput.Text = "0";
|
|
}
|
|
else if (key == "ENTER" || key == "ENT")
|
|
{
|
|
Confirm();
|
|
}
|
|
else if(key == ".")
|
|
{
|
|
if (tbInput.Text != "" && tbInput.Text.IndexOf(".") == -1) tbInput.Text += ".";
|
|
}
|
|
else
|
|
{
|
|
if (tbInput.SelectionLength > 0 && tbInput.Text.Length == tbInput.SelectionLength)
|
|
{
|
|
tbInput.Text = key;
|
|
}
|
|
else if (tbInput.SelectionLength > 0)
|
|
{
|
|
//선택된 영역을 대체해준다.
|
|
tbInput.SelectedText = key;
|
|
}
|
|
else
|
|
{
|
|
//if(tbInput.Text.IndexOf(".") == -1)
|
|
tbInput.Text += key;
|
|
}
|
|
|
|
}
|
|
|
|
tbInput.SelectionLength = 0;
|
|
if (!tbInput.Text.isEmpty())
|
|
tbInput.SelectionStart = tbInput.Text.Length;
|
|
}
|
|
|
|
private void fInput_Load(object sender, EventArgs e)
|
|
{
|
|
this.Show();
|
|
this.tbInput.SelectAll();
|
|
this.tbInput.Focus();
|
|
}
|
|
}
|
|
}
|