/// <summary> /// “连接”按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Connect_Click(object sender, RoutedEventArgs e) { try { string ip = ((sender as Button).DataContext as device).Ip; string username = ((sender as Button).DataContext as device).Username; string password = ((sender as Button).DataContext as device).Password; var form = new System.Windows.Forms.Form(); form.Text = ip; form.Size = new System.Drawing.Size((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight); var axmstsc = new AxMsTscAxNotSafeForScripting(); ((System.ComponentModel.ISupportInitialize)(axmstsc)).BeginInit(); form.Controls.Add(axmstsc); ((System.ComponentModel.ISupportInitialize)(axmstsc)).EndInit(); Desktop desk = new Desktop(); desk.Title = ip; //WindowsFormsHost wfh = new WindowsFormsHost(); axmstsc.Height = (int)SystemParameters.PrimaryScreenHeight; axmstsc.Width = (int)SystemParameters.PrimaryScreenWidth; //wfh.Child = axmstsc; axmstsc.Server = ip; axmstsc.UserName = username; IMsTscNonScriptable secured = (IMsTscNonScriptable)axmstsc.GetOcx(); secured.ClearTextPassword = password; axmstsc.Connect(); form.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// Verify if connection is still opened private void DisconnectRemote(AxMsTscAxNotSafeForScripting remote) { try { if (remote.Connected.ToString() == "1") { remote.Disconnect(); } } catch { } }
// Dinamically create Tab Page Control and remote connection control inside it public void CreateNewTab(TabControl tabControl) { TabPage page = new TabPage("VM" + (tabControl.TabPages.Count + 1).ToString()); tabControl.TabPages.Add(page); remoteConControl = CreateRemoteControl(); page.Controls.Add(remoteConControl); }
public Window1() { InitializeComponent(); // Create the host and the ActiveX control _terminalService = new AxMsTscAxNotSafeForScripting(); // Add the ActiveX control to the host, and the host to the WPF panel var host = new WindowsFormsHost { Child = _terminalService }; Panel.Children.Add(host); }
// Create the remote connection object / control private AxMsTscAxNotSafeForScripting CreateRemoteControl() { ComponentResourceManager resources = new ComponentResourceManager(typeof(RemoteConnectionForm)); remoteConControl = new AxMsTscAxNotSafeForScripting(); //Code above is related to UI stuff - same as designer file code for the controls on tab1/2 ((ISupportInitialize)(remoteConControl)).BeginInit(); remoteConControl.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right))); remoteConControl.Enabled = true; remoteConControl.Location = new System.Drawing.Point(0, 0); remoteConControl.Name = "remoteConControl"; remoteConControl.OcxState = ((AxHost.State)(resources.GetObject("remoteConControl.OcxState"))); remoteConControl.Size = new System.Drawing.Size(1001, 670); remoteConControl.TabIndex = 0; remoteConControl.Dock = DockStyle.Fill; return(remoteConControl); }
public AxMsTscAxNotSafeForScriptingEventMulticaster(AxMsTscAxNotSafeForScripting parent) { this.parent = parent; }
// Validate if remote object is in connected state public bool ValidateConnection(AxMsTscAxNotSafeForScripting remote) { bool connected; return(connected = remote.Connected.ToString() == "1"); }