132 lines
3.9 KiB
C#
132 lines
3.9 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;
|
|
|
|
namespace Lskj.MyControl {
|
|
public partial class LabelAutoTextEx : UserControl {
|
|
|
|
#region 属性
|
|
private int padding_right = 7;
|
|
private string labelText;
|
|
[Description("Label值")]
|
|
public string LabelText {
|
|
get { return labelText; }
|
|
set {
|
|
labelText = value;
|
|
lbMsg.Text = value;
|
|
pl_left.Width = lbMsg.Width + padding_right;
|
|
}
|
|
}
|
|
|
|
private string text;
|
|
[Description("文本框值")]
|
|
public override string Text {
|
|
get {
|
|
return txtBox.Text;
|
|
}
|
|
set {
|
|
text = value;
|
|
txtBox.Text = text;
|
|
}
|
|
}
|
|
|
|
[Description("提示文本")]
|
|
public string TipMsg { get; set; }
|
|
|
|
[Description("是否允许为空")]
|
|
public bool IsEmpt { get; set; }
|
|
|
|
public TextBoxEx GetTextBox { get { return txtBox; } }
|
|
private string defaultString;
|
|
public string DefaultString {
|
|
get { return defaultString; }
|
|
set { defaultString = value; }
|
|
}
|
|
private string unionFields;
|
|
public string UnionFields {
|
|
get { return unionFields; }
|
|
set { unionFields = value; }
|
|
}
|
|
private string unionValue;
|
|
public string UnionValue {
|
|
get { return unionValue; }
|
|
set { unionValue = value; }
|
|
}
|
|
|
|
[Description("联想框宽度")]
|
|
public int ImageWidth { get; set; }
|
|
|
|
[Description("联想框高度")]
|
|
public int ImageHeight { get; set; }
|
|
#endregion
|
|
|
|
private Panel pMain;
|
|
private GridControlEx gc;
|
|
public LabelAutoTextEx() {
|
|
InitializeComponent();
|
|
pMain = new Panel();
|
|
pMain.Visible = false;
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e) {
|
|
base.OnLoad(e);
|
|
pMain.Width = ImageWidth;
|
|
pMain.Height = ImageHeight;
|
|
pMain.BackColor = Color.Black;
|
|
pMain.Location = new Point(this.Location.X + lbMsg.Width, this.Location.Y + this.Height);
|
|
gc = new GridControlEx();
|
|
gc.gridView.OptionsBehavior.Editable = false;
|
|
gc.Dock = DockStyle.Fill;
|
|
List<User> us = new List<User>();
|
|
for (int i = 0; i < 10; i++) {
|
|
us.Add(new User() { pwd = "333", userName = "3333" + i });
|
|
}
|
|
gc.gridControl.DataSource = us;
|
|
pMain.Controls.Add(gc);
|
|
this.Parent.Controls.Add(pMain);
|
|
|
|
this.txtBox.Leave += new EventHandler(OnSelfLostFocus);
|
|
this.txtBox.KeyUp += new KeyEventHandler(onSelfKeyUp);
|
|
this.txtBox.Enter += new EventHandler(AutoSearcher_Enter);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 输入控件失去焦点事件处理
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnSelfLostFocus(object sender, EventArgs e) {
|
|
if (gc.Focused) {
|
|
pMain.Visible = false;
|
|
}
|
|
}
|
|
|
|
/// 输入框回车事件的处理
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void onSelfKeyUp(object sender, KeyEventArgs e) {
|
|
if (e.KeyValue == 13) {
|
|
gc.Focus();
|
|
gc.gridView.Focus();
|
|
gc.gridControl.Focus();
|
|
}
|
|
}
|
|
|
|
private void AutoSearcher_Enter(object sender, EventArgs e) {
|
|
pMain.Visible = true;
|
|
}
|
|
|
|
public class User {
|
|
public String userName { get; set; }
|
|
public String pwd { get; set; }
|
|
|
|
}
|
|
}
|
|
}
|