123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using MetroFramework.Controls;
- using System;
- using System.ComponentModel;
- using System.Windows.Forms;
- namespace Infoking.Common.Windows.Control
- {
- public class IKMetroTextBox : MetroTextBox
- {
- private Container components;
- private bool _HaveChanged;
- [ReadOnly(true)]
- [Category("BizPeri Configuration")]
- [DefaultValue(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [Description("Get or Set whether the control changed.")]
- public bool HaveChanged
- {
- get
- {
- return _HaveChanged;
- }
- set
- {
- _HaveChanged = value;
- }
- }
- [Category("BizPeri Configuration")]
- [ReadOnly(true)]
- [Description("Get or Set text.")]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public string CValue
- {
- get
- {
- return Text;
- }
- set
- {
- Text = value;
- }
- }
- public IntPtr TextBoxHandle
- {
- get
- {
- try
- {
- return base.Handle;
- }
- catch
- {
- return IntPtr.Zero;
- }
- }
- }
- public event KeyPressEventHandler OnEnterPress;
- #region ReadOnly Change
- private static readonly object EVENT_READONLYCHANGED = new object();
- [DefaultValue(false)]
- [Description("TextBoxReadOnlyDescr")]
- [RefreshProperties(RefreshProperties.Repaint)]
- [Category("CatBehavior")]
- public new bool ReadOnly
- {
- get
- {
- return base.ReadOnly;
- }
- set
- {
- base.ReadOnly = value;
- OnReadOnlyChanged(EventArgs.Empty);
- }
- }
- [Description("TextBoxBaseOnReadOnlyChangedDescr")]
- [Category("CatPropertyChanged")]
- public event EventHandler ReadOnlyChanged
- {
- add
- {
- base.Events.AddHandler(EVENT_READONLYCHANGED, value);
- }
- remove
- {
- base.Events.RemoveHandler(EVENT_READONLYCHANGED, value);
- }
- }
- protected virtual void OnReadOnlyChanged(EventArgs e)
- {
- (base.Events[EVENT_READONLYCHANGED] as EventHandler)?.Invoke(this, e);
- }
- #endregion
- public IKMetroTextBox()
- {
- InitializeComponent();
- base.TextChanged += IKTextBox_TextChanged;
- this.ReadOnlyChanged += IKTextBox_ReadOnlyChanged;
- }
- private void InitializeComponent()
- {
- components = new System.ComponentModel.Container();
- }
- protected override void OnPaint(PaintEventArgs pe)
- {
- base.OnPaint(pe);
- }
- protected override void OnGotFocus(EventArgs e)
- {
- SelectAll();
- }
- protected override void OnLostFocus(EventArgs e)
- {
- Select(0, 0);
- }
- protected override void OnKeyPress(KeyPressEventArgs e)
- {
- if (e.KeyChar == '\r')
- {
- if (this.OnEnterPress != null)
- {
- this.OnEnterPress(this, e);
- }
- e.Handled = true;
- }
- else
- {
- base.OnKeyPress(e);
- }
- }
- private void IKTextBox_TextChanged(object sender, EventArgs e)
- {
- _HaveChanged = true;
- }
- private void IKTextBox_ReadOnlyChanged(object sender, EventArgs e)
- {
- base.TabStop = !base.ReadOnly;
- }
- public void EnterPress(KeyPressEventArgs e)
- {
- if (this.OnEnterPress != null)
- {
- this.OnEnterPress(this, e);
- }
- }
- }
- }
|