174 lines
4.6 KiB
C#
174 lines
4.6 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 选择文本框
|
|
/// </summary>
|
|
[DefaultEvent("OnSelected")]
|
|
public partial class DoubleText : UserControl
|
|
{
|
|
/// <summary>
|
|
/// 选择文本框
|
|
/// </summary>
|
|
public DoubleText()
|
|
{
|
|
InitializeComponent();
|
|
txtInfo.Font = Font;
|
|
base.GotFocus += DoubleText_Enter;
|
|
}
|
|
private Color _baseColor = Color.FromArgb(12, 125, 182);//基颜色
|
|
/// <summary>
|
|
///按钮基础背景色
|
|
/// </summary>
|
|
[Description("按钮基础背景色")]
|
|
[DefaultValue(typeof(Color), "12, 125, 182")]
|
|
public Color BaseColor
|
|
{
|
|
get { return _baseColor; }
|
|
set
|
|
{
|
|
_baseColor = value;
|
|
btnSelected.BaseColor = _baseColor;
|
|
}
|
|
}
|
|
private bool _UseDefSkin = true;
|
|
/// <summary>
|
|
///优先使用默认皮肤
|
|
/// </summary>
|
|
[Description("优先使用默认皮肤")]
|
|
[DefaultValue(typeof(bool), "true")]
|
|
public bool UseDefSkin
|
|
{
|
|
get
|
|
{
|
|
return _UseDefSkin;
|
|
}
|
|
set
|
|
{
|
|
_UseDefSkin = value;
|
|
btnSelected.UseDefSkin = _UseDefSkin;
|
|
base.Invalidate();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 选择的id
|
|
/// </summary>
|
|
public string selectId = "";
|
|
/// <summary>
|
|
/// 选择的名称
|
|
/// </summary>
|
|
public string SelectName
|
|
{
|
|
get { return txtInfo.Text; }
|
|
set { txtInfo.Text = value; toolTip1.SetToolTip(txtInfo, value); toolTip1.SetToolTip(this, value); }
|
|
}
|
|
/// <summary>
|
|
/// 选择的名称
|
|
/// </summary>
|
|
public override string Text
|
|
{
|
|
get
|
|
{
|
|
return SelectName;
|
|
}
|
|
set
|
|
{
|
|
SelectName = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 字体
|
|
/// </summary>
|
|
public override Font Font
|
|
{
|
|
get
|
|
{
|
|
return txtInfo.Font;
|
|
}
|
|
|
|
set
|
|
{
|
|
txtInfo.Font = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 重新设置大小
|
|
/// </summary>
|
|
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;
|
|
}
|
|
/// <summary>
|
|
/// 在选择时激发
|
|
/// </summary>
|
|
[Description("在选择时激发")]
|
|
public event EventHandler OnSelected;
|
|
private void DoubleText_Load(object sender, EventArgs e)
|
|
{
|
|
ResizeSize();
|
|
}
|
|
|
|
private void DoubleText_Resize(object sender, EventArgs e)
|
|
{
|
|
ResizeSize();
|
|
}
|
|
/// <summary>
|
|
/// 点击选择
|
|
/// </summary>
|
|
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();
|
|
}
|
|
}
|
|
}
|