从全屏模式最小化后,AxMSTSCLib 显示在任务栏中消失

时间:2021-07-21 06:29:45

标签: c# winforms rdp mstsc windows-controls

我正在使用 AxMSTSCLib 开发用于创建 RDP 连接的 Windows 应用程序。

下面列出的步骤导致我的远程桌面显示消失:

  1. 以全屏模式启动 RDP 连接
  2. 点击连接栏中的“还原”按钮
  3. 再次点击“最大化”按钮重新进入全屏模式
  4. 点击“最小化”按钮
  5. 然后我的应用消失了,我在任务栏中看不到它(但仍然在任务管理器中列出/运行)

enter image description here

如果我跳过第 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;

这种方式不是解决问题,只是避免触发问题。

我将不胜感激。

0 个答案:

没有答案
相关问题