⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sshotkeycontrol.cs

📁 飞信的收发使用csharp进行开发
💻 CS
字号:
namespace Imps.Client.Pc.Options
{
    using Imps.Client;
    using Imps.Client.Core;
    using Imps.Client.Pc;
    using Imps.Client.Pc.Controls;
    using Imps.Client.Pc.Utils;
    using Imps.Client.Resource;
    using Imps.Client.Utils;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class SsHotKeyControl : OptionsControlBase
    {
        private IFrameworkWindow _iFrameworkWindow;
        private string _oldHotKey = string.Empty;
        private IContainer components;
        private GroupBox gbHKShowMW;
        private GroupBox gpHKSendMessage;
        private XLabel lbUseHk;
        private XLabel lbUserHk2;
        private RadioButton rbDefaultKey;
        private RadioButton rbNoHotKey;
        private RadioButton rbSendByCtrlEnter;
        private RadioButton rbSendByEnter;
        private RadioButton rbUserKey;
        private XHotKeyInputBox xHotKeyBoxMainWnd;

        public SsHotKeyControl(IFrameworkWindow iFrameworkWin)
        {
            this._iFrameworkWindow = iFrameworkWin;
            this.InitializeComponent();
            this.HandleUiEvent();
            this.gpHKSendMessage.Enabled = this.CurrentUser.Status == UserAccountStatus.Logon;
        }

        private void _user_StatusChanged(object sender, UserSatusChangedEventArgs e)
        {
            this.gpHKSendMessage.Enabled = e.NewStatus == UserAccountStatus.Logon;
        }

        public override bool ControlLoad()
        {
            this.CurrentUser.StatusChanged += new EventHandler<UserSatusChangedEventArgs>(this._user_StatusChanged);
            return base.ControlLoad();
        }

        public override bool ControlUnload()
        {
            this.CurrentUser.StatusChanged -= new EventHandler<UserSatusChangedEventArgs>(this._user_StatusChanged);
            return base.ControlUnload();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void HandleUiEvent()
        {
            this.rbDefaultKey.CheckedChanged += new EventHandler(this.uiData_Changed);
            this.rbUserKey.CheckedChanged += new EventHandler(this.uiData_Changed);
            this.rbSendByCtrlEnter.CheckedChanged += new EventHandler(this.uiData_Changed);
            this.rbSendByEnter.CheckedChanged += new EventHandler(this.uiData_Changed);
            this.xHotKeyBoxMainWnd.TextChanged += new EventHandler(this.uiData_Changed);
            this.xHotKeyBoxMainWnd.KeyUp += new KeyEventHandler(this.xHotKeyBoxMainWnd_KeyUp);
            this.xHotKeyBoxMainWnd.KeyDown += new KeyEventHandler(this.xHotKeyBoxMainWnd_KeyDown);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            HotKey key = new HotKey();
            this.gbHKShowMW = new GroupBox();
            this.rbNoHotKey = new RadioButton();
            this.xHotKeyBoxMainWnd = new XHotKeyInputBox();
            this.rbUserKey = new RadioButton();
            this.rbDefaultKey = new RadioButton();
            this.lbUseHk = new XLabel();
            this.gpHKSendMessage = new GroupBox();
            this.rbSendByCtrlEnter = new RadioButton();
            this.rbSendByEnter = new RadioButton();
            this.lbUserHk2 = new XLabel();
            this.gbHKShowMW.SuspendLayout();
            this.gpHKSendMessage.SuspendLayout();
            base.SuspendLayout();
            this.gbHKShowMW.Controls.Add(this.rbNoHotKey);
            this.gbHKShowMW.Controls.Add(this.xHotKeyBoxMainWnd);
            this.gbHKShowMW.Controls.Add(this.rbUserKey);
            this.gbHKShowMW.Controls.Add(this.rbDefaultKey);
            this.gbHKShowMW.Controls.Add(this.lbUseHk);
            this.gbHKShowMW.ForeColor = Color.Black;
            this.gbHKShowMW.Location = new Point(5, 9);
            this.gbHKShowMW.Name = "gbHKShowMW";
            this.gbHKShowMW.Size = new Size(0x161, 0x77);
            this.gbHKShowMW.TabIndex = 0;
            this.gbHKShowMW.TabStop = false;
            this.rbNoHotKey.AutoSize = true;
            this.rbNoHotKey.Checked = true;
            this.rbNoHotKey.Location = new Point(40, 0x63);
            this.rbNoHotKey.Name = "rbNoHotKey";
            this.rbNoHotKey.Size = new Size(14, 13);
            this.rbNoHotKey.TabIndex = 4;
            this.rbNoHotKey.TabStop = true;
            this.rbNoHotKey.UseVisualStyleBackColor = true;
            this.xHotKeyBoxMainWnd.BackColor = Color.White;
            this.xHotKeyBoxMainWnd.BorderStyle = BorderStyle.FixedSingle;
            this.xHotKeyBoxMainWnd.HotKey = key;
            this.xHotKeyBoxMainWnd.ImeMode = ImeMode.Disable;
            this.xHotKeyBoxMainWnd.Location = new Point(0x75, 0x44);
            this.xHotKeyBoxMainWnd.Name = "xHotKeyBoxMainWnd";
            this.xHotKeyBoxMainWnd.NoneText = "";
            this.xHotKeyBoxMainWnd.Size = new Size(0xa4, 20);
            this.xHotKeyBoxMainWnd.TabIndex = 3;
            this.rbUserKey.AutoSize = true;
            this.rbUserKey.Location = new Point(40, 70);
            this.rbUserKey.Name = "rbUserKey";
            this.rbUserKey.Size = new Size(14, 13);
            this.rbUserKey.TabIndex = 2;
            this.rbUserKey.TabStop = true;
            this.rbUserKey.UseVisualStyleBackColor = true;
            this.rbUserKey.CheckedChanged += new EventHandler(this.rbUserKey_CheckedChanged);
            this.rbDefaultKey.AutoSize = true;
            this.rbDefaultKey.Checked = true;
            this.rbDefaultKey.Location = new Point(40, 0x2a);
            this.rbDefaultKey.Name = "rbDefaultKey";
            this.rbDefaultKey.Size = new Size(0x61, 0x11);
            this.rbDefaultKey.TabIndex = 1;
            this.rbDefaultKey.TabStop = true;
            this.rbDefaultKey.Text = "默认热键 Alt+.";
            this.rbDefaultKey.UseVisualStyleBackColor = true;
            this.lbUseHk.AutoEllipsis = false;
            this.lbUseHk.AutoSize = true;
            this.lbUseHk.BorderColor = Color.Black;
            this.lbUseHk.BorderStyle = BorderStyle.None;
            this.lbUseHk.ButtonBorderStyle = ButtonBorderStyle.Solid;
            this.lbUseHk.Location = new Point(0x10, 0x11);
            this.lbUseHk.Name = "lbUseHk";
            this.lbUseHk.Size = new Size(0x31, 14);
            this.lbUseHk.TabIndex = 0;
            this.lbUseHk.Text = "lbUseHk";
            this.lbUseHk.TextAlign = ContentAlignment.TopLeft;
            this.lbUseHk.UseMnemonic = false;
            this.gpHKSendMessage.Controls.Add(this.rbSendByCtrlEnter);
            this.gpHKSendMessage.Controls.Add(this.rbSendByEnter);
            this.gpHKSendMessage.Controls.Add(this.lbUserHk2);
            this.gpHKSendMessage.Enabled = false;
            this.gpHKSendMessage.ForeColor = Color.Black;
            this.gpHKSendMessage.Location = new Point(6, 0x84);
            this.gpHKSendMessage.Name = "gpHKSendMessage";
            this.gpHKSendMessage.Size = new Size(0x15f, 0x63);
            this.gpHKSendMessage.TabIndex = 1;
            this.gpHKSendMessage.TabStop = false;
            this.rbSendByCtrlEnter.AutoSize = true;
            this.rbSendByCtrlEnter.Location = new Point(40, 0x48);
            this.rbSendByCtrlEnter.Name = "rbSendByCtrlEnter";
            this.rbSendByCtrlEnter.Size = new Size(14, 13);
            this.rbSendByCtrlEnter.TabIndex = 5;
            this.rbSendByCtrlEnter.TabStop = true;
            this.rbSendByCtrlEnter.UseVisualStyleBackColor = true;
            this.rbSendByEnter.AutoSize = true;
            this.rbSendByEnter.Checked = true;
            this.rbSendByEnter.Location = new Point(40, 0x2f);
            this.rbSendByEnter.Name = "rbSendByEnter";
            this.rbSendByEnter.Size = new Size(14, 13);
            this.rbSendByEnter.TabIndex = 4;
            this.rbSendByEnter.TabStop = true;
            this.rbSendByEnter.UseVisualStyleBackColor = true;
            this.lbUserHk2.AutoEllipsis = false;
            this.lbUserHk2.AutoSize = true;
            this.lbUserHk2.BorderColor = Color.Black;
            this.lbUserHk2.BorderStyle = BorderStyle.None;
            this.lbUserHk2.ButtonBorderStyle = ButtonBorderStyle.Solid;
            this.lbUserHk2.Location = new Point(0x10, 0x19);
            this.lbUserHk2.Name = "lbUserHk2";
            this.lbUserHk2.Size = new Size(0x3b, 14);
            this.lbUserHk2.TabIndex = 4;
            this.lbUserHk2.Text = "lbUserHk2";
            this.lbUserHk2.TextAlign = ContentAlignment.TopLeft;
            this.lbUserHk2.UseMnemonic = false;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.gpHKSendMessage);
            base.Controls.Add(this.gbHKShowMW);
            base.Name = "SsHotKeyControl";
            base.Size = new Size(0x16b, 0x1b1);
            base.Load += new EventHandler(this.SsHotKeyControl_Load);
            this.gbHKShowMW.ResumeLayout(false);
            this.gbHKShowMW.PerformLayout();
            this.gpHKSendMessage.ResumeLayout(false);
            this.gpHKSendMessage.PerformLayout();
            base.ResumeLayout(false);
        }

        private void rbUserKey_CheckedChanged(object sender, EventArgs e)
        {
            this.xHotKeyBoxMainWnd.Enabled = this.rbUserKey.Checked;
        }

        private void SsHotKeyControl_Load(object sender, EventArgs e)
        {
            this.gbHKShowMW.Text = StringTable.Hotkey.gpShowMw;
            this.gpHKSendMessage.Text = StringTable.Hotkey.gpSendMsg;
            this.lbUseHk.Text = StringTable.Hotkey.lbUseHotKey;
            this.lbUserHk2.Text = StringTable.Hotkey.lbUseHotKey;
            this.rbDefaultKey.Text = StringTable.Hotkey.rbDefaultHotkey;
            this.rbUserKey.Text = StringTable.Hotkey.rbUseHotkey;
            this.rbNoHotKey.Text = StringTable.Hotkey.rbNoHotKey;
            this.rbSendByCtrlEnter.Text = StringTable.Hotkey.rbSendByCtrlEnter;
            this.rbSendByEnter.Text = StringTable.Hotkey.rbSendByEnter;
        }

        private void uiData_Changed(object sender, EventArgs e)
        {
            UiErrorHelper.HandEventSafely(this._iFrameworkWindow, delegate {
                base.Modified = true;
            });
        }

        public override bool UpdateData(bool update)
        {
            Imps.Client.Core.ConversationSetting conversationSetting = this.CurrentUser.Configuration.UserSetting.ConversationSetting;
            Imps.Client.Core.MainWindowSetting mainWindowSetting = this.CurrentUser.Configuration.UserSetting.MainWindowSetting;
            try
            {
                if (update)
                {
                    if (!this.CheckUserInput())
                    {
                        return false;
                    }
                    Suspender suspender = new Suspender(mainWindowSetting);
                    try
                    {
                        if (this.rbDefaultKey.Checked)
                        {
                            mainWindowSetting.HotKeyShowMainwindow = 0;
                        }
                        else if (this.rbNoHotKey.Checked)
                        {
                            mainWindowSetting.HotKeyShowMainwindow = 1;
                        }
                        else
                        {
                            mainWindowSetting.HotKeyShowMainwindow = this.xHotKeyBoxMainWnd.HotKey.LParam;
                        }
                    }
                    finally
                    {
                        suspender.Dispose();
                    }
                    Suspender suspender2 = new Suspender(conversationSetting);
                    try
                    {
                        conversationSetting.SendMessageByEnterKey.ProposedValue = this.rbSendByEnter.Checked;
                    }
                    finally
                    {
                        suspender2.Dispose();
                    }
                }
                else
                {
                    if (mainWindowSetting.HotKeyShowMainwindow == 0)
                    {
                        this.rbDefaultKey.Checked = true;
                    }
                    else if (mainWindowSetting.HotKeyShowMainwindow == 1)
                    {
                        this.rbNoHotKey.Checked = true;
                    }
                    else
                    {
                        this.xHotKeyBoxMainWnd.HotKey = new HotKey(mainWindowSetting.HotKeyShowMainwindow);
                        this.rbUserKey.Checked = true;
                    }
                    this.xHotKeyBoxMainWnd.Enabled = this.rbUserKey.Checked;
                    if (conversationSetting.SendMessageByEnterKey != null)
                    {
                        this.rbSendByEnter.Checked = true;
                    }
                    else
                    {
                        this.rbSendByCtrlEnter.Checked = true;
                    }
                }
                base.Modified = false;
                return true;
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
                return false;
            }
        }

        private void xHotKeyBoxMainWnd_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                BalloonHelper.RemoveAll();
            }
            catch
            {
            }
        }

        private void xHotKeyBoxMainWnd_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (this.xHotKeyBoxMainWnd.HotKey != null)
                {
                    string str = this.xHotKeyBoxMainWnd.HotKey.ToString();
                    if (!this.xHotKeyBoxMainWnd.HotKey.IsValid && (this._oldHotKey != str))
                    {
                        BalloonHelper.ShowInputErrorBallon(this.xHotKeyBoxMainWnd, string.Format(StringTable.Hotkey.MsgInvalidHotKey, str), StringTable.Options.TitleInvalidInput);
                    }
                    this._oldHotKey = str;
                }
            }
            catch
            {
            }
        }

        private Imps.Client.Core.User CurrentUser
        {
            get
            {
                return this._iFrameworkWindow.AccountManager.CurrentUser;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -