📄 controlhelper.cs
字号:
try
{
ctrl.ImeMode = ImeMode.Off;
ctrl.ImeMode = ImeMode.Hangul;
}
catch
{
}
}
private class FadeinImageHelper
{
private object _host;
private float _percent;
private Image _pic;
private PropertyInfo _piImage;
public FadeinImageHelper(object host, Image pic)
{
this._host = host;
this._pic = pic;
this._percent = 0f;
this._piImage = host.GetType().GetProperty("Image");
if (this._piImage != null)
{
Image objA = this._piImage.GetValue(this._host, null) as Image;
if (!object.Equals(objA, pic))
{
if (host is IComponent)
{
((IComponent) host).Disposed += new EventHandler(this.FadeinImageHelper_Disposed);
}
GlobalTimer.Register(new EventHandler(this.FadeinImage_Tick));
}
}
}
public void FadeinImage_Tick(object sender, EventArgs e)
{
try
{
this._percent += 0.2f;
this._piImage.SetValue(this._host, ImageHelper.TryGetTransparentImage(this._pic, this._percent), null);
}
catch
{
this._percent = 1f;
}
if (this._percent >= 1f)
{
GlobalTimer.Unregister(new EventHandler(this.FadeinImage_Tick));
}
}
private void FadeinImageHelper_Disposed(object sender, EventArgs e)
{
GlobalTimer.Unregister(new EventHandler(this.FadeinImage_Tick));
}
}
private class FlashWindowHelper
{
private Form _flashForm;
private int _interval;
private DateTime _start;
private int _totalSeconds;
public FlashWindowHelper(Form flashForm, int interval, int totalSeconds)
{
this._flashForm = flashForm;
this._interval = (interval <= 0) ? 15 : interval;
this._totalSeconds = totalSeconds;
}
private void _flashForm_Activated(object sender, EventArgs e)
{
this.FinishFlash();
}
private void FinishFlash()
{
try
{
if (GlobalTimer.IsHandlerRegistered(new EventHandler(this.Flash)))
{
GlobalTimer.Unregister(new EventHandler(this.Flash));
}
}
catch
{
}
}
private void Flash(object sender, EventArgs e)
{
try
{
Imps.Client.Utils.Win32.NativeMethods.FlashWindow(this._flashForm.Handle.ToInt32(), 1);
if ((this._totalSeconds > 0) && (DateTime.Now.Subtract(this._start).TotalSeconds > this._totalSeconds))
{
this.FinishFlash();
}
}
catch
{
this.FinishFlash();
}
}
public void Start()
{
this._start = DateTime.Now;
Imps.Client.Utils.Win32.NativeMethods.FlashWindow(this._flashForm.Handle.ToInt32(), 1);
GlobalTimer.Register(new EventHandler(this.Flash), this._flashForm, this._interval);
this._flashForm.Activated += new EventHandler(this._flashForm_Activated);
}
}
private class NudgeWindowHelper
{
private Form _form;
private Point _initLocation;
private int _initTickCount;
private int _interval;
private bool _moved;
private int _range;
private Timer _timer;
private int _totalmillisecond;
public NudgeWindowHelper(Form form)
{
this._interval = 30;
this._totalmillisecond = 0x7d0;
this._range = 10;
this._form = form;
this._initLocation = form.Location;
}
public NudgeWindowHelper(Form form, int interval, int totalmillisecond) : this(form)
{
this._interval = interval;
this._totalmillisecond = totalmillisecond;
}
public void NudgeWindow()
{
if (this._timer == null)
{
this._timer = new Timer();
}
this._timer.Interval = this._interval;
this._timer.Tick += new EventHandler(this.timer_Tick);
this._initTickCount = Environment.TickCount;
this._timer.Start();
}
private void RestoreWindow()
{
if (this._form.WindowState == FormWindowState.Maximized)
{
Imps.Client.Utils.Win32.NativeMethods.MoveWindow(this._form.Handle, -4, -4, this._form.Width, this._form.Height, true);
}
else
{
this._form.Location = this._initLocation;
}
}
private void timer_Tick(object sender, EventArgs e)
{
try
{
if ((Environment.TickCount - this._initTickCount) >= this._totalmillisecond)
{
this._timer.Stop();
this._timer.Dispose();
this.RestoreWindow();
}
else if (this._moved)
{
this.RestoreWindow();
this._moved = false;
}
else
{
Random random = new Random();
int x = this._form.Location.X;
int y = this._form.Location.Y;
if (random.Next(2) == 1)
{
x += random.Next(this._range);
}
else
{
x -= random.Next(this._range);
}
if (random.Next(2) == 1)
{
y += random.Next(this._range);
}
else
{
y -= random.Next(this._range);
}
Imps.Client.Utils.Win32.NativeMethods.MoveWindow(this._form.Handle, x, y, this._form.Width, this._form.Height, true);
this._moved = true;
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
this._timer.Stop();
this._timer.Dispose();
}
}
}
private class SetControlAcceptSpecialChars
{
private Control _host;
private char[] _specialchars;
internal SetControlAcceptSpecialChars(Control ctrl, char[] specialchars)
{
if ((ctrl == null) || (specialchars == null))
{
throw new ArgumentNullException();
}
this._host = ctrl;
this._specialchars = specialchars;
Array.Sort<char>(this._specialchars);
ctrl.ImeMode = ImeMode.Disable;
ctrl.ImeModeChanged += new EventHandler(ControlHelper.ctrl_ImeModeChanged);
ctrl.KeyPress += new KeyPressEventHandler(this.ctrlAcceptSpecialCharsOnly_KeyPress);
ctrl.TextChanged += new EventHandler(this.ctrlAcceptSpecialCharsOnly_TextChanged);
}
private void ctrlAcceptSpecialCharsOnly_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (((((e.KeyValue > 0x69) || (e.KeyValue < 0x60)) && (((e.KeyValue < 0x30) || (e.KeyValue > 0x39)) || e.Shift)) && ((e.KeyValue >= 0x30) && !e.Control)) && !e.Alt)
{
e.set_SuppressKeyPress(true);
}
}
catch
{
}
}
private void ctrlAcceptSpecialCharsOnly_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if ((e.KeyChar > '\x001f') && (Array.BinarySearch<char>(this._specialchars, e.KeyChar) < 0))
{
e.Handled = true;
}
}
catch
{
}
}
private void ctrlAcceptSpecialCharsOnly_TextChanged(object sender, EventArgs e)
{
try
{
StringBuilder builder = new StringBuilder();
string text = ((Control) sender).Text;
for (int i = 0; i < text.Length; i++)
{
if (Array.BinarySearch<char>(this._specialchars, text[i]) >= 0)
{
builder.Append(text[i]);
}
}
if (builder.Length < text.Length)
{
((Control) sender).Text = builder.ToString();
}
}
catch
{
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -