I working on application that will optimize my job, with multiple connection by means RDP to my servers. At that point I will like to do a single windows form that show me all my servers. With my appropriate knowledge - I will like to add programmatically AxMsRdpClient2 or AxMsTscAxNotSafeForScripting control in my windows form. At start I have a Form1 where I save my credential (IP,USER,PASS) and with simple FOR I trung to add ActiveX Client to my Form2 and connect to the servers.
And here I have the problem. Lets see my code below.
call from Form1() >
var btt = new RunRDP();
for (int i = 0; i < 15; i++)
{
btt.PozitionMaster();
}
RunRDP Class:
private static int _count;
private static int _row = 4;
private static int _colum = 4;
private static int _objId;
public void PozitionMaster()
{
if (_count != 6)
{
UInitializer(_objId++, _row, _colum);
_row += 196;
_count++;
}
else
{
_colum += 196;
_row = 4;
_count = 0;
}
}
UInitializer function:
public AxMsRdpClient2 rdpClient;
public void UInitializer(int id, int x, int y)
{
Form2 ippo = new Form2();
rdpClient = new AxMsRdpClient2();
rdpClient.UserName = "username";
rdpClient.Server = "192.168.0.100";
rdpClient.Height = y;
rdpClient.Width = x;
rdpClient.BeginInit();
rdpClient.CreateControl();
if (ippo.InvokeRequired)
{
ippo.Invoke(new Action(() => ippo.Controls.Add(rdpClient)));
ippo.Invoke(new Action(() => ippo.Update()));
}
else
{
ippo.Controls.Add(rdpClient);
}
//this.Controls.Add(rdpClient);
rdpClient.AdvancedSettings2.RDPPort = 3389;
rdpClient.AdvancedSettings2.ClearTextPassword = "hello_rdp";//
rdpClient.ColorDepth = 16;//
rdpClient.FullScreen = false;//
rdpClient.Connect();
}
get that error:
An unhandled exception of type 'System.Windows.Forms.AxHost.
InvalidActiveXStateException' occurred in AxInterop.MSTSCLib.dll
{"Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown."}
InvalidActiveXStateException is raised when you start using the ActiveX control before its native window is created. That does not happen until after you call ippo.Show(); Move critical property assignments and method calls after that statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With