Windows遠端桌面用戶端

來源:互聯網
上載者:User

標籤:tools   scree   end   targe   rect   sys   setting   this   ext   

1、註冊控制項:regsvr32 C:\Windows\System32\mstscax.dll。

2、添加RDP Control控制項到工具箱中。我選擇的RDP Client Control (redistributable) - version 9

 

3、在VS項目中引用C:\Windows\System32\mstscax.dll

 4、RdpTabPage類

using System;using System.Windows.Forms;namespace RdpClient{    public class RdpTabPage : TabPage    {        AxMSTSCLib.AxMsRdpClient9 rdpc = null;        protected override void OnCreateControl()        {            rdpc = new AxMSTSCLib.AxMsRdpClient9();            rdpc.OnDisconnected += new AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEventHandler(rdpc_OnDisconnected);            this.Controls.Add(rdpc);            rdpc.Dock = DockStyle.Fill;            base.OnCreateControl();        }        void rdpc_OnDisconnected(object sender, AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent e)        {            ((TabControl)this.Parent).TabPages.Remove(this);        }        public void Disconnect()        {            try            {                if (rdpc.Connected == 1)                {                    rdpc.Disconnect();                }            }            catch (Exception) { }        }        private void SetRdpClientProperties(RdpInfo info)        {            rdpc.Server = info.MachineName;            rdpc.UserName = info.UserName;            rdpc.Domain = "";            rdpc.AdvancedSettings9.RDPPort = info.RdpPort;            rdpc.AdvancedSettings9.ClearTextPassword = info.Password;            rdpc.AdvancedSettings9.RedirectDrives = true;            rdpc.AdvancedSettings9.RedirectPrinters = true;            rdpc.AdvancedSettings9.RedirectSmartCards = true;            rdpc.AdvancedSettings9.ConnectToServerConsole = true;            rdpc.ColorDepth = 32;            rdpc.Dock = DockStyle.Fill;        }        public void Connect(RdpInfo info)        {            SetRdpClientProperties(info);            rdpc.Connect();        }    }}

5、主表單

using System;using System.Windows.Forms;namespace RdpClient{    public partial class Form_Main : Form    {        #region 構造        public Form_Main()        {            InitializeComponent();        }        #endregion        #region 方法        /// <summary>        /// 綁定遠端桌面列表        /// </summary>        private void BindMenuItem()        {            tsb_Rdps.DropDownItems.Clear();            if (Config.RdpInfos == null) return;            foreach (var info in Config.RdpInfos.Items)            {                ToolStripMenuItem item = new ToolStripMenuItem();                item.ImageScaling = ToolStripItemImageScaling.SizeToFit;                item.Name = string.Format("MenuItem{0}", info.AliasName);                item.Text = info.AliasName;                item.Tag = info;                tsb_Rdps.DropDownItems.Add(item);            }        }        public void RdpConnect(RdpInfo info)        {            RdpTabPage rdpTab = new RdpTabPage();            rdpTab.Text = info.AliasName;            foreach (TabPage tp in tab_Rdps.TabPages)            {                if (tp.Text == rdpTab.Text)                {                    tab_Rdps.SelectTab(tp);                    return;                }            }            tab_Rdps.TabPages.Add(rdpTab);            rdpTab.Connect(info);            tab_Rdps.SelectTab(rdpTab);        }        #endregion        #region 事件        private void Form_Main_Load(object sender, EventArgs e)        {            rdpClient.Visible = false;            Config.Load();            BindMenuItem();        }        private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)        {            if (MessageBox.Show("確定退出程式?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)            {                e.Cancel = true;                return;            }        }        /// <summary>        /// 串連遠端桌面        /// </summary>        private void tsb_Rdps_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)        {            RdpInfo item = e.ClickedItem.Tag as RdpInfo;            if (item == null) return;            RdpConnect(item);        }        /// <summary>        /// 關閉當前Tab頁的遠端桌面        /// </summary>        private void tsb_Disconnect_Click(object sender, EventArgs e)        {            if (tab_Rdps.SelectedIndex < 0) return;            RdpTabPage rdpTab = (RdpTabPage)tab_Rdps.SelectedTab;            if (rdpTab != null)            {                rdpTab.Disconnect();            }        }        /// <summary>        /// 關閉所有Tab頁的遠端桌面        /// </summary>        private void tsb_DisconnectAll_Click(object sender, EventArgs e)        {            foreach (TabPage tab in tab_Rdps.TabPages)            {                RdpTabPage rdpTab = (RdpTabPage)tab;                rdpTab.Disconnect();            }        }        /// <summary>        /// 最大化        /// </summary>        private void tsb_Max_Click(object sender, EventArgs e)        {            if (tab_Rdps.SelectedIndex < 0) return;            RdpTabPage rdpTab = (RdpTabPage)tab_Rdps.SelectedTab;            if (rdpTab != null)            {                var rdpc = rdpTab.Controls[0] as AxMSTSCLib.AxMsRdpClient9;                rdpc.FullScreen = true;                rdpc.FullScreenTitle = rdpTab.Text;            }        }        private void tsb_Config_Click(object sender, EventArgs e)        {            Form_Settings form = new Form_Settings();            if (form.ShowDialog() == DialogResult.OK)            {                BindMenuItem();            }        }        private void tsb_About_Click(object sender, EventArgs e)        {            MessageBox.Show("遠端桌面", "資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);        }        #endregion    }}

6、程式下載地直址

https://pan.baidu.com/s/1Fcolic2QAcNANJszscVUjg

 

Windows遠端桌面用戶端

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.