C#将RDP客户端控件添加到选项卡控件

时间:2014-01-03 04:59:22

标签: c# tabs controls add rdp

我正在制作一个程序来通过Windows RDP管理多个远程桌面会话。我找到了一个教程,展示了如何通过将AxMsRdpClient2a控件拖入窗体设计器中的控件来使用它。但是我想在选项卡控件内动态创建它们(即用户单击一个按钮并创建包含远程桌面客户端的新选项卡)。出于某种原因,运行它时,AxMsRdpClient2a控件没有显示在选项卡页面中。以下是我正在使用的代码,非常感谢任何建议!

            // Create a new tab for the remote desktop
        tabs[currentTab] = new TabPage();
        clients[currentTab] = new AxMsRdpClient2a();
        clients[currentTab].CreateControl();
        clients[currentTab].BringToFront();
        clients[currentTab].Parent = tabs[currentTab];
        clients[currentTab].ColorDepth = 16;
        //clients[currentTab].Location = new Point(0, 0);
        //clients[currentTab].Size = new System.Drawing.Size(50, 50);

        tabs[currentTab].Controls.Add(clients[currentTab]);
        tabs[currentTab].Name = RemoteIP;
        tabs[currentTab].Padding = new System.Windows.Forms.Padding(3);
        tabs[currentTab].Size = remoteDesktopTabControl.Size;
        clients[currentTab].DesktopWidth = tabs[currentTab].Width;
        clients[currentTab].DesktopHeight = tabs[currentTab].Height;
        clients[currentTab].AdvancedSettings3.DisplayConnectionBar = true;
        tabs[currentTab].Text = RemoteIP;
        tabs[currentTab].UseVisualStyleBackColor = true;
        remoteDesktopTabControl.TabPages.Add(tabs[currentTab]);
        tabs[currentTab].Controls.Add(new RichTextBox());

        remoteDesktopTabControl.SelectedTab = remoteDesktopTabControl.TabPages[remoteDesktopTabControl.TabPages.Count - 1];

        clients[currentTab].Server = RemoteIP;
        clients[currentTab].UserName = Username;
        IMsTscNonScriptable secured = (IMsTscNonScriptable)clients[currentTab].GetOcx();
        secured.ClearTextPassword = Password;
        clients[currentTab].ColorDepth = 16;
        clients[currentTab].Connect();

        currentTab++;

1 个答案:

答案 0 :(得分:1)

以下是我动态创建控件的方法

AxMsRdpClient7NotSafeForScripting newrdp = new AxMsRdpClient7NotSafeForScripting();
                newrdp.Name = "RDPControl";
                tab.Controls.Add(newrdp);
                tab.Size = new System.Drawing.Size(814, 508);

                tabControl.TabPages.Add(tab);
                tabControl.SelectedTab = tab;
                ConnectNewTab(newrdp, serverTextBox.Text, usernameTextBox.Text, passwordTextBox.Text);

我包含名称的原因是我使用另一种方法在特定选项卡上按该名称查找控件,以便我可以正常断开连接。