public FormField(Field f, XDataForm form, int tabIndex) { m_field = f; m_type = f.Type; m_var = f.Var; m_val = f.Vals; m_required = f.IsRequired; m_form = form; Panel p = null; if (m_type != FieldType.hidden) { p = new Panel(); p.Parent = m_form.pnlFields; p.TabIndex = tabIndex; } switch (m_type) { case FieldType.hidden: break; case FieldType.boolean: CheckBox cb = new CheckBox(); cb.Checked = f.BoolVal; cb.Text = null; m_control = cb; break; case FieldType.text_multi: TextBox mtxt = new TextBox(); mtxt.Multiline = true; mtxt.ScrollBars = ScrollBars.Vertical; mtxt.Lines = m_val; mtxt.Height = m_form.btnOK.Height * 3; m_control = mtxt; break; case FieldType.text_private: TextBox ptxt = new TextBox(); ptxt.Lines = m_val; ptxt.PasswordChar = '*'; m_control = ptxt; break; case FieldType.list_single: ComboBox box = new ComboBox(); box.DropDownStyle = ComboBoxStyle.DropDownList; box.BeginUpdate(); string v = null; if (m_val.Length > 0) { v = m_val[0]; } foreach (Option o in f.GetOptions()) { int i = box.Items.Add(o); if (o.Val == v) { box.SelectedIndex = i; } } box.EndUpdate(); m_control = box; break; case FieldType.list_multi: //ListBox lb = new ListBox(); CheckedListBox lb = new CheckedListBox(); //lb.SelectionMode = SelectionMode.MultiExtended; lb.VisibleChanged += new EventHandler(lb_VisibleChanged); m_control = lb; break; case FieldType.jid_single: TextBox jtxt = new TextBox(); jtxt.Lines = m_val; jtxt.Validating += new CancelEventHandler(jid_Validating); jtxt.Validated += new EventHandler(jid_Validated); m_control = jtxt; m_form.error.SetIconAlignment(m_control, ErrorIconAlignment.MiddleLeft); break; case FieldType.jid_multi: JidMulti multi = new JidMulti(); multi.AddRange(m_val); m_control = multi; break; case FieldType.Fixed: // All of this so that we can detect URLs. // We can't just make it disabled, because then the URL clicked // event handler doesn't fire, and there's no way to set the // text foreground color. // It would be cool to make copy work, but it doesn't work for // labels, either. RichTextBox rich = new RichTextBox(); rich.DetectUrls = true; rich.Text = string.Join("\r\n", f.Vals); rich.ScrollBars = RichTextBoxScrollBars.None; rich.Resize += new EventHandler(lbl_Resize); rich.BorderStyle = BorderStyle.None; rich.LinkClicked += new LinkClickedEventHandler(rich_LinkClicked); rich.BackColor = System.Drawing.SystemColors.Control; rich.KeyPress += new KeyPressEventHandler(rich_KeyPress); rich.GotFocus += new EventHandler(rich_GotFocus); rich.AcceptsTab = false; rich.AutoSize = false; m_control = rich; break; default: TextBox txt = new TextBox(); txt.Lines = m_val; m_control = txt; break; } if (m_type != FieldType.hidden) { m_control.Parent = p; if (f.Desc != null) { form.tip.SetToolTip(m_control, f.Desc); } String lblText = ""; if (f.Label != "") { lblText = f.Label + ":"; } else if (f.Var != "") { lblText = f.Var + ":"; } if (lblText != "") { m_label = new Label(); m_label.Parent = p; m_label.Text = lblText; if (m_required) { m_label.Text = "* " + m_label.Text; m_form.error.SetIconAlignment(m_control, ErrorIconAlignment.MiddleLeft); m_control.Validating += new CancelEventHandler(m_control_Validating); m_control.Validated += new EventHandler(m_control_Validated); } Graphics graphics = m_label.CreateGraphics(); SizeF s = m_label.Size; s.Height = 0; int chars; int lines; SizeF textSize = graphics.MeasureString(m_label.Text, m_label.Font, s, StringFormat.GenericDefault, out chars, out lines); m_label.Height = (int)(textSize.Height); if (lines > 1) { m_label.TextAlign = ContentAlignment.MiddleLeft; } else { m_label.TextAlign = ContentAlignment.TopLeft; } m_label.Top = 0; p.Controls.Add(m_label); m_control.Location = new Point(m_label.Width + 3, 0); m_control.Width = p.Width - m_label.Width - 6; p.Height = Math.Max(m_label.Height, m_control.Height) + 4; } else { m_control.Location = new Point(0, 0); m_control.Width = p.Width - 6; p.Height = m_control.Height + 4; } m_control.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; p.Controls.Add(m_control); p.Dock = DockStyle.Top; m_form.pnlFields.Controls.Add(p); if (m_form.m_type != XDataType.form) { m_control.Enabled = false; } } }
public FormField(Field f, XDataForm form, int tabIndex) { m_field = f; m_type = f.Type; m_var = f.Var; m_val = f.Vals; m_required = f.IsRequired; m_form = form; Panel p = null; if (m_type != FieldType.hidden) { p = new Panel(); p.Parent = m_form.pnlFields; p.TabIndex = tabIndex; } switch (m_type) { case FieldType.hidden: break; case FieldType.boolean: CheckBox cb = new CheckBox(); cb.Checked = f.BoolVal; cb.Text = null; m_control = cb; break; case FieldType.text_multi: TextBox mtxt = new TextBox(); mtxt.Multiline = true; mtxt.ScrollBars = ScrollBars.Vertical; mtxt.Lines = m_val; mtxt.Height = m_form.btnOK.Height * 3; m_control = mtxt; break; case FieldType.text_private: TextBox ptxt = new TextBox(); ptxt.Lines = m_val; ptxt.PasswordChar = '*'; m_control = ptxt; break; case FieldType.list_single: ComboBox box = new ComboBox(); box.DropDownStyle = ComboBoxStyle.DropDownList; box.BeginUpdate(); string v = null; if (m_val.Length > 0) v = m_val[0]; foreach (Option o in f.GetOptions()) { int i = box.Items.Add(o); if (o.Val == v) { box.SelectedIndex = i; } } box.EndUpdate(); m_control = box; break; case FieldType.list_multi: //ListBox lb = new ListBox(); CheckedListBox lb = new CheckedListBox(); //lb.SelectionMode = SelectionMode.MultiExtended; lb.VisibleChanged += new EventHandler(lb_VisibleChanged); m_control = lb; break; case FieldType.jid_single: TextBox jtxt = new TextBox(); jtxt.Lines = m_val; jtxt.Validating += new CancelEventHandler(jid_Validating); jtxt.Validated += new EventHandler(jid_Validated); m_control = jtxt; m_form.error.SetIconAlignment(m_control, ErrorIconAlignment.MiddleLeft); break; case FieldType.jid_multi: JidMulti multi = new JidMulti(); multi.AddRange(m_val); m_control = multi; break; case FieldType.Fixed: // All of this so that we can detect URLs. // We can't just make it disabled, because then the URL clicked // event handler doesn't fire, and there's no way to set the // text foreground color. // It would be cool to make copy work, but it doesn't work for // labels, either. RichTextBox rich = new RichTextBox(); rich.DetectUrls = true; rich.Text = string.Join("\r\n", f.Vals); rich.ScrollBars = RichTextBoxScrollBars.None; rich.Resize += new EventHandler(lbl_Resize); rich.BorderStyle = BorderStyle.None; rich.LinkClicked += new LinkClickedEventHandler(rich_LinkClicked); rich.BackColor = System.Drawing.SystemColors.Control; rich.KeyPress += new KeyPressEventHandler(rich_KeyPress); rich.GotFocus += new EventHandler(rich_GotFocus); rich.AcceptsTab = false; rich.AutoSize = false; m_control = rich; break; default: TextBox txt = new TextBox(); txt.Lines = m_val; m_control = txt; break; } if (m_type != FieldType.hidden) { m_control.Parent = p; if (f.Desc != null) form.tip.SetToolTip(m_control, f.Desc); String lblText = ""; if (f.Label != "") lblText = f.Label + ":"; else if (f.Var != "") lblText = f.Var + ":"; if (lblText != "") { m_label = new Label(); m_label.Parent = p; m_label.Text = lblText; if (m_required) { m_label.Text = "* " + m_label.Text; m_form.error.SetIconAlignment(m_control, ErrorIconAlignment.MiddleLeft); m_control.Validating += new CancelEventHandler(m_control_Validating); m_control.Validated += new EventHandler(m_control_Validated); } Graphics graphics = m_label.CreateGraphics(); SizeF s = m_label.Size; s.Height = 0; int chars; int lines; SizeF textSize = graphics.MeasureString(m_label.Text, m_label.Font, s, StringFormat.GenericDefault, out chars, out lines); m_label.Height = (int)(textSize.Height); if (lines > 1) m_label.TextAlign = ContentAlignment.MiddleLeft; else m_label.TextAlign = ContentAlignment.TopLeft; m_label.Top = 0; p.Controls.Add(m_label); m_control.Location = new Point(m_label.Width + 3, 0); m_control.Width = p.Width - m_label.Width - 6; p.Height = Math.Max(m_label.Height, m_control.Height) + 4; } else { m_control.Location = new Point(0, 0); m_control.Width = p.Width - 6; p.Height = m_control.Height + 4; } m_control.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; p.Controls.Add(m_control); p.Dock = DockStyle.Top; m_form.pnlFields.Controls.Add(p); if (m_form.m_type != XDataType.form) m_control.Enabled = false; } }