// Adds a textbox and accompanying intro text. Returns the height of vertical space occupied by these new object(s). public static int AddTextBox(string text, Font font, int top, int left, int numlines, int width, AnchorStyles anchors, string introText, Panel panel, int tabidx, int selidx) { //int gap = 4; TextBoxPP txtBox = new TextBoxPP(); txtBox.Anchor = anchors; txtBox.Font = font; txtBox.TabIndex = tabidx; txtBox.SelectedIndex = selidx; txtBox.Name = "textBox" + tabidx.ToString(); txtBox.Width = width; txtBox.Multiline = (numlines == 1) ? false : true; txtBox.Text = text; txtBox.Height = (int)(font.Size * 1.625 * numlines); Label label = null; int totHgt = txtBox.Height; // Default if (introText != null & introText != "") { if (numlines > 1) { //label = AddLabel(introText, font, top + 1, left, ContentAlignment.MiddleLeft, anchors, panel); label = AddMultilineLabel(introText, font, top, left, -1, panel.Width - left * 2, anchors, panel); txtBox.Location = new Point(left + 2, top + label.Height + 2); txtBox.Width = panel.Width - 2 * (left + 2); totHgt = txtBox.Bottom - top; } else if (left + Tools.GetLabelWidth(introText, font) + width > panel.Width * 0.9) { label = AddMultilineLabel(introText, font, top, left, -1, panel.Width - left * 2, anchors, panel); txtBox.Location = new Point(left + 2, top + label.Height + 1); txtBox.Width = label.Width; totHgt = txtBox.Bottom - top; } else { label = AddLabel(introText, font, top + 2, left, ContentAlignment.MiddleLeft, anchors, panel); txtBox.Location = new Point(left + label.Width + 2, top); } } else { txtBox.Location = new Point(left, top); } panel.Controls.Add(txtBox); txtBox.LostFocus += new System.EventHandler(Preview_Event); return(totHgt); }
public static int AddTextBox(string text, Font font, int top, int left, int numlines, int width, string introText, Panel panel, int selidx) { int gap = 4; TextBoxPP txtBox = new TextBoxPP(); txtBox.Font = font; txtBox.ForeColor = Color.Blue; txtBox.SelectedIndex = selidx; txtBox.Width = width; txtBox.Multiline = numlines == 1 ? false : true; txtBox.ScrollBars = (txtBox.Multiline) ? ScrollBars.Vertical : ScrollBars.None; txtBox.Height = (int)(font.Size * 2.25 * numlines); txtBox.Top = top; txtBox.Text = text; Label label = null; int totHgt = txtBox.Height; // Default if (introText != null & introText != "") { if (numlines > 1) { label = AddLabel(introText, font, Color.Black, top + 1, left, -1, ContentAlignment.TopLeft, panel); txtBox.Location = new Point(left + 2, top + label.Height + gap); txtBox.Width = panel.Width - 2 * (left + 2); totHgt = txtBox.Bottom - top; } else if (left + Tools.GetLabelWidth(introText, font) + width > panel.Width * 0.9) { label = AddMultilineLabel(introText, font, Color.Black, top, left, -1, panel.Width - left * 2, panel); txtBox.Location = new Point(left, top + label.Height + gap); txtBox.Width = label.Width; totHgt = txtBox.Bottom - top; } else { label = AddLabel(introText, font, Color.Black, top + 1, left, -1, ContentAlignment.TopLeft, panel); // Debug: Was 'MiddleLeft' in Desktop Preview txtBox.Location = new Point(left + label.Width + 4, top); } } else { txtBox.Location = new Point(left, top); } panel.Controls.Add(txtBox); txtBox.LostFocus += new System.EventHandler(PanelChoices_Event); return(totHgt); }