public ServerLogForm(ShadowsocksController controller) { this.controller = controller; this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); InitializeComponent(); this.Width = 810; int dpi_mul = Util.Utils.GetDpiMul(); Configuration config = controller.GetCurrentConfiguration(); if (config.configs.Count < 8) { this.Height = 300 * dpi_mul / 4; } else if (config.configs.Count < 20) { this.Height = (300 + (config.configs.Count - 8) * 16) * dpi_mul / 4; } else { this.Height = 500 * dpi_mul / 4; } UpdateTexts(); UpdateLog(); this.contextMenu1 = new ContextMenu(new MenuItem[] { CreateMenuItem("Auto &size", new EventHandler(this.autosizeItem_Click)), this.topmostItem = CreateMenuItem("Always On &Top", new EventHandler(this.topmostItem_Click)), new MenuItem("-"), CreateMenuItem("Copy current link", new EventHandler(this.copyLinkItem_Click)), CreateMenuItem("Copy all enable links", new EventHandler(this.copyEnableLinksItem_Click)), new MenuItem("-"), CreateMenuItem("Clear &MaxSpeed", new EventHandler(this.ClearMaxSpeed_Click)), this.clearItem = CreateMenuItem("&Clear", new EventHandler(this.ClearItem_Click)), }); ServerDataGrid.ContextMenu = contextMenu1; controller.ConfigChanged += controller_ConfigChanged; for (int i = 0; i < ServerDataGrid.Columns.Count; ++i) { ServerDataGrid.Columns[i].Width = ServerDataGrid.Columns[i].Width * dpi_mul / 4; } ServerDataGrid.RowTemplate.Height = 20 * dpi_mul / 4; //ServerDataGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; int width = 0; for (int i = 0; i < ServerDataGrid.Columns.Count; ++i) { if (!ServerDataGrid.Columns[i].Visible) { continue; } width += ServerDataGrid.Columns[i].Width; } this.Width = width + SystemInformation.VerticalScrollBarWidth + (this.Width - this.ClientSize.Width) + 1; ServerDataGrid.AutoResizeColumnHeadersHeight(); }
private void autosizeColumns() { for (int i = 0; i < ServerDataGrid.Columns.Count; ++i) { string name = ServerDataGrid.Columns[i].Name; if (name == "AvgLatency" || name == "AvgDownSpeed" || name == "MaxDownSpeed" || name == "AvgUpSpeed" || name == "MaxUpSpeed" || name == "Upload" || name == "Download" || name == "DownloadRaw" || name == "Group" || name == "Connecting" || name == "ErrorPercent" || name == "ConnectError" || name == "ConnectTimeout" || name == "Continuous" || name == "ConnectEmpty" ) { if (ServerDataGrid.Columns[i].Width <= 2) { continue; } ServerDataGrid.AutoResizeColumn(i, DataGridViewAutoSizeColumnMode.AllCellsExceptHeader); if (name == "AvgLatency" || name == "Connecting" || name == "AvgDownSpeed" || name == "MaxDownSpeed" || name == "AvgUpSpeed" || name == "MaxUpSpeed" ) { ServerDataGrid.Columns[i].MinimumWidth = ServerDataGrid.Columns[i].Width; } } } int width = 0; for (int i = 0; i < ServerDataGrid.Columns.Count; ++i) { if (!ServerDataGrid.Columns[i].Visible) { continue; } width += ServerDataGrid.Columns[i].Width; } this.Width = width + SystemInformation.VerticalScrollBarWidth + (this.Width - this.ClientSize.Width) + 1; ServerDataGrid.AutoResizeColumnHeadersHeight(); }
private void ServerDataGrid_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e) { int width = 0; for (int i = 0; i < ServerDataGrid.Columns.Count; ++i) { if (!ServerDataGrid.Columns[i].Visible) { continue; } width += ServerDataGrid.Columns[i].Width; } this.Width = width + SystemInformation.VerticalScrollBarWidth + (this.Width - this.ClientSize.Width) + 1; ServerDataGrid.AutoResizeColumnHeadersHeight(); }
public ServerLogForm(ShadowsocksController controller) { this.controller = controller; try { this.Icon = Icon.FromHandle((new Bitmap("icon.png")).GetHicon()); title_perfix = System.Windows.Forms.Application.StartupPath; if (title_perfix.Length > 20) { title_perfix = title_perfix.Substring(0, 20); } } catch { this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); } this.Font = System.Drawing.SystemFonts.MessageBoxFont; InitializeComponent(); this.Width = 810; int dpi_mul = Util.Utils.GetDpiMul(); Configuration config = controller.GetCurrentConfiguration(); if (config.configs.Count < 8) { this.Height = 300 * dpi_mul / 4; } else if (config.configs.Count < 20) { this.Height = (300 + (config.configs.Count - 8) * 16) * dpi_mul / 4; } else { this.Height = 500 * dpi_mul / 4; } UpdateTexts(); UpdateLog(); this.Menu = new MainMenu(new MenuItem[] { CreateMenuGroup("&Control", new MenuItem[] { CreateMenuItem("&Disconnect All", new EventHandler(this.Disconnect_Click)), CreateMenuItem("Clear &MaxSpeed", new EventHandler(this.ClearMaxSpeed_Click)), this.clearItem = CreateMenuItem("&Clear", new EventHandler(this.ClearItem_Click)), new MenuItem("-"), CreateMenuItem("Clear &Selected Total", new EventHandler(this.ClearSelectedTotal_Click)), CreateMenuItem("Clear &Total", new EventHandler(this.ClearTotal_Click)), }), CreateMenuGroup("C&opy", new MenuItem[] { CreateMenuItem("Copy current link", new EventHandler(this.copyLinkItem_Click)), CreateMenuItem("Copy all enable links", new EventHandler(this.copyEnableLinksItem_Click)), CreateMenuItem("Copy all links", new EventHandler(this.copyLinksItem_Click)), }), CreateMenuGroup("&Window", new MenuItem[] { CreateMenuItem("Auto &size", new EventHandler(this.autosizeItem_Click)), this.topmostItem = CreateMenuItem("Always On &Top", new EventHandler(this.topmostItem_Click)), }), }); controller.ConfigChanged += controller_ConfigChanged; for (int i = 0; i < ServerDataGrid.Columns.Count; ++i) { ServerDataGrid.Columns[i].Width = ServerDataGrid.Columns[i].Width * dpi_mul / 4; } ServerDataGrid.RowTemplate.Height = 20 * dpi_mul / 4; //ServerDataGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; int width = 0; for (int i = 0; i < ServerDataGrid.Columns.Count; ++i) { if (!ServerDataGrid.Columns[i].Visible) { continue; } width += ServerDataGrid.Columns[i].Width; } this.Width = width + SystemInformation.VerticalScrollBarWidth + (this.Width - this.ClientSize.Width) + 1; ServerDataGrid.AutoResizeColumnHeadersHeight(); }