Reputation: 53
I am trying to create a rdp in WPF. I used the AxMSTSCLib library to create a rdp client in my wpf application. I planned to create a usercontrol that hosts the rdp.I achieved it with the following code. But i get the grey area of the windows host visible. I need to fill the rdp client for the size of the windows host.
public partial class RDPUserControl : UserControl
{
internal RDPActiveXControl _rdp;
internal string Servername { get; set; }
internal string Username { get; set; }
internal string Password { get; set; }
internal TabItem TabItem { get; set; }
public RDPUserControl()
{
InitializeComponent();
}
private void InitData()
{
_rdp = new RDPActiveXControl();
((System.ComponentModel.ISupportInitialize)(_rdp)).BeginInit();
_rdp.Name = "rdp";
_rdp.Enabled = true;
wfHost.Child = _rdp;
((System.ComponentModel.ISupportInitialize)(_rdp)).EndInit();
}
internal void Connect()
{
_rdp.Server = Servername;
_rdp.UserName = Username;
_rdp.AdvancedSettings7.ClearTextPassword = Password;
_rdp.ColorDepth = 24;
_rdp.AdvancedSettings7.SmartSizing = true;
_rdp.AdvancedSettings7.AuthenticationLevel = 2;
_rdp.AdvancedSettings7.EnableCredSspSupport = true;
_rdp.Width = Convert.ToInt32(this.ActualWidth);
_rdp.Height = Convert.ToInt32(this.ActualHeight);
_rdp.DesktopWidth = Convert.ToInt32(this.ActualWidth);
_rdp.DesktopHeight = Convert.ToInt32(this.ActualHeight);
_rdp.OnDisconnected += _rdp_OnDisconnected;
try
{
_rdp.Connect();
}
catch(Exception e)
{
MessageBox.Show("Connection Failed: "+e.Message);
}
}
private void _rdp_OnDisconnected(object sender, AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent e)
{
MainWindow window = Application.Current.MainWindow as MainWindow;
Page page = window._mainFrame.Content as Page;
ConnectionsPage connectionPage = page as ConnectionsPage;
connectionPage.CloseTab(TabItem);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
InitData();
Connect();
}
public class RDPActiveXControl : AxMSTSCLib.AxMsRdpClient6NotSafeForScripting
{
public RDPActiveXControl() : base() { }
protected override void WndProc(ref System.Windows.Forms.Message m)
{
// Fix for the missing focus issue on the rdp client component
if (m.Msg == 0x0021) // WM_MOUSEACTIVATE
{
if (!this.ContainsFocus)
{
this.Focus();
}
}
base.WndProc(ref m);
}
}
How to make the RDP ActiveXControl for Full size of the windowsFormHost
I tried with
_rdp.Dock = System.Windows.Forms.DockStyle.Fill;
But it makes the app to disappear.Anyone know what is wrong with this?. Any working example will be helpful.
Upvotes: 1
Views: 161