我正在使用 AxMSTSCLib
开发用于创建 RDP 连接的 Windows 应用程序。
下面列出的步骤导致我的远程桌面显示消失:
如果我跳过第 2 步和第 3 步,点击连接栏中的“最小化”按钮时它不会消失,这真的很奇怪。
我在这里发布了我的部分代码,希望有人能帮我找出问题所在。
public partial class RdpShowForm : Form
{
public AxMSTSCLib.AxMsRdpClient9NotSafeForScripting oRemote;
public RdpShowForm()
{
InitializeComponent();
oRemote = new AxMSTSCLib.AxMsRdpClient9NotSafeForScripting();
((System.ComponentModel.ISupportInitialize)(this.oRemote)).BeginInit();
oRemote.Dock = System.Windows.Forms.DockStyle.Fill;
oRemote.Enabled = true;
oRemote.Name = "WindowsVM";
this.Controls.Add(oRemote); // Controls contains 'panel1' and 'oRemote'
((System.ComponentModel.ISupportInitialize)(this.oRemote)).EndInit();
oRemote.CreateControl();
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
}
private void RdpShowForm_Load(object sender, EventArgs e)
{
NewRdpConnectionInstance();
}
private void NewRdpConnectionInstance()
{
oRemote.Server = 'xxx';
...
oRemote.FullScreen = true;
oRemote.AdvancedSettings7.DisplayConnectionBar = true;
oRemote.AdvancedSettings7.ConnectionBarShowMinimizeButton = true;
oRemote.AdvancedSettings7.ConnectionBarShowRestoreButton = true;
oRemote.OnConnected += rdpClient_OnConnected;
oRemote.OnLeaveFullScreenMode += rdpClient_OnLeaveFullScreenMode;
oRemote.Connect();
oRemote.Show();
oRemote.Focus();
}
private void rdpClient_OnConnected(object sender, EventArgs e)
{
this.panel1.Visible = false;
this.Visible = false;
}
private void rdpClient_OnLeaveFullScreenMode(object sender, EventArgs e)
{
this.Visible = true;
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SYSCOMMAND)
{
if (m.WParam.ToInt32() == MAXIMIZE)
{
this.Visible = false;
oRemote.FullScreen = true;
oRemote.Show();
}
}
base.WndProc(ref m);
}
}
我尝试了一些方法,但没有有效。
oRemote.Bounds = Screen.PrimaryScreen.WorkingArea;
oRemote.IsAccessible = true;
this.ShowInTaskbar = true;
或
this.Visible = ture; // do not hide the main form
或
if (m.WParam.ToInt32() == MAXIMIZE)
{
oRemote.FullScreen = true;
oRemote.Show();
oRemote.Update();
oRemote.Refresh();
}
到目前为止,我想到的唯一解决方案是禁用恢复按钮,如下所示:
oRemote.AdvancedSettings7.ConnectionBarShowRestoreButton = false;
这种方式不是解决问题,只是避免触发问题。
我将不胜感激。