You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

237 lines
6.1 KiB

using System;
using System.Drawing;
using System.Windows.Forms;
using CK.SCP.Utils;
namespace CK.SCP.Common
{
public partial class CktTextBox : UserControl
{
public CktTextBox()
{
InitializeComponent();
txtValue.Width = Width - Lbl.Width - 3;
}
public bool IsNum { get; set; } = false;
public string LblText
{
get { return Lbl.Text; }
set
{
Lbl.Text = value;
// using (var g = this.CreateGraphics())
// {
// var strSize = g.MeasureString(Caption.Text, Caption.Font);
// Caption.Width = (int)strSize.Width + 6;
// }
}
}
public string RearLblText
{
get { return lblRear.Text; }
set
{
lblRear.Visible = !string.IsNullOrEmpty(value);
lblRear.Text = value;
}
}
public int RearLblWidth
{
get { return lblRear.Width; }
set { lblRear.Width = value; }
}
public string Value
{
get { return txtValue.Text; }
set { txtValue.Text = value; }
}
public int IntValue
{
get
{
if (string.IsNullOrEmpty(txtValue.Text) && IsNum)
{
return 0;
}
int value;
if (!int.TryParse(txtValue.Text, out value))
{
//throw new Exception($"请在{Lbl.Text}中输入数字");
}
return value;
}
set { txtValue.Text = value.ToString(); }
}
public decimal DecimalValue
{
get
{
if (string.IsNullOrEmpty(txtValue.Text) && IsNum)
{
return 0;
}
decimal value;
if (!decimal.TryParse(txtValue.Text, out value))
{
// throw new Exception($"请在{Lbl.Text}中输入数字");
}
return value;
}
set { txtValue.Text = value.ToString(); }
}
public override string Text
{
get { return txtValue.Text; }
set { txtValue.Text = value; }
}
public int BoxWidth { get; set; }
// get { return txtValue.Width; }
// set { txtValue.Width = value; }
public int LblWidth
{
get { return Lbl.Width; }
set
{
Lbl.Width = value;
txtValue.Width = Width - Lbl.Width - 3;
}
}
public Boolean ReadOnly
{
get
{
return txtValue.ReadOnly;
}
set
{
txtValue.ReadOnly = value;
if (value)
{
txtValue.ButtonCustom.Visible = false;
txtValue.BackColor = Color.LightGray;
}
else
{
txtValue.BackColor = Color.White;
}
}
}
public string ButtonText
{
get { return txtValue.ButtonCustom.Text; }
set { txtValue.ButtonCustom.Text = value; }
}
public Boolean UserSystemPasswordChar
{
get { return txtValue.UseSystemPasswordChar; }
set { txtValue.UseSystemPasswordChar = value; }
}
public void FocusToValue()
{
txtValue.Focus();
}
public bool Multiline
{
get { return txtValue.Multiline; }
set { txtValue.Multiline = value; }
}
public StringAlignment LblTextAlign
{
get { return Lbl.TextAlignment; }
set { Lbl.TextAlignment = value; }
}
public bool ButtonVisible
{
get { return txtValue.ButtonCustom.Visible; }
set { txtValue.ButtonCustom.Visible = value; }
}
private void UcLabelTextBox_SizeChanged(object sender, EventArgs e)
{
txtValue.Width = Width - Lbl.Width - 3;
}
public delegate void TextChangedHandler(object sender, EventArgs e);
public event TextChangedHandler TxtTextChanged;
private void txtValue_TextChanged(object sender, EventArgs e)
{
try
{
TxtTextChanged?.Invoke(sender, e);
}
catch
{
// ignored
}
}
public delegate void DoubleClickHandler(object sender, EventArgs e);
public event DoubleClickHandler TxtDoubleClick;
private void txtValue_DoubleClick(object sender, EventArgs e)
{
try
{
TxtDoubleClick?.Invoke(sender, e);
}
catch
{
// ignored
}
}
public delegate void TxtKeyPressHandler(object sender, KeyPressEventArgs e);
public event TxtKeyPressHandler TxtKeyPress;
private void txtValue_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != (char)Keys.Enter) return;
try
{
TxtKeyPress?.Invoke(sender, e);
}
catch (Exception ex)
{
MessageHelper.ShowInfo(ex.Message);
}
}
public delegate void ButtonCustomClickHandler(object sender, EventArgs e);
public event ButtonCustomClickHandler ButtonCustomClick;
private void txtValue_ButtonCustomClick(object sender, EventArgs e)
{
try
{
ButtonCustomClick?.Invoke(sender, e);
}
catch
{
// ignored
}
}
}
}