public SelectSignEmployeeDialog(List <Data.Temp.Objects.Employee> replacementEmployees, Data.Temp.Objects.SignType sign) { InitializeComponent(); signType = sign; tableLayoutPanel.GrowStyle = TableLayoutPanelGrowStyle.AddRows; tableLayoutPanel.RowCount = replacementEmployees.Count + 2 + (sign == Data.Temp.Objects.SignType.firstSign ? 0 : 1); int startButtonIdx = 0; if (sign != Data.Temp.Objects.SignType.firstSign) { Width += 120; AddSignLabel(signType); startButtonIdx = 1; } else { pictureBox.Hide(); Controls.Remove(pictureBox); } if (Environment.CurCultureInfo.TwoLetterISOLanguageName.Equals("ru")) { replacementEmployees = replacementEmployees.OrderBy(x => x.ShortName).ToList(); } else { replacementEmployees = replacementEmployees.OrderBy(x => x.ShortEngName).ToList(); } AddButton(startButtonIdx, Environment.CurEmp); bool fa = false; for (int idx = 0; idx < replacementEmployees.Count; idx++) { if (replacementEmployees[idx].ID != Environment.CurEmp.ID) { AddButton(idx + startButtonIdx + (fa ? 0 : 1), replacementEmployees[idx]); } else { fa = true; } } AddCancelButton(startButtonIdx + replacementEmployees.Count); AddCheckBox(startButtonIdx + replacementEmployees.Count + 1); ClientSize = new Size(tableLayoutPanel.Width, tableLayoutPanel.Height + 10); MinimumSize = Size; }
private void AddSignLabel(Data.Temp.Objects.SignType signtype) { TableLayoutPanel tlp = new TableLayoutPanel(); tlp.AutoSize = true; tlp.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; tlp.ColumnCount = 2; tlp.Dock = DockStyle.Fill; tlp.Margin = new Padding(0); tlp.RowCount = 1; tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); tlp.Controls.Add(pictureBox, 0, 0); Controls.Remove(pictureBox); Label label = new Label(); label.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; label.AutoSize = false; label.Margin = new Padding(0); switch (signType) { case Data.Temp.Objects.SignType.finalSign: label.Text = Environment.StringResources.GetString("msgFinishSign"); break; case Data.Temp.Objects.SignType.cancelSign: label.Text = Environment.StringResources.GetString("msgCancelSign"); break; } tableLayoutPanel.Controls.Add(tlp, 0, 0); tlp.Controls.Add(label, 1, 0); // Следующий код проверяет, поместился ли тект в label'е, и, если нет, увеличивает label'у высоту using (Graphics g = Graphics.FromHwnd(label.Handle)) { SizeF size = g.MeasureString(label.Text, label.Font, label.Width); if (size.Height > label.Height) { label.Height = (int)size.Height + 1; } } }