using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using ryControls; namespace ryControls { /// /// 选择文本框 /// [DefaultEvent("OnSelected")] public partial class DoubleText : UserControl { /// /// 选择文本框 /// public DoubleText() { InitializeComponent(); txtInfo.Font = Font; base.GotFocus += DoubleText_Enter; } private Color _baseColor = Color.FromArgb(12, 125, 182);//基颜色 /// ///按钮基础背景色 /// [Description("按钮基础背景色")] [DefaultValue(typeof(Color), "12, 125, 182")] public Color BaseColor { get { return _baseColor; } set { _baseColor = value; btnSelected.BaseColor = _baseColor; } } private bool _UseDefSkin = true; /// ///优先使用默认皮肤 /// [Description("优先使用默认皮肤")] [DefaultValue(typeof(bool), "true")] public bool UseDefSkin { get { return _UseDefSkin; } set { _UseDefSkin = value; btnSelected.UseDefSkin = _UseDefSkin; base.Invalidate(); } } /// /// 选择的id /// public string selectId = ""; /// /// 选择的名称 /// public string SelectName { get { return txtInfo.Text; } set { txtInfo.Text = value; toolTip1.SetToolTip(txtInfo, value); toolTip1.SetToolTip(this, value); } } /// /// 选择的名称 /// public override string Text { get { return SelectName; } set { SelectName = value; } } /// /// 字体 /// public override Font Font { get { return txtInfo.Font; } set { txtInfo.Font = value; } } /// /// 重新设置大小 /// public void ResizeSize() { txtInfo.Location = new Point(3, 1); txtInfo.Top = (Height - txtInfo.Height) / 2; //Height = txtInfo.Height; btnSelected.Height = Height; btnSelected.Width = Height; btnSelected.Location = new Point(Width- btnSelected.Width, 0); txtInfo.Width = Width - btnSelected.Width-3; } /// /// 在选择时激发 /// [Description("在选择时激发")] public event EventHandler OnSelected; private void DoubleText_Load(object sender, EventArgs e) { ResizeSize(); } private void DoubleText_Resize(object sender, EventArgs e) { ResizeSize(); } /// /// 点击选择 /// public void PerformClick() { btnSelected.PerformClick(); } private void BtnSelected_Click(object sender, EventArgs e) { OnSelected?.Invoke(this, new EventArgs()); } private void TxtInfo_DoubleClick(object sender, EventArgs e) { OnSelected?.Invoke(this, new EventArgs()); } private void DoubleText_FontChanged(object sender, EventArgs e) { txtInfo.Font = Font; btnSelected.Font = Font; ResizeSize(); } private void DoubleText_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawRectangle(new Pen(SkinHelp.DefalutBorderColor), new Rectangle(0, 0, this.Width - 1, this.Height - 1)); } private void TxtInfo_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode==Keys.Enter) { OnSelected?.Invoke(this, new EventArgs()); } } private void DoubleText_Enter(object sender, EventArgs e) { txtInfo.Focus(); txtInfo.Select(); } } }