diff --git a/RdpTest/MainForm.cs b/RdpTest/MainForm.cs index fbcaca6..7b61007 100644 --- a/RdpTest/MainForm.cs +++ b/RdpTest/MainForm.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Data.SQLite; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Windows.Forms; @@ -40,10 +41,10 @@ private void LoadHostConfig() panelBody.Controls.Clear(); //清空原有 var hosts = (List)Db.Connection.Query( - "SELECT Id,Name,Address,Port,User,Pwd,Sort,ParentId FROM RemoteHost"); + "SELECT Id,Name,Address,Port,User,Pwd,Sort,ParentId,RemoteProgram FROM RemoteHost"); //创建分组 - foreach (var hostGroup in hosts.Where(x => x.ParentId == 0).OrderBy(x => x.Sort)) + foreach (var hostGroup in hosts.Where(x => x.ParentId == 0).OrderByDescending(x => x.Sort)) { //建立分组 var hostGroupBox = new HostGroupBox { Dock = DockStyle.Top, Height = 100, Text = hostGroup.Name }; @@ -99,6 +100,34 @@ void ConnectRemoteHost(object sender, EventArgs e) rdpClient.UserName = host.User; rdpClient.AdvancedSettings2.ClearTextPassword = host.Pwd; + //进运行远程程序模式 + if (!string.IsNullOrEmpty(host.RemoteProgram)) + { + rdpClient.RemoteProgram2.RemoteProgramMode = true; + rdpClient.Width = Screen.PrimaryScreen.Bounds.Width; + rdpClient.Height = Screen.PrimaryScreen.Bounds.Height; + rdpClient.OnLoginComplete += (o, args) => + { + rdpClient.RemoteProgram2.ServerStartProgram(host.RemoteProgram, "", "%SYSTEMROOT%", false, "", false); + rdpClient.OnRemoteProgramResult += (o1, args1) => + { + if (args1.lError != RemoteProgramResult.remoteAppResultOk) + { + rdpClient.Dispose(); + MessageBox.Show(args1.lError.ToString(), "打开远程程序失败"); + } + }; + + tabMain.TabPages.Remove(page); + }; + } + + //rdpClient.RemoteProgram2.RemoteProgramMode = true; + //rdpClient.OnLoginComplete += (o, args) => + //{ + // rdpClient.RemoteProgram2.ServerStartProgram("cmd", "", "%SYSTEMROOT%", false, "", false); + // tabMain.TabPages.Remove(page); + //}; /* 因为分辨率比例问题,缩放效果并不怎么样 rdpClient.Width = Screen.PrimaryScreen.Bounds.Width; @@ -117,7 +146,6 @@ void ConnectRemoteHost(object sender, EventArgs e) rdpClient.Connect(); } - #region 菜单按钮 private void btnChangeStyle_Click(object sender, EventArgs e) { diff --git a/RdpTest/Model/RemoteHost.cs b/RdpTest/Model/RemoteHost.cs index 0635311..2121060 100644 --- a/RdpTest/Model/RemoteHost.cs +++ b/RdpTest/Model/RemoteHost.cs @@ -15,7 +15,7 @@ public class RemoteHost public int Sort { get; set; } public int ParentId { get; set; } - + public string RemoteProgram { get; set; } } } diff --git a/RdpTest/RdpTest.csproj b/RdpTest/RdpTest.csproj index 74d7079..ce79456 100644 --- a/RdpTest/RdpTest.csproj +++ b/RdpTest/RdpTest.csproj @@ -15,7 +15,7 @@ - x86 + AnyCPU true full false diff --git a/RdpTest/RemoteHostForm.cs b/RdpTest/RemoteHostForm.cs index fd27746..878b2aa 100644 --- a/RdpTest/RemoteHostForm.cs +++ b/RdpTest/RemoteHostForm.cs @@ -59,8 +59,16 @@ private void LoadRemoteHost() numPort.Value = RemoteHost.Port; txtUser.Text = RemoteHost.User; txtPwd.Text = RemoteHost.Pwd; + txtRemoteProgram.Text = RemoteHost.RemoteProgram; + + lbCopy.Visible = true; //显示复制按钮 } + private void lbCopy_Click(object sender, EventArgs e) + { + RemoteHost = null; + lbCopy.Visible = false; + } private void cbIsParent_CheckedChanged(object sender, System.EventArgs e) { @@ -110,16 +118,19 @@ private void btnSave_Click(object sender, System.EventArgs e) host.Port = Convert.ToInt32(numPort.Value); host.User = txtUser.Text.Trim(); host.Pwd = txtPwd.Text; + host.RemoteProgram = txtRemoteProgram.Text.Trim(); } Db.Connection.Execute( IsModify - ? "UPDATE RemoteHost SET Name=@Name,Address=@Address,Port=@Port,User=@User,Pwd=@Pwd,Sort=@Sort,ParentId=@ParentId WHERE Id=" + RemoteHost.Id - : "INSERT INTO RemoteHost(Name,Address,Port,User,Pwd,Sort,ParentId) VALUES(@Name,@Address,@Port,@User,@Pwd,@Sort,@ParentId)", + ? "UPDATE RemoteHost SET Name=@Name,Address=@Address,Port=@Port,User=@User,Pwd=@Pwd,Sort=@Sort,ParentId=@ParentId,RemoteProgram=@RemoteProgram WHERE Id=" + RemoteHost.Id + : "INSERT INTO RemoteHost(Name,Address,Port,User,Pwd,Sort,ParentId,RemoteProgram) VALUES(@Name,@Address,@Port,@User,@Pwd,@Sort,@ParentId,@RemoteProgram)", host); DialogResult = DialogResult.OK; } + + } } diff --git a/RdpTest/RemoteHostForm.designer.cs b/RdpTest/RemoteHostForm.designer.cs index 69f2e6e..6d57c87 100644 --- a/RdpTest/RemoteHostForm.designer.cs +++ b/RdpTest/RemoteHostForm.designer.cs @@ -49,6 +49,9 @@ private void InitializeComponent() this.pnlBottom = new MetroFramework.Controls.MetroPanel(); this.metroPanel1 = new MetroFramework.Controls.MetroPanel(); this.pnlHost = new MetroFramework.Controls.MetroPanel(); + this.metroLabel8 = new MetroFramework.Controls.MetroLabel(); + this.txtRemoteProgram = new System.Windows.Forms.TextBox(); + this.lbCopy = new MetroFramework.Controls.MetroLabel(); ((System.ComponentModel.ISupportInitialize)(this.numSort)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numPort)).BeginInit(); this.pnlBottom.SuspendLayout(); @@ -61,7 +64,7 @@ private void InitializeComponent() this.chIsParent.DisplayStatus = false; this.chIsParent.Location = new System.Drawing.Point(108, 14); this.chIsParent.Name = "chIsParent"; - this.chIsParent.Size = new System.Drawing.Size(76, 24); + this.chIsParent.Size = new System.Drawing.Size(75, 24); this.chIsParent.TabIndex = 0; this.chIsParent.Text = "~StatusOff"; this.chIsParent.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -82,7 +85,7 @@ private void InitializeComponent() // this.txtName.Location = new System.Drawing.Point(62, 60); this.txtName.Name = "txtName"; - this.txtName.Size = new System.Drawing.Size(122, 21); + this.txtName.Size = new System.Drawing.Size(121, 21); this.txtName.TabIndex = 11; // // metroLabel3 @@ -200,7 +203,7 @@ private void InitializeComponent() // this.txtAddress.Location = new System.Drawing.Point(62, 8); this.txtAddress.Name = "txtAddress"; - this.txtAddress.Size = new System.Drawing.Size(122, 21); + this.txtAddress.Size = new System.Drawing.Size(121, 21); this.txtAddress.TabIndex = 27; // // txtPwd @@ -215,7 +218,7 @@ private void InitializeComponent() // this.txtUser.Location = new System.Drawing.Point(62, 51); this.txtUser.Name = "txtUser"; - this.txtUser.Size = new System.Drawing.Size(123, 21); + this.txtUser.Size = new System.Drawing.Size(121, 21); this.txtUser.TabIndex = 30; this.txtUser.Text = "Administrator"; // @@ -246,9 +249,9 @@ private void InitializeComponent() this.pnlBottom.HorizontalScrollbarBarColor = true; this.pnlBottom.HorizontalScrollbarHighlightOnWheel = false; this.pnlBottom.HorizontalScrollbarSize = 10; - this.pnlBottom.Location = new System.Drawing.Point(20, 235); + this.pnlBottom.Location = new System.Drawing.Point(20, 292); this.pnlBottom.Name = "pnlBottom"; - this.pnlBottom.Size = new System.Drawing.Size(396, 63); + this.pnlBottom.Size = new System.Drawing.Size(401, 64); this.pnlBottom.TabIndex = 20; this.pnlBottom.VerticalScrollbarBarColor = true; this.pnlBottom.VerticalScrollbarHighlightOnWheel = false; @@ -269,7 +272,7 @@ private void InitializeComponent() this.metroPanel1.HorizontalScrollbarSize = 10; this.metroPanel1.Location = new System.Drawing.Point(20, 60); this.metroPanel1.Name = "metroPanel1"; - this.metroPanel1.Size = new System.Drawing.Size(396, 95); + this.metroPanel1.Size = new System.Drawing.Size(401, 95); this.metroPanel1.TabIndex = 21; this.metroPanel1.VerticalScrollbarBarColor = true; this.metroPanel1.VerticalScrollbarHighlightOnWheel = false; @@ -277,6 +280,8 @@ private void InitializeComponent() // // pnlHost // + this.pnlHost.Controls.Add(this.metroLabel8); + this.pnlHost.Controls.Add(this.txtRemoteProgram); this.pnlHost.Controls.Add(this.metroLabel7); this.pnlHost.Controls.Add(this.metroLabel5); this.pnlHost.Controls.Add(this.metroLabel6); @@ -291,17 +296,47 @@ private void InitializeComponent() this.pnlHost.HorizontalScrollbarSize = 10; this.pnlHost.Location = new System.Drawing.Point(20, 155); this.pnlHost.Name = "pnlHost"; - this.pnlHost.Size = new System.Drawing.Size(396, 80); + this.pnlHost.Size = new System.Drawing.Size(401, 137); this.pnlHost.TabIndex = 22; this.pnlHost.VerticalScrollbarBarColor = true; this.pnlHost.VerticalScrollbarHighlightOnWheel = false; this.pnlHost.VerticalScrollbarSize = 10; // + // metroLabel8 + // + this.metroLabel8.AutoSize = true; + this.metroLabel8.Location = new System.Drawing.Point(26, 94); + this.metroLabel8.Name = "metroLabel8"; + this.metroLabel8.Size = new System.Drawing.Size(79, 19); + this.metroLabel8.TabIndex = 38; + this.metroLabel8.Text = "仅启动程序"; + // + // txtRemoteProgram + // + this.txtRemoteProgram.Location = new System.Drawing.Point(108, 94); + this.txtRemoteProgram.Name = "txtRemoteProgram"; + this.txtRemoteProgram.Size = new System.Drawing.Size(265, 21); + this.txtRemoteProgram.TabIndex = 36; + // + // lbCopy + // + this.lbCopy.AutoSize = true; + this.lbCopy.ForeColor = System.Drawing.Color.Blue; + this.lbCopy.Location = new System.Drawing.Point(270, 28); + this.lbCopy.Name = "lbCopy"; + this.lbCopy.Size = new System.Drawing.Size(45, 19); + this.lbCopy.TabIndex = 23; + this.lbCopy.Text = "[复制]"; + this.lbCopy.UseCustomForeColor = true; + this.lbCopy.Visible = false; + this.lbCopy.Click += new System.EventHandler(this.lbCopy_Click); + // // RemoteHostForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(436, 318); + this.ClientSize = new System.Drawing.Size(441, 376); + this.Controls.Add(this.lbCopy); this.Controls.Add(this.pnlBottom); this.Controls.Add(this.pnlHost); this.Controls.Add(this.metroPanel1); @@ -347,5 +382,8 @@ private void InitializeComponent() private MetroFramework.Controls.MetroLabel metroLabel4; private MetroFramework.Controls.MetroPanel metroPanel1; private MetroFramework.Controls.MetroPanel pnlHost; + private MetroFramework.Controls.MetroLabel metroLabel8; + private System.Windows.Forms.TextBox txtRemoteProgram; + private MetroFramework.Controls.MetroLabel lbCopy; } } \ No newline at end of file diff --git a/RdpTest/Resources/config.wdb b/RdpTest/Resources/config.wdb index 7e2bfb6..81aa503 100644 Binary files a/RdpTest/Resources/config.wdb and b/RdpTest/Resources/config.wdb differ