/// <summary> /// 加载所有远程桌面配置 /// </summary> private void LoadHosts() { panelBody.Visible = false; panelBody.Controls.Clear(); //清空原有 var hosts = (List <RemoteHost>)Db.Connection.Query <RemoteHost>( "SELECT Id,Name,Address,Port,User,Pwd,Sort,ParentId,RemoteProgram,ExtJson FROM RemoteHost"); //创建分组 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, ContextMenuStrip = menuGroup, Tag = hostGroup }; hostGroupBox.GropNameMouseDown += (sender, e) => { if (e.Button == MouseButtons.Right) { _currSelectGroup = sender; } }; panelBody.Controls.Add(hostGroupBox); //填充分组内容 foreach (var host in hosts.Where(x => x.ParentId == hostGroup.Id).OrderBy(x => x.Sort)) { var title = new MetroTile { Name = "title", ActiveControl = null, Height = 60, Text = $"{host.Name}\r\n ({host.FullAddress})", UseSelectable = true, UseVisualStyleBackColor = true, Tag = host, AutoSize = true, ContextMenuStrip = menuHost, StyleManager = metroStyleManager, TextAlign = ContentAlignment.MiddleCenter }; title.DoubleClick += ConnectRemoteHost; title.MouseDown += MenuTitleRightClick; hostGroupBox.AddControl(title); } } panelBody.Visible = true; }
private void LoadHostConfig() { panelBody.Controls.Clear(); //清空原有 var hosts = (List <RemoteHost>)Db.Connection.Query <RemoteHost>( "SELECT Id,Name,Address,Port,User,Pwd,Sort,ParentId,RemoteProgram FROM RemoteHost"); //创建分组 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 }; panelBody.Controls.Add(hostGroupBox); //填充分组内容 foreach (var host in hosts.Where(x => x.ParentId == hostGroup.Id).OrderBy(x => x.Sort)) { var title = new MetroTile { Name = "title", ActiveControl = null, Height = 60, Text = $"{host.Name}\r\n {host.FullAddress}", UseSelectable = true, UseVisualStyleBackColor = true, Tag = host, AutoSize = true, ContextMenuStrip = menuTitle, StyleManager = metroStyleManager }; title.Click += ConnectRemoteHost; title.MouseDown += MenuTitleRightClick; hostGroupBox.AddControl(title); } } }