240 lines
7.3 KiB
C#
240 lines
7.3 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace HYJig
|
|
{
|
|
public partial class PromptDlg : Form
|
|
{
|
|
public PromptDlg(IntPtr hWnd, Color bkColor)
|
|
{
|
|
this.InitializeComponent();
|
|
this.intptr_0 = hWnd;
|
|
base.Location = new Point(100, 100);
|
|
this.BackColor = bkColor;
|
|
base.Show(new JigWindowHandle(this.intptr_0));
|
|
}
|
|
|
|
public string GetInputValue()
|
|
{
|
|
string text;
|
|
if (this.bool_2)
|
|
{
|
|
text = this.textBox_0.Text;
|
|
}
|
|
else
|
|
{
|
|
text = null;
|
|
}
|
|
return text;
|
|
}
|
|
|
|
public void SetInputValue(string strText)
|
|
{
|
|
if (this.bool_2)
|
|
{
|
|
this.textBox_0.Text = strText;
|
|
}
|
|
}
|
|
|
|
public void SetDlgState(string strPrompt, bool bShowPrompt, string strInput, bool bShowInput)
|
|
{
|
|
this.label_0.Text = strPrompt;
|
|
Control control = this.label_0;
|
|
this.bool_1 = bShowPrompt;
|
|
control.Visible = bShowPrompt;
|
|
this.textBox_0.Text = strInput;
|
|
Control control2 = this.textBox_0;
|
|
this.bool_2 = bShowInput;
|
|
control2.Visible = bShowInput;
|
|
this.method_1();
|
|
}
|
|
|
|
public void OnFocusChangeEvent(object sender, bool bHadFocus)
|
|
{
|
|
if (this.bool_0)
|
|
{
|
|
this.bool_0 = false;
|
|
}
|
|
else
|
|
{
|
|
this.DlgVisible(bHadFocus);
|
|
}
|
|
}
|
|
|
|
public void DlgVisible(bool bVisible)
|
|
{
|
|
base.Visible = bVisible;
|
|
if (bVisible)
|
|
{
|
|
this.bool_0 = true;
|
|
Class1.SetCapture(this.intptr_0);
|
|
Class1.SetFocus(this.intptr_0);
|
|
}
|
|
else
|
|
{
|
|
Class1.ReleaseCapture();
|
|
}
|
|
}
|
|
|
|
public void OnKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (this.bool_2)
|
|
{
|
|
if ((e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) || (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9))
|
|
{
|
|
string text = this.GetInputValue() + this.method_0(e);
|
|
this.SetInputValue(text);
|
|
}
|
|
else if (e.KeyCode == Keys.Back)
|
|
{
|
|
string text2 = this.GetInputValue();
|
|
if (!string.IsNullOrEmpty(text2))
|
|
{
|
|
text2 = text2.Substring(0, text2.Length - 1);
|
|
this.SetInputValue(text2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void textBox_0_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (this.method_2())
|
|
{
|
|
this.method_1();
|
|
}
|
|
}
|
|
|
|
private string method_0(KeyEventArgs keyEventArgs_0)
|
|
{
|
|
int num;
|
|
if (keyEventArgs_0.KeyCode >= Keys.D0 && keyEventArgs_0.KeyCode <= Keys.D9)
|
|
{
|
|
num = keyEventArgs_0.KeyCode - Keys.D0;
|
|
}
|
|
else
|
|
{
|
|
if (keyEventArgs_0.KeyCode < Keys.NumPad0 || keyEventArgs_0.KeyCode > Keys.NumPad9)
|
|
{
|
|
return null;
|
|
}
|
|
num = keyEventArgs_0.KeyCode - Keys.NumPad0;
|
|
}
|
|
return num.ToString();
|
|
}
|
|
public static void GetWinFormXYDpi(ref double Xdpi, ref double Ydpi)
|
|
{
|
|
using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
|
|
{
|
|
Xdpi = (double)graphics.DpiX;
|
|
Ydpi = (double)graphics.DpiY;
|
|
}
|
|
Xdpi /= 96.0;
|
|
Ydpi /= 96.0;
|
|
}
|
|
private void method_1()
|
|
{
|
|
double num = 1.0;
|
|
double num2 = 1.0;
|
|
GetWinFormXYDpi(ref num, ref num2);
|
|
int num3 = 1;
|
|
if (this.bool_1)
|
|
{
|
|
int num4 = (int)this.label_0.CreateGraphics().MeasureString(this.label_0.Text, this.Font).Width;
|
|
this.label_0.Location = new Point(num3, 2);
|
|
this.label_0.Size = new Size(num4, 12);
|
|
num3 += num4 + 2;
|
|
}
|
|
if (this.bool_2)
|
|
{
|
|
int width = this.textBox_0.Width;
|
|
this.textBox_0.Location = new Point(num3, 1);
|
|
this.textBox_0.Size = new Size(Convert.ToInt32(width), Convert.ToInt32(10.0 * num2));
|
|
num3 += width + 1;
|
|
}
|
|
base.Size = new Size(Convert.ToInt32(num3), Convert.ToInt32(16.0 * num2));
|
|
}
|
|
|
|
private bool method_2()
|
|
{
|
|
int num = 30;
|
|
int num2 = (int)this.textBox_0.CreateGraphics().MeasureString(this.textBox_0.Text, this.Font).Width;
|
|
if (num2 > this.textBox_0.Width)
|
|
{
|
|
this.textBox_0.Width = num2;
|
|
}
|
|
else
|
|
{
|
|
if (num2 >= this.textBox_0.Width)
|
|
{
|
|
return false;
|
|
}
|
|
if (num2 >= num)
|
|
{
|
|
this.textBox_0.Width = num2;
|
|
}
|
|
else
|
|
{
|
|
this.textBox_0.Width = num;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
this.label_0 = new Label();
|
|
this.textBox_0 = new TextBox();
|
|
base.SuspendLayout();
|
|
this.label_0.AutoSize = true;
|
|
this.label_0.Location = new Point(4, 3);
|
|
this.label_0.Name = "m_labelPrompt";
|
|
this.label_0.Size = new Size(53, 12);
|
|
this.label_0.TabIndex = 1;
|
|
this.label_0.Text = "拖动提示";
|
|
this.textBox_0.BorderStyle = BorderStyle.None;
|
|
this.textBox_0.Location = new Point(58, 3);
|
|
this.textBox_0.Name = "m_textInput";
|
|
this.textBox_0.Size = new Size(52, 14);
|
|
this.textBox_0.TabIndex = 0;
|
|
this.textBox_0.TextChanged += this.textBox_0_TextChanged;
|
|
base.AutoScaleDimensions = new SizeF(6f, 12f);
|
|
base.AutoScaleMode = AutoScaleMode.Font;
|
|
base.ClientSize = new Size(171, 50);
|
|
base.ControlBox = false;
|
|
base.Controls.Add(this.textBox_0);
|
|
base.Controls.Add(this.label_0);
|
|
base.ShowIcon = false;
|
|
base.ShowInTaskbar = false;
|
|
base.FormBorderStyle = FormBorderStyle.None;
|
|
base.MaximizeBox = false;
|
|
base.MinimizeBox = false;
|
|
base.Name = "PromptDlg";
|
|
this.DoubleBuffered = true;
|
|
base.SizeGripStyle = SizeGripStyle.Hide;
|
|
base.StartPosition = FormStartPosition.Manual;
|
|
this.Text = "PromptDlg";
|
|
base.ResumeLayout(false);
|
|
base.PerformLayout();
|
|
}
|
|
|
|
public PromptDlg.DoWhenMouseMove MouseMoveArgs;
|
|
|
|
private bool bool_0 = true;
|
|
|
|
private bool bool_1 = false;
|
|
|
|
private bool bool_2 = false;
|
|
|
|
private IntPtr intptr_0;
|
|
|
|
private Label label_0;
|
|
|
|
private TextBox textBox_0;
|
|
|
|
public delegate void DoWhenMouseMove();
|
|
}
|
|
}
|