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

📄 frmaddprotocol.cs

📁 Gibphone is CSharp Program, it can tell you how to design p2p chat.
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using GPCore.Protocols;

namespace GPCore.Forms
{
    /// <summary>
    /// Provides a way for the user to add an account.
    /// </summary>
    internal partial class frmAddProtocol : Form
    {
        private ProtocolPanel APanel;
        private Hashtable hashmap;

        /// <summary>
        /// Creates a new <see cref="frmAddProtocol"/>.
        /// </summary>
        public frmAddProtocol()
        {
            hashmap = new Hashtable();
            InitializeComponent();
            foreach (string s in Core.PluginManager.Protocols)
            {
                object[] os = Core.PluginManager.GetAttributes(s);
                string name = s;
                foreach (object o in os)
                {
                    if (o is PluginAttribute)
                        name = (o as PluginAttribute).Title;
                }
                hashmap.Add(name, s);
                cmbProtocols.Items.Add(name);
            }
            cmbProtocols.SelectedIndex = 0;
        }

        private void cmbProtocols_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (APanel != null)
            {
                Controls.Remove(APanel);
            }
            string s = hashmap[cmbProtocols.SelectedItem.ToString()] as string;
            object o = Core.CreateInstance(s);
            IProtocol p = o as IProtocol;
            if (p is ICustomProtocolOptions)
            {
                APanel = (p as ICustomProtocolOptions).CustomProtocolPanel;
            }
            else
            {
                APanel = new ProtocolPanel(s);
            }
            APanel.CancelButton.Click += new EventHandler(CancelButton_Click);
            APanel.OKButton.Click += new EventHandler(OKButton_Click);
            ShowPanel();
        }

        void OKButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ShowPanel()
        {
            APanel.Top = cmbProtocols.Height + 15;
            APanel.Left = label1.Left;
            this.Width = APanel.Width + label1.Left * 2;
            this.Controls.Add(APanel);
            this.Height = APanel.Top + cmbProtocols.Top + APanel.Height + cmbProtocols.Height + cmbProtocols.Top;

        }
    }
}

⌨️ 快捷键说明

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