Horizontal Radiobuttons
Column2 is DataGridViewTextBoxCell
Horizontal Custom Radiobuttons =>
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace HRadioButtons { public partial class HorizontalRadioButtons : UserControl { public event EventHandler CheckedChanged; private int minWidth = 5; private int oneCharWidth = 7; private int extraWidth = 40; private List<string> _titles; private List<RadioButton> radiobuttons = new List<RadioButton>(); private int _radiobuttonsIndex = 0; public int Value { get { return _radiobuttonsIndex; } set { setRadiobuttons(value); } } public int SelectedValue { get { return _radiobuttonsIndex; } set { setRadiobuttons(value); } } public List<string> Titles { get { return _titles; } set { _titles = value; } } public int RowIndex; public int CellIndex; public HorizontalRadioButtons() { } public HorizontalRadioButtons(List<string> titles, DataGridView dgv, int columnIndex, int rowIndex) { InitializeComponent(); if (dgv != null && dgv.Rows.Count > 0) { Titles = titles; Rectangle rect = dgv.GetCellDisplayRectangle(columnIndex, rowIndex, true); this.Location = new Point(rect.X, rect.Y); this.Size = new Size(rect.Width + 0, rect.Height + 0); this.RowIndex = rowIndex; int position = minWidth; int width = 0; int i = 0; foreach (string item in Titles) { RadioButton r = new RadioButton(); r.Text = item; r.Location = new Point(position, 0); r.Size = new Size(item.Length * oneCharWidth + extraWidth, rect.Height); position += item.Length * oneCharWidth + extraWidth; width += item.Length * oneCharWidth + extraWidth; r.CheckedChanged += r_CheckedChanged; this.Controls.Add(r); radiobuttons.Add(r); i++; } radiobuttons.Reverse(); //radiobuttons[Value].Checked = true; this.Width = width; this.Height = rect.Height; } } public void SetChecked(int index) { if (index >= 0 && index < radiobuttons.Count) { radiobuttons[index].Checked = true; } } void r_CheckedChanged(object sender, EventArgs e) { //int k = radiobuttons.Count - 1; int k = 0; foreach (RadioButton item in radiobuttons) { if (item.Checked) { if (SelectedValue != k) { _radiobuttonsIndex = k; CheckedChanged(this, e); return; } } k++; } } private void setRadiobuttons(int value) { if (_radiobuttonsIndex != value) { if (value >= 0 && value < radiobuttons.Count) { radiobuttons[value].Checked = true; _radiobuttonsIndex = value; //Value = value; //cause trouble //SelectedValue = value; //cause trouble } } } } }
namespace HRadioButtons { partial class HorizontalRadioButtons { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Component Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.radioButton1 = new System.Windows.Forms.RadioButton(); this.SuspendLayout(); // // radioButton1 // this.radioButton1.AutoSize = true; this.radioButton1.Location = new System.Drawing.Point(476, 14); this.radioButton1.Name = "radioButton1"; this.radioButton1.Size = new System.Drawing.Size(85, 17); this.radioButton1.TabIndex = 0; this.radioButton1.TabStop = true; this.radioButton1.Text = "radioButton1"; this.radioButton1.UseVisualStyleBackColor = true; // // HorizontalRadioButtons // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.ActiveCaption; this.Controls.Add(this.radioButton1); this.Margin = new System.Windows.Forms.Padding(0); this.Name = "HorizontalRadioButtons"; this.Size = new System.Drawing.Size(564, 41); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.RadioButton radioButton1; } }
Usage => Code
public partial class Form1 : Form { HorizontalRadioButtons rbs; BindingSource bs = new BindingSource(); Dictionary<int, HorizontalRadioButtons> _RadioButtons = new Dictionary<int, HorizontalRadioButtons>(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { List<string> titles = new List<string>(); titles.Add("A"); titles.Add("B"); titles.Add("C"); titles.Add("Good"); //rbs = new HorizontalRadioButtons(); //rbs.Titles = titles; //rbs.Location = new Point(20, 30); //rbs.Height = 25; //rbs.CheckedChanged += rbs_CheckedChanged; //this.Controls.Add(rbs); //rbs.DrawRadioButtons(); DataTable table = new DataTable(); table.Columns.Add("Name", typeof(string)); table.Columns.Add("Age", typeof(int)); table.Rows.Add("Yang", 0); table.Rows.Add("Betty", 1); bs.DataSource = table; dataGridView1.DataSource = bs; dataGridView1.AutoGenerateColumns = false; DataRowView row = (DataRowView)bs.Current; rbs = new HorizontalRadioButtons(titles, dataGridView1, 1, 0); dataGridView1.Controls.Add(rbs); rbs.CheckedChanged += rbs_CheckedChanged; rbs.SetChecked((int)row[1]); bs.MoveNext(); row = (DataRowView)bs.Current; rbs = new HorizontalRadioButtons(titles, dataGridView1, 1, 1); dataGridView1.Controls.Add(rbs); rbs.CheckedChanged += rbs_CheckedChanged; rbs.SetChecked((int)row[1]); dataGridView1.Invalidate(); } void rbs_CheckedChanged(object sender, EventArgs e) { HorizontalRadioButtons rdbTmp = sender as HorizontalRadioButtons; if (rdbTmp == null) { return; } //MessageBox.Show(rbs.SelectedValue.ToString()); //dataGridView1.Rows[rbs.RowIndex].Selected = true; if (rdbTmp.RowIndex == 0) { bs.MoveFirst(); } else { bs.Position = rdbTmp.RowIndex - 1; bs.MoveNext(); } DataRowView row = (DataRowView)bs.Current; row[1] = rdbTmp.Value; row.EndEdit(); //MessageBox.Show(rdb.Value.ToString()); } private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e) { int x; DataRowView row = (DataRowView)bs.Current; row.EndEdit(); if (dataGridView1.CurrentCell.ColumnIndex == 1) { //_RadioButtons[(int)row[1]].Value = int.TryParse(row[1].ToString(), out x) ? x : 0; } }
RadiobuttonFive usage:
DataTable table = new DataTable(); table.TableName = "Parent"; table.Columns.Add("Index_Code", typeof(string)); table.Columns.Add("Index_Item_Name", typeof(string)); table.Columns.Add("Index_Item_Value", typeof(decimal)); table.Columns.Add("Score", typeof(decimal)); table.Rows.Add("11", "How are you?", 10, 0); table.Rows.Add("11", "What is your favor?", 10, 0); FlowLayoutPanel flp = new FlowLayoutPanel(); this.Controls.Add(flp); flp.Width = 800; int c = 1; foreach (DataRow item in table.Rows) { decimal d1 = (decimal)item["Index_Item_Value"]; decimal d2 = (decimal)item["Score"]; RadioButtonFive rb = new RadioButtonFive(c, item["Index_Code"].ToString(), item["Index_Item_Name"].ToString(), d1, d2, 200); rb.AnswerTypes = 3; rb.Col2Width = 300; rb.AllowDataChanged = true; rb.Refresh(); flp.Controls.Add(rb); rb.ProperAnswerType(); }
RadioButtonFive user control
Code
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace WFControlLibrary { public partial class RadioButtonFive : UserControl { public event EventHandler Clicked; public int RowNumber = 0; public int Value { get; set; } public int AnswerTypes { get; set; } // 1 = Five; 2 = Two; 3 = Two Numbers [Bindable(true)] public int SerialNo { get; set; } [Bindable(true)] public string ItemCode { get; set; } [Bindable(true)] public string Question { get; set; } [Bindable(true)] public decimal AssignedValue { get; set; } [Bindable(true)] public decimal Score { get; set; } public decimal NumberAInput { get; set; } public decimal NumberBInput { get; set; } [Bindable(true)] public bool AllowDataChanged { get; set; } public int Col1Width { get; set; } public int Col2Width { get; set; } public int Col3Width { get; set; } public int Col4Width { get; set; } public int Col5Width { get; set; } TextBox NumberA = new TextBox(); TextBox NumberB = new TextBox(); ErrorProvider errorProvider; public RadioButtonFive() { InitializeComponent(); //tableLayoutPanel1.co tableLayoutPanel1.BackColor = Color.LightPink; if (RowNumber % 2 == 0) { //tableLayoutPanel1.BackColor = new Color( } } public RadioButtonFive(int aSerialNo, string itemCode, string aQuestion, decimal aValue, decimal aScore, int questionWidth) { InitializeComponent(); this.SerialNo = aSerialNo; this.ItemCode = itemCode; this.Question = aQuestion; this.AssignedValue = aValue; this.Score = aScore; lbSerialNo.Text = SerialNo.ToString(); lbQuestion.Text = Question; lbValue.Text = AssignedValue.ToString(); lbScore.Text = Score.ToString(); Col2Width = questionWidth; errorProvider = new ErrorProvider(); if (aSerialNo % 2 == 0) { tableLayoutPanel1.BackColor = Color.Beige; } } public RadioButtonFive(int aSerialNo, string itemCode, string aQuestion, decimal aValue, decimal aScore, int questionWidth, int type) { InitializeComponent(); this.SerialNo = aSerialNo; this.ItemCode = itemCode; this.Question = aQuestion; this.AssignedValue = aValue; this.Score = aScore; lbSerialNo.Text = SerialNo.ToString(); lbQuestion.Text = Question; lbValue.Text = AssignedValue.ToString(); lbScore.Text = Score.ToString(); Col2Width = questionWidth; errorProvider = new ErrorProvider(); if (aSerialNo % 2 == 0) { tableLayoutPanel1.BackColor = Color.Beige; } } public new void Refresh() { lbSerialNo.Text = SerialNo.ToString(); lbQuestion.Text = Question; lbValue.Text = AssignedValue.ToString(); lbScore.Text = Score.ToString(); tableLayoutPanel1.ColumnStyles[1].SizeType = SizeType.Absolute; tableLayoutPanel1.ColumnStyles[1].Width = Col2Width; if (AnswerTypes == 1) { if (Score > 0.0001m) { int x = (int)Math.Round(((4 * Score) / AssignedValue)); if (x == 4) { rbA.Checked = true; } else if (x == 3) { rbB.Checked = true; } else if (x == 2) { rbC.Checked = true; } else if (x == 1) { rbD.Checked = true; } else { rbE.Checked = true; } } if (AllowDataChanged == false) { rbA.Enabled = false; rbB.Enabled = false; rbC.Enabled = false; rbD.Enabled = false; rbE.Enabled = false; } } if (AnswerTypes == 2) { if (Score > 0.0001m) { int x = (int)Math.Round((Score / AssignedValue)); if (x == 1) { rbA.Checked = true; } else { rbB.Checked = true; } } if (AllowDataChanged == false) { rbA.Enabled = false; rbB.Enabled = false; } } if (AnswerTypes == 3) { NumberA.Text = NumberAInput.ToString(); NumberB.Text = NumberBInput.ToString(); if (AllowDataChanged == false) { NumberA.Enabled = false; NumberB.Enabled = false; } } } private void rbA_CheckedChanged(object sender, EventArgs e) { if (AnswerTypes == 1) { if (rbA.Checked) { Value = 4; } if (rbB.Checked) { Value = 3; } if (rbC.Checked) { Value = 2; } if (rbD.Checked) { Value = 1; } if (rbE.Checked) { Value = 0; } Score = Value * AssignedValue / 4; lbScore.Text = Score.ToString(); } if (AnswerTypes == 2) { if (rbA.Checked) { Value = 1; } if (rbB.Checked) { Value = 0; } Score = Value * AssignedValue; lbScore.Text = Score.ToString(); } if (Value == 0) { tableLayoutPanel1.BackColor = Color.LightPink; } else { tableLayoutPanel1.BackColor = Color.LawnGreen; } Clicked(sender, e); } private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e) { } private void RadioButtonFive_Load(object sender, EventArgs e) { } public void ProperAnswerType() { if (AnswerTypes == 1) //default { return; } if (AnswerTypes == 2) // two answer => modify answers { rbC.Visible = false; rbD.Visible = false; rbE.Visible = false; rbC.Enabled = false; rbD.Enabled = false; rbE.Enabled = false; rbA.Text = "Choosed"; rbB.Text = "Unchoosed"; TableLayoutColumnStyleCollection styles = tableFlowLayoutPanelAnswer.ColumnStyles; if (styles.Count == 5) { styles[0].Width = 84; styles[1].Width = 84; styles[2].Width = 0; styles[3].Width = 0; styles[4].Width = 0; } TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles; styles2[3].Width = 170; } if (AnswerTypes == 3) // numbers { rbA.Visible = false; rbB.Visible = false; rbC.Visible = false; rbD.Visible = false; rbE.Visible = false; rbA.Enabled = false; rbB.Enabled = false; rbC.Enabled = false; rbD.Enabled = false; rbE.Enabled = false; NumberA.Validated += NumberA_Validated; NumberB.Validated += NumberB_Validated; NumberA.Width = 60; NumberB.Width = 60; TableLayoutColumnStyleCollection styles = tableFlowLayoutPanelAnswer.ColumnStyles; if (styles.Count == 5) { styles[0].Width = 84; styles[1].Width = 84; styles[2].Width = 0; styles[3].Width = 0; styles[4].Width = 0; } tableFlowLayoutPanelAnswer.Controls.Clear(); tableFlowLayoutPanelAnswer.Controls.Add(NumberA, 0, 0); //NumberB.Dock = DockStyle.Right; tableFlowLayoutPanelAnswer.Controls.Add(NumberB, 1, 0); TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles; styles2[3].Width = 170; NumberB.Invalidate(); } } void NumberA_Validated(object sender, EventArgs e) { decimal tmp; if (decimal.TryParse(NumberA.Text.ToString(), out tmp)) { if (tmp < 0 || tmp > 100) { NumberAInput = tmp; errorProvider.SetError(NumberA, "number is out of range"); } else { NumberAInput = tmp; errorProvider.SetError(NumberA, ""); } } else { NumberAInput = 0; errorProvider.SetError(NumberA, "Not a number"); } } void NumberB_Validated(object sender, EventArgs e) { decimal tmp; if (decimal.TryParse(NumberB.Text.ToString(), out tmp)) { if (tmp < 0 || tmp > 100) { NumberBInput = tmp; errorProvider.SetError(NumberB, "number is out of range"); } else { NumberBInput = tmp; errorProvider.SetError(NumberB, ""); } } else { NumberBInput = 0; errorProvider.SetError(NumberB, "Not a number"); } } } }
UI
namespace WFControlLibrary { partial class RadioButtonFive { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region 组件设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.rbA = new System.Windows.Forms.RadioButton(); this.rbB = new System.Windows.Forms.RadioButton(); this.rbC = new System.Windows.Forms.RadioButton(); this.rbD = new System.Windows.Forms.RadioButton(); this.rbE = new System.Windows.Forms.RadioButton(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.lbScore = new System.Windows.Forms.Label(); this.lbValue = new System.Windows.Forms.Label(); this.lbQuestion = new System.Windows.Forms.Label(); this.tableFlowLayoutPanelAnswer = new System.Windows.Forms.TableLayoutPanel(); this.lbSerialNo = new System.Windows.Forms.Label(); this.tableLayoutPanel1.SuspendLayout(); this.tableFlowLayoutPanelAnswer.SuspendLayout(); this.SuspendLayout(); // // rbA // this.rbA.AutoSize = true; this.rbA.Location = new System.Drawing.Point(3, 3); this.rbA.Name = "rbA"; this.rbA.Size = new System.Drawing.Size(32, 17); this.rbA.TabIndex = 0; this.rbA.Text = "A"; this.rbA.UseVisualStyleBackColor = true; this.rbA.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbB // this.rbB.AutoSize = true; this.rbB.Location = new System.Drawing.Point(43, 3); this.rbB.Name = "rbB"; this.rbB.Size = new System.Drawing.Size(32, 17); this.rbB.TabIndex = 1; this.rbB.Text = "B"; this.rbB.UseVisualStyleBackColor = true; this.rbB.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbC // this.rbC.AutoSize = true; this.rbC.Location = new System.Drawing.Point(83, 3); this.rbC.Name = "rbC"; this.rbC.Size = new System.Drawing.Size(32, 17); this.rbC.TabIndex = 2; this.rbC.Text = "C"; this.rbC.UseVisualStyleBackColor = true; this.rbC.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbD // this.rbD.AutoSize = true; this.rbD.Location = new System.Drawing.Point(123, 3); this.rbD.Name = "rbD"; this.rbD.Size = new System.Drawing.Size(33, 17); this.rbD.TabIndex = 3; this.rbD.Text = "D"; this.rbD.UseVisualStyleBackColor = true; this.rbD.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbE // this.rbE.AutoSize = true; this.rbE.Checked = true; this.rbE.Location = new System.Drawing.Point(163, 3); this.rbE.Name = "rbE"; this.rbE.Size = new System.Drawing.Size(61, 17); this.rbE.TabIndex = 4; this.rbE.TabStop = true; this.rbE.Text = "未回答"; this.rbE.UseVisualStyleBackColor = true; this.rbE.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // tableLayoutPanel1 // this.tableLayoutPanel1.AutoSize = true; this.tableLayoutPanel1.BackColor = System.Drawing.SystemColors.InactiveCaption; this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; this.tableLayoutPanel1.ColumnCount = 5; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 60F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 229F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 90F)); this.tableLayoutPanel1.Controls.Add(this.lbScore, 4, 0); this.tableLayoutPanel1.Controls.Add(this.lbValue, 2, 0); this.tableLayoutPanel1.Controls.Add(this.lbQuestion, 1, 0); this.tableLayoutPanel1.Controls.Add(this.tableFlowLayoutPanelAnswer, 3, 0); this.tableLayoutPanel1.Controls.Add(this.lbSerialNo, 0, 0); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Left; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 1; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(466, 44); this.tableLayoutPanel1.TabIndex = 5; this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint); // // lbScore // this.lbScore.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lbScore.AutoSize = true; this.lbScore.Location = new System.Drawing.Point(378, 1); this.lbScore.Name = "lbScore"; this.lbScore.Size = new System.Drawing.Size(84, 42); this.lbScore.TabIndex = 9; this.lbScore.Text = "label4"; this.lbScore.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbValue // this.lbValue.Dock = System.Windows.Forms.DockStyle.Fill; this.lbValue.Location = new System.Drawing.Point(87, 1); this.lbValue.Name = "lbValue"; this.lbValue.Size = new System.Drawing.Size(54, 42); this.lbValue.TabIndex = 8; this.lbValue.Text = "label3"; this.lbValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbQuestion // this.lbQuestion.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lbQuestion.AutoSize = true; this.lbQuestion.Location = new System.Drawing.Point(45, 1); this.lbQuestion.Name = "lbQuestion"; this.lbQuestion.Size = new System.Drawing.Size(35, 42); this.lbQuestion.TabIndex = 7; this.lbQuestion.Text = "label2"; this.lbQuestion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // tableFlowLayoutPanelAnswer // this.tableFlowLayoutPanelAnswer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableFlowLayoutPanelAnswer.ColumnCount = 5; this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbE, 4, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbC, 2, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbD, 3, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbA, 0, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbB, 1, 0); this.tableFlowLayoutPanelAnswer.Location = new System.Drawing.Point(148, 4); this.tableFlowLayoutPanelAnswer.Name = "tableFlowLayoutPanelAnswer"; this.tableFlowLayoutPanelAnswer.RowCount = 1; this.tableFlowLayoutPanelAnswer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableFlowLayoutPanelAnswer.Size = new System.Drawing.Size(223, 36); this.tableFlowLayoutPanelAnswer.TabIndex = 5; // // lbSerialNo // this.lbSerialNo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lbSerialNo.Location = new System.Drawing.Point(4, 1); this.lbSerialNo.Name = "lbSerialNo"; this.lbSerialNo.Size = new System.Drawing.Size(34, 42); this.lbSerialNo.TabIndex = 6; this.lbSerialNo.Text = "lb1"; this.lbSerialNo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // RadioButtonFive // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.tableLayoutPanel1); this.Margin = new System.Windows.Forms.Padding(0); this.Name = "RadioButtonFive"; this.Size = new System.Drawing.Size(1077, 44); this.Load += new System.EventHandler(this.RadioButtonFive_Load); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); this.tableFlowLayoutPanelAnswer.ResumeLayout(false); this.tableFlowLayoutPanelAnswer.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.RadioButton rbA; private System.Windows.Forms.RadioButton rbB; private System.Windows.Forms.RadioButton rbC; private System.Windows.Forms.RadioButton rbD; private System.Windows.Forms.RadioButton rbE; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Label lbScore; private System.Windows.Forms.Label lbValue; private System.Windows.Forms.Label lbQuestion; private System.Windows.Forms.TableLayoutPanel tableFlowLayoutPanelAnswer; private System.Windows.Forms.Label lbSerialNo; } }
RadioButton with Y/N, 1/0, true/false;
Use GroupBox to implement it.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace WFControlLibrary { public partial class RadioButtonFive : UserControl { public event EventHandler Clicked; public int AnswerWidth { get; set; } public int RowNumber = 0; public int Value { get; set; } public int AnswerTypes { get; set; } // 1 = Five; 2 = Two; 3 = Two Numbers [Bindable(true)] public int SerialNo { get; set; } [Bindable(true)] public string ItemCode { get; set; } [Bindable(true)] public string Question { get; set; } [Bindable(true)] public decimal AssignedValue { get; set; } [Bindable(true)] public decimal Score { get; set; } public decimal NumberAInput { get; set; } public decimal NumberBInput { get; set; } [Bindable(true)] public bool AllowDataChanged { get; set; } public int Col1Width { get; set; } public int Col2Width { get; set; } public int Col3Width { get; set; } public int Col4Width { get; set; } public int Col5Width { get; set; } TextBox NumberA = new TextBox(); TextBox NumberB = new TextBox(); ErrorProvider errorProvider = new ErrorProvider(); public RadioButtonFive() { InitializeComponent(); //tableLayoutPanel1.co tableLayoutPanel1.BackColor = Color.LightPink; if (RowNumber % 2 == 0) { //tableLayoutPanel1.BackColor = new Color( } } public RadioButtonFive(int aSerialNo, string itemCode, string aQuestion, decimal aValue, decimal aScore, int questionWidth) { InitializeComponent(); this.SerialNo = aSerialNo; this.ItemCode = itemCode; this.Question = aQuestion; this.AssignedValue = aValue; this.Score = aScore; lbSerialNo.Text = SerialNo.ToString(); lbQuestion.Text = Question; lbValue.Text = AssignedValue.ToString(); lbScore.Text = Score.ToString(); Col2Width = questionWidth; ErrorProvider errorProvider = new ErrorProvider(); if (aSerialNo % 2 == 0) { tableLayoutPanel1.BackColor = Color.Beige; } } public RadioButtonFive(int aSerialNo, string itemCode, string aQuestion, decimal aValue, decimal aScore, int questionWidth, int type) { InitializeComponent(); this.SerialNo = aSerialNo; this.ItemCode = itemCode; this.Question = aQuestion; this.AssignedValue = aValue; this.Score = aScore; lbSerialNo.Text = SerialNo.ToString(); lbQuestion.Text = Question; lbValue.Text = AssignedValue.ToString(); lbScore.Text = Score.ToString(); Col2Width = questionWidth; if (aSerialNo % 2 == 0) { tableLayoutPanel1.BackColor = Color.Beige; } } public new void Refresh() { lbSerialNo.Text = SerialNo.ToString(); lbQuestion.Text = Question; lbValue.Text = AssignedValue.ToString(); lbScore.Text = Score.ToString(); tableLayoutPanel1.ColumnStyles[1].SizeType = SizeType.Absolute; tableLayoutPanel1.ColumnStyles[1].Width = Col2Width; if (AnswerTypes == 1) { if (Score > 0.0001m) { int x = (int)Math.Round(((4 * Score) / AssignedValue)); if (x == 4) { rbA.Checked = true; } else if (x == 3) { rbB.Checked = true; } else if (x == 2) { rbC.Checked = true; } else if (x == 1) { rbD.Checked = true; } else { rbE.Checked = true; } } if (AllowDataChanged == false) { rbA.Enabled = false; rbB.Enabled = false; rbC.Enabled = false; rbD.Enabled = false; rbE.Enabled = false; } } if (AnswerTypes == 2) { if (Score > 0.0001m) { int x = (int)Math.Round((Score / AssignedValue)); if (x == 1) { rbA.Checked = true; } else { rbB.Checked = true; } } if (AllowDataChanged == false) { rbA.Enabled = false; rbB.Enabled = false; } } if (AnswerTypes == 3) { NumberA.Text = NumberAInput.ToString(); NumberA.Name = "txtNumber"; NumberB.Text = NumberBInput.ToString(); NumberB.Name = "txtExpiredNumber"; if (AllowDataChanged == false) { NumberA.Enabled = false; NumberB.Enabled = false; } NumberA.TextChanged += new EventHandler(NumberA_TextChanged); NumberB.TextChanged += new EventHandler(NumberB_TextChanged); } } private void rbA_CheckedChanged(object sender, EventArgs e) { if (AnswerTypes == 1) { if (rbA.Checked) { Value = 4; } if (rbB.Checked) { Value = 3; } if (rbC.Checked) { Value = 2; } if (rbD.Checked) { Value = 1; } if (rbE.Checked) { Value = 0; } Score = Value * AssignedValue / 4; lbScore.Text = Score.ToString(); } if (AnswerTypes == 2) { if (rbA.Checked) { Value = 1; } if (rbB.Checked) { Value = 0; } Score = Value * AssignedValue; lbScore.Text = Score.ToString(); } if (Value == 0) { tableLayoutPanel1.BackColor = Color.LightPink; } else { tableLayoutPanel1.BackColor = Color.LawnGreen; } Clicked(sender, e); } public void ProperAnswerType() { if (AnswerTypes == 1) //default { return; } if (AnswerTypes == 2) // two answer => modify answers { rbC.Visible = false; rbD.Visible = false; rbE.Visible = false; rbC.Enabled = false; rbD.Enabled = false; rbE.Enabled = false; rbA.Text = "达标"; rbB.Text = "未达标"; TableLayoutColumnStyleCollection styles = tableFlowLayoutPanelAnswer.ColumnStyles; if (styles.Count == 5) { styles[0].Width = AnswerWidth/2 - 1; styles[1].Width = AnswerWidth/2 - 1; styles[2].Width = 0; styles[3].Width = 0; styles[4].Width = 0; } TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles; styles2[3].Width = AnswerWidth; } if (AnswerTypes == 3) // numbers { rbA.Visible = false; rbB.Visible = false; rbC.Visible = false; rbD.Visible = false; rbE.Visible = false; rbA.Enabled = false; rbB.Enabled = false; rbC.Enabled = false; rbD.Enabled = false; rbE.Enabled = false; //NumberA.TextChanged += NumberA_TextChanged; //NumberB.TextChanged += NumberB_TextChanged; NumberA.Validated += NumberA_TextChanged; NumberB.Validated += NumberB_TextChanged; NumberA.Width = AnswerWidth/2 - 5; NumberB.Width = AnswerWidth/2 - 5; TableLayoutColumnStyleCollection styles = tableFlowLayoutPanelAnswer.ColumnStyles; if (styles.Count == 5) { styles[0].Width = AnswerWidth/2 - 1; styles[1].Width = AnswerWidth/2 - 1; styles[2].Width = 0; styles[3].Width = 0; styles[4].Width = 0; } tableFlowLayoutPanelAnswer.Controls.Clear(); tableFlowLayoutPanelAnswer.Controls.Add(NumberA, 0, 0); tableFlowLayoutPanelAnswer.Controls.Add(NumberB, 1, 0); TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles; styles2[3].Width = AnswerWidth; } } void NumberA_TextChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(NumberA.Text.Trim())) { NumberAInput = decimal.MinValue; //special Clicked(sender, e); return; } decimal tmp; if (decimal.TryParse(NumberA.Text.ToString(), out tmp)) { NumberAInput = tmp; if (NumberAInput > 0 && NumberBInput >= 0 && NumberAInput - NumberBInput >= 0) { NumberAInput = tmp; Score = Math.Round((NumberAInput - NumberBInput) / NumberAInput, 3) * AssignedValue; lbScore.Text = Score.ToString(); errorProvider.SetError(NumberA, ""); } else { lbScore.Text = ""; errorProvider.SetError(NumberA, "该行数据有错"); } } else { NumberAInput = 0; lbScore.Text = ""; errorProvider.SetError(NumberA, "该值不是一个数据。"); } if (Score == 0) { tableLayoutPanel1.BackColor = Color.LightPink; } else { tableLayoutPanel1.BackColor = Color.LawnGreen; } Clicked(sender, e); } void NumberB_TextChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(NumberA.Text.Trim())) { NumberAInput = decimal.MinValue;//special Clicked(sender, e); return; } decimal tmp; if (decimal.TryParse(NumberB.Text.ToString(), out tmp)) { if (NumberAInput > 0 && NumberBInput >= 0 && NumberAInput - NumberBInput >= 0) { NumberBInput = tmp; Score = Math.Round((NumberAInput - NumberBInput) / NumberAInput, 3) * AssignedValue; lbScore.Text = Score.ToString(); errorProvider.SetError(NumberB, ""); } else { errorProvider.SetError(NumberB, "该行数据有错"); lbScore.Text = ""; } } else { NumberBInput = 0; lbScore.Text = ""; MessageBox.Show("该值不是一个数据。"); } if (Score == 0) { tableLayoutPanel1.BackColor = Color.LightPink; } else { tableLayoutPanel1.BackColor = Color.LawnGreen; } Clicked(sender, e); } } }
namespace WFControlLibrary { partial class RadioButtonFive { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region 组件设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.rbA = new System.Windows.Forms.RadioButton(); this.rbB = new System.Windows.Forms.RadioButton(); this.rbC = new System.Windows.Forms.RadioButton(); this.rbD = new System.Windows.Forms.RadioButton(); this.rbE = new System.Windows.Forms.RadioButton(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.lbScore = new System.Windows.Forms.Label(); this.lbValue = new System.Windows.Forms.Label(); this.lbQuestion = new System.Windows.Forms.Label(); this.tableFlowLayoutPanelAnswer = new System.Windows.Forms.TableLayoutPanel(); this.lbSerialNo = new System.Windows.Forms.Label(); this.tableLayoutPanel1.SuspendLayout(); this.tableFlowLayoutPanelAnswer.SuspendLayout(); this.SuspendLayout(); // // rbA // this.rbA.AutoSize = true; this.rbA.Location = new System.Drawing.Point(3, 3); this.rbA.Name = "rbA"; this.rbA.Size = new System.Drawing.Size(29, 16); this.rbA.TabIndex = 0; this.rbA.Text = "A"; this.rbA.UseVisualStyleBackColor = true; this.rbA.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbB // this.rbB.AutoSize = true; this.rbB.Location = new System.Drawing.Point(43, 3); this.rbB.Name = "rbB"; this.rbB.Size = new System.Drawing.Size(29, 16); this.rbB.TabIndex = 1; this.rbB.Text = "B"; this.rbB.UseVisualStyleBackColor = true; this.rbB.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbC // this.rbC.AutoSize = true; this.rbC.Location = new System.Drawing.Point(83, 3); this.rbC.Name = "rbC"; this.rbC.Size = new System.Drawing.Size(29, 16); this.rbC.TabIndex = 2; this.rbC.Text = "C"; this.rbC.UseVisualStyleBackColor = true; this.rbC.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbD // this.rbD.AutoSize = true; this.rbD.Location = new System.Drawing.Point(123, 3); this.rbD.Name = "rbD"; this.rbD.Size = new System.Drawing.Size(29, 16); this.rbD.TabIndex = 3; this.rbD.Text = "D"; this.rbD.UseVisualStyleBackColor = true; this.rbD.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbE // this.rbE.AutoSize = true; this.rbE.Checked = true; this.rbE.Location = new System.Drawing.Point(163, 3); this.rbE.Name = "rbE"; this.rbE.Size = new System.Drawing.Size(59, 16); this.rbE.TabIndex = 4; this.rbE.TabStop = true; this.rbE.Text = "未回答"; this.rbE.UseVisualStyleBackColor = true; this.rbE.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // tableLayoutPanel1 // this.tableLayoutPanel1.AutoSize = true; this.tableLayoutPanel1.BackColor = System.Drawing.SystemColors.InactiveCaption; this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; this.tableLayoutPanel1.ColumnCount = 5; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 60F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 229F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 84F)); this.tableLayoutPanel1.Controls.Add(this.lbScore, 4, 0); this.tableLayoutPanel1.Controls.Add(this.lbValue, 2, 0); this.tableLayoutPanel1.Controls.Add(this.lbQuestion, 1, 0); this.tableLayoutPanel1.Controls.Add(this.tableFlowLayoutPanelAnswer, 3, 0); this.tableLayoutPanel1.Controls.Add(this.lbSerialNo, 0, 0); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Left; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 1; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(466, 41); this.tableLayoutPanel1.TabIndex = 5; // // lbScore // this.lbScore.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lbScore.AutoSize = true; this.lbScore.Location = new System.Drawing.Point(384, 1); this.lbScore.Name = "lbScore"; this.lbScore.Size = new System.Drawing.Size(78, 39); this.lbScore.TabIndex = 9; this.lbScore.Text = "label4"; this.lbScore.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbValue // this.lbValue.Dock = System.Windows.Forms.DockStyle.Fill; this.lbValue.Location = new System.Drawing.Point(93, 1); this.lbValue.Name = "lbValue"; this.lbValue.Size = new System.Drawing.Size(54, 39); this.lbValue.TabIndex = 8; this.lbValue.Text = "label3"; this.lbValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbQuestion // this.lbQuestion.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lbQuestion.AutoSize = true; this.lbQuestion.Location = new System.Drawing.Point(45, 1); this.lbQuestion.Name = "lbQuestion"; this.lbQuestion.Size = new System.Drawing.Size(41, 39); this.lbQuestion.TabIndex = 7; this.lbQuestion.Text = "label2"; this.lbQuestion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // tableFlowLayoutPanelAnswer // this.tableFlowLayoutPanelAnswer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableFlowLayoutPanelAnswer.ColumnCount = 5; this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbE, 4, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbC, 2, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbD, 3, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbA, 0, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbB, 1, 0); this.tableFlowLayoutPanelAnswer.Location = new System.Drawing.Point(154, 4); this.tableFlowLayoutPanelAnswer.Name = "tableFlowLayoutPanelAnswer"; this.tableFlowLayoutPanelAnswer.RowCount = 1; this.tableFlowLayoutPanelAnswer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableFlowLayoutPanelAnswer.Size = new System.Drawing.Size(223, 33); this.tableFlowLayoutPanelAnswer.TabIndex = 5; // // lbSerialNo // this.lbSerialNo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lbSerialNo.Location = new System.Drawing.Point(4, 1); this.lbSerialNo.Name = "lbSerialNo"; this.lbSerialNo.Size = new System.Drawing.Size(34, 39); this.lbSerialNo.TabIndex = 6; this.lbSerialNo.Text = "lb1"; this.lbSerialNo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // RadioButtonFive // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.tableLayoutPanel1); this.Margin = new System.Windows.Forms.Padding(0); this.Name = "RadioButtonFive"; this.Size = new System.Drawing.Size(1077, 41); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); this.tableFlowLayoutPanelAnswer.ResumeLayout(false); this.tableFlowLayoutPanelAnswer.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.RadioButton rbA; private System.Windows.Forms.RadioButton rbB; private System.Windows.Forms.RadioButton rbC; private System.Windows.Forms.RadioButton rbD; private System.Windows.Forms.RadioButton rbE; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Label lbScore; private System.Windows.Forms.Label lbValue; private System.Windows.Forms.Label lbQuestion; private System.Windows.Forms.TableLayoutPanel tableFlowLayoutPanelAnswer; private System.Windows.Forms.Label lbSerialNo; } }
FiveRadiobuttonTitle
partial class RadioButtonFiveTitle { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region 组件设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.label1 = new System.Windows.Forms.Label(); this.lbScore = new System.Windows.Forms.Label(); this.lbValue = new System.Windows.Forms.Label(); this.lbQuestion = new System.Windows.Forms.Label(); this.lbSerialNo = new System.Windows.Forms.Label(); this.tableLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // // tableLayoutPanel1 // this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel1.AutoSize = true; this.tableLayoutPanel1.BackColor = System.Drawing.SystemColors.InactiveCaption; this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; this.tableLayoutPanel1.ColumnCount = 5; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 60F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 229F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 70F)); this.tableLayoutPanel1.Controls.Add(this.lbScore, 4, 0); this.tableLayoutPanel1.Controls.Add(this.lbQuestion, 1, 0); this.tableLayoutPanel1.Controls.Add(this.lbValue, 3, 0); this.tableLayoutPanel1.Controls.Add(this.lbSerialNo, 1, 0); this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 1; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(518, 38); this.tableLayoutPanel1.TabIndex = 6; this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint); // // label1 // this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(4, 1); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(34, 36); this.label1.TabIndex = 10; this.label1.Text = "序号"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbScore // this.lbScore.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.lbScore.AutoSize = true; this.lbScore.Location = new System.Drawing.Point(377, 1); this.lbScore.Name = "lbScore"; this.lbScore.Size = new System.Drawing.Size(31, 36); this.lbScore.TabIndex = 9; this.lbScore.Text = "得分"; this.lbScore.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbValue // this.lbValue.Dock = System.Windows.Forms.DockStyle.Fill; this.lbValue.Location = new System.Drawing.Point(147, 1); this.lbValue.Name = "lbValue"; this.lbValue.Size = new System.Drawing.Size(223, 36); this.lbValue.TabIndex = 8; this.lbValue.Text = "请选择下面的项"; this.lbValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbQuestion // this.lbQuestion.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lbQuestion.AutoSize = true; this.lbQuestion.Location = new System.Drawing.Point(86, 1); this.lbQuestion.Name = "lbQuestion"; this.lbQuestion.Size = new System.Drawing.Size(54, 36); this.lbQuestion.TabIndex = 7; this.lbQuestion.Text = "标准值"; this.lbQuestion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // lbSerialNo // this.lbSerialNo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lbSerialNo.Location = new System.Drawing.Point(45, 1); this.lbSerialNo.Name = "lbSerialNo"; this.lbSerialNo.Size = new System.Drawing.Size(34, 36); this.lbSerialNo.TabIndex = 6; this.lbSerialNo.Text = "护理质量指标标准项目"; this.lbSerialNo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // RadioButtonFiveTitle // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.tableLayoutPanel1); this.Margin = new System.Windows.Forms.Padding(0); this.Name = "RadioButtonFiveTitle"; this.Size = new System.Drawing.Size(518, 41); this.Load += new System.EventHandler(this.RadioButtonFiveTitle_Load); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label lbScore; private System.Windows.Forms.Label lbValue; private System.Windows.Forms.Label lbQuestion; private System.Windows.Forms.Label lbSerialNo; }
public partial class RadioButtonFiveTitle : UserControl { public int Col1Width { get; set; } public int Col2Width { get; set; } public int Col3Width { get; set; } public int Col4Width { get; set; } public int Col5Width { get; set; } public int TotalWidth { get; set; } public RadioButtonFiveTitle() { InitializeComponent(); } private void RadioButtonFiveTitle_Load(object sender, EventArgs e) { } public new void Refresh() { tableLayoutPanel1.ColumnStyles[1].SizeType = SizeType.Absolute; Col1Width = (int)tableLayoutPanel1.ColumnStyles[0].Width; Col3Width = (int)tableLayoutPanel1.ColumnStyles[2].Width; Col4Width = (int)tableLayoutPanel1.ColumnStyles[3].Width; Col5Width = (int)tableLayoutPanel1.ColumnStyles[4].Width; tableLayoutPanel1.ColumnStyles[0].Width = Col1Width; tableLayoutPanel1.ColumnStyles[1].Width = Col2Width; tableLayoutPanel1.ColumnStyles[2].Width = Col3Width; tableLayoutPanel1.ColumnStyles[3].Width = Col4Width; tableLayoutPanel1.ColumnStyles[4].Width = Col5Width; TotalWidth = Col1Width + Col3Width + Col4Width + Col5Width; } private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e) { } }
FiveRadiobutton
partial class RadioButtonFive { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region 组件设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.rbA = new System.Windows.Forms.RadioButton(); this.rbB = new System.Windows.Forms.RadioButton(); this.rbC = new System.Windows.Forms.RadioButton(); this.rbD = new System.Windows.Forms.RadioButton(); this.rbE = new System.Windows.Forms.RadioButton(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.lbScore = new System.Windows.Forms.Label(); this.lbValue = new System.Windows.Forms.Label(); this.lbQuestion = new System.Windows.Forms.Label(); this.tableFlowLayoutPanelAnswer = new System.Windows.Forms.TableLayoutPanel(); this.lbSerialNo = new System.Windows.Forms.Label(); this.tableLayoutPanel1.SuspendLayout(); this.tableFlowLayoutPanelAnswer.SuspendLayout(); this.SuspendLayout(); // // rbA // this.rbA.AutoSize = true; this.rbA.Location = new System.Drawing.Point(3, 3); this.rbA.Name = "rbA"; this.rbA.Size = new System.Drawing.Size(32, 17); this.rbA.TabIndex = 0; this.rbA.Text = "A"; this.rbA.UseVisualStyleBackColor = true; this.rbA.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbB // this.rbB.AutoSize = true; this.rbB.Location = new System.Drawing.Point(43, 3); this.rbB.Name = "rbB"; this.rbB.Size = new System.Drawing.Size(32, 17); this.rbB.TabIndex = 1; this.rbB.Text = "B"; this.rbB.UseVisualStyleBackColor = true; this.rbB.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbC // this.rbC.AutoSize = true; this.rbC.Location = new System.Drawing.Point(83, 3); this.rbC.Name = "rbC"; this.rbC.Size = new System.Drawing.Size(32, 17); this.rbC.TabIndex = 2; this.rbC.Text = "C"; this.rbC.UseVisualStyleBackColor = true; this.rbC.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbD // this.rbD.AutoSize = true; this.rbD.Location = new System.Drawing.Point(123, 3); this.rbD.Name = "rbD"; this.rbD.Size = new System.Drawing.Size(33, 17); this.rbD.TabIndex = 3; this.rbD.Text = "D"; this.rbD.UseVisualStyleBackColor = true; this.rbD.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // rbE // this.rbE.AutoSize = true; this.rbE.Checked = true; this.rbE.Location = new System.Drawing.Point(163, 3); this.rbE.Name = "rbE"; this.rbE.Size = new System.Drawing.Size(61, 17); this.rbE.TabIndex = 4; this.rbE.TabStop = true; this.rbE.Text = "未回答"; this.rbE.UseVisualStyleBackColor = true; this.rbE.CheckedChanged += new System.EventHandler(this.rbA_CheckedChanged); // // tableLayoutPanel1 // this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel1.AutoSize = true; this.tableLayoutPanel1.BackColor = System.Drawing.SystemColors.InactiveCaption; this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; this.tableLayoutPanel1.ColumnCount = 5; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 60F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 229F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 70F)); this.tableLayoutPanel1.Controls.Add(this.lbScore, 4, 0); this.tableLayoutPanel1.Controls.Add(this.lbValue, 2, 0); this.tableLayoutPanel1.Controls.Add(this.lbQuestion, 1, 0); this.tableLayoutPanel1.Controls.Add(this.tableFlowLayoutPanelAnswer, 3, 0); this.tableLayoutPanel1.Controls.Add(this.lbSerialNo, 0, 0); this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 1; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(480, 44); this.tableLayoutPanel1.TabIndex = 5; this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint); // // lbScore // this.lbScore.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.lbScore.AutoSize = true; this.lbScore.Location = new System.Drawing.Point(378, 1); this.lbScore.Name = "lbScore"; this.lbScore.Size = new System.Drawing.Size(35, 42); this.lbScore.TabIndex = 9; this.lbScore.Text = "label4"; this.lbScore.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbValue // this.lbValue.Dock = System.Windows.Forms.DockStyle.Fill; this.lbValue.Location = new System.Drawing.Point(87, 1); this.lbValue.Name = "lbValue"; this.lbValue.Size = new System.Drawing.Size(54, 42); this.lbValue.TabIndex = 8; this.lbValue.Text = "label3"; this.lbValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbQuestion // this.lbQuestion.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lbQuestion.AutoSize = true; this.lbQuestion.Location = new System.Drawing.Point(45, 1); this.lbQuestion.Name = "lbQuestion"; this.lbQuestion.Size = new System.Drawing.Size(35, 42); this.lbQuestion.TabIndex = 7; this.lbQuestion.Text = "label2"; this.lbQuestion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // tableFlowLayoutPanelAnswer // this.tableFlowLayoutPanelAnswer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableFlowLayoutPanelAnswer.ColumnCount = 5; this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableFlowLayoutPanelAnswer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbE, 4, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbC, 2, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbD, 3, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbA, 0, 0); this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbB, 1, 0); this.tableFlowLayoutPanelAnswer.Location = new System.Drawing.Point(148, 4); this.tableFlowLayoutPanelAnswer.Name = "tableFlowLayoutPanelAnswer"; this.tableFlowLayoutPanelAnswer.RowCount = 1; this.tableFlowLayoutPanelAnswer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableFlowLayoutPanelAnswer.Size = new System.Drawing.Size(223, 36); this.tableFlowLayoutPanelAnswer.TabIndex = 5; // // lbSerialNo // this.lbSerialNo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lbSerialNo.Location = new System.Drawing.Point(4, 1); this.lbSerialNo.Name = "lbSerialNo"; this.lbSerialNo.Size = new System.Drawing.Size(34, 42); this.lbSerialNo.TabIndex = 6; this.lbSerialNo.Text = "lb1"; this.lbSerialNo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // RadioButtonFive // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.tableLayoutPanel1); this.Margin = new System.Windows.Forms.Padding(0); this.Name = "RadioButtonFive"; this.Size = new System.Drawing.Size(480, 44); this.Load += new System.EventHandler(this.RadioButtonFive_Load); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); this.tableFlowLayoutPanelAnswer.ResumeLayout(false); this.tableFlowLayoutPanelAnswer.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.RadioButton rbA; private System.Windows.Forms.RadioButton rbB; private System.Windows.Forms.RadioButton rbC; private System.Windows.Forms.RadioButton rbD; private System.Windows.Forms.RadioButton rbE; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Label lbScore; private System.Windows.Forms.Label lbValue; private System.Windows.Forms.Label lbQuestion; private System.Windows.Forms.TableLayoutPanel tableFlowLayoutPanelAnswer; private System.Windows.Forms.Label lbSerialNo; }
public partial class RadioButtonFive : UserControl { public event EventHandler Clicked; public int RowNumber = 0; public int Value { get; set; } public int AnswerTypes { get; set; } // 1 = Five; 2 = Two; 3 = Two Numbers [Bindable(true)] public int SerialNo { get; set; } [Bindable(true)] public string ItemCode { get; set; } [Bindable(true)] public string Question { get; set; } [Bindable(true)] public decimal AssignedValue { get; set; } [Bindable(true)] public decimal Score { get; set; } public decimal NumberAInput { get; set; } public decimal NumberBInput { get; set; } [Bindable(true)] public bool AllowDataChanged { get; set; } public int Col1Width { get; set; } public int Col2Width { get; set; } public int Col3Width { get; set; } public int Col4Width { get; set; } public int Col5Width { get; set; } TextBox NumberA = new TextBox(); TextBox NumberB = new TextBox(); ErrorProvider errorProvider; public RadioButtonFive() { InitializeComponent(); //tableLayoutPanel1.co tableLayoutPanel1.BackColor = Color.LightPink; if (RowNumber % 2 == 0) { //tableLayoutPanel1.BackColor = new Color( } } public RadioButtonFive(int aSerialNo, string itemCode, string aQuestion, decimal aValue, decimal aScore, int questionWidth) { InitializeComponent(); this.SerialNo = aSerialNo; this.ItemCode = itemCode; this.Question = aQuestion; this.AssignedValue = aValue; this.Score = aScore; lbSerialNo.Text = SerialNo.ToString(); lbQuestion.Text = Question; lbValue.Text = AssignedValue.ToString(); lbScore.Text = Score.ToString(); Col2Width = questionWidth; errorProvider = new ErrorProvider(); if (aSerialNo % 2 == 0) { tableLayoutPanel1.BackColor = Color.Beige; } } public RadioButtonFive(int aSerialNo, string itemCode, string aQuestion, decimal aValue, decimal aScore, int questionWidth, int type) { InitializeComponent(); this.SerialNo = aSerialNo; this.ItemCode = itemCode; this.Question = aQuestion; this.AssignedValue = aValue; this.Score = aScore; lbSerialNo.Text = SerialNo.ToString(); lbQuestion.Text = Question; lbValue.Text = AssignedValue.ToString(); lbScore.Text = Score.ToString(); Col2Width = questionWidth; errorProvider = new ErrorProvider(); if (aSerialNo % 2 == 0) { tableLayoutPanel1.BackColor = Color.Beige; } } public new void Refresh() { lbSerialNo.Text = SerialNo.ToString(); lbQuestion.Text = Question; lbValue.Text = AssignedValue.ToString(); lbScore.Text = Score.ToString(); tableLayoutPanel1.ColumnStyles[1].SizeType = SizeType.Absolute; tableLayoutPanel1.ColumnStyles[1].Width = Col2Width; tableLayoutPanel1.ColumnStyles[0].Width = Col1Width; tableLayoutPanel1.ColumnStyles[1].Width = Col2Width; tableLayoutPanel1.ColumnStyles[2].Width = Col3Width; tableLayoutPanel1.ColumnStyles[3].Width = Col4Width; tableLayoutPanel1.ColumnStyles[4].Width = Col5Width; if (AnswerTypes == 1) { if (Score > 0.0001m) { int x = (int)Math.Round(((4 * Score) / AssignedValue)); if (x == 4) { rbA.Checked = true; } else if (x == 3) { rbB.Checked = true; } else if (x == 2) { rbC.Checked = true; } else if (x == 1) { rbD.Checked = true; } else { rbE.Checked = true; } } if (AllowDataChanged == false) { rbA.Enabled = false; rbB.Enabled = false; rbC.Enabled = false; rbD.Enabled = false; rbE.Enabled = false; } } if (AnswerTypes == 2) { if (Score > 0.0001m) { int x = (int)Math.Round((Score / AssignedValue)); if (x == 1) { rbA.Checked = true; } else { rbB.Checked = true; } } if (AllowDataChanged == false) { rbA.Enabled = false; rbB.Enabled = false; } } if (AnswerTypes == 3) { NumberA.Text = NumberAInput.ToString(); NumberB.Text = NumberBInput.ToString(); if (AllowDataChanged == false) { NumberA.Enabled = false; NumberB.Enabled = false; } } } private void rbA_CheckedChanged(object sender, EventArgs e) { if (AnswerTypes == 1) { if (rbA.Checked) { Value = 4; } if (rbB.Checked) { Value = 3; } if (rbC.Checked) { Value = 2; } if (rbD.Checked) { Value = 1; } if (rbE.Checked) { Value = 0; } Score = Value * AssignedValue / 4; lbScore.Text = Score.ToString(); } if (AnswerTypes == 2) { if (rbA.Checked) { Value = 1; } if (rbB.Checked) { Value = 0; } Score = Value * AssignedValue; lbScore.Text = Score.ToString(); } if (Value == 0) { tableLayoutPanel1.BackColor = Color.LightPink; } else { tableLayoutPanel1.BackColor = Color.LawnGreen; } Clicked(sender, e); } private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e) { } private void RadioButtonFive_Load(object sender, EventArgs e) { } public void ProperAnswerType() { if (AnswerTypes == 1) //default { return; } if (AnswerTypes == 2) // two answer => modify answers { rbC.Visible = false; rbD.Visible = false; rbE.Visible = false; rbC.Enabled = false; rbD.Enabled = false; rbE.Enabled = false; rbA.Text = "Choosed"; rbB.Text = "Unchoosed"; TableLayoutColumnStyleCollection styles = tableFlowLayoutPanelAnswer.ColumnStyles; if (styles.Count == 5) { styles[0].Width = 84; styles[1].Width = 84; styles[2].Width = 0; styles[3].Width = 0; styles[4].Width = 0; } TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles; styles2[3].Width = 170; } if (AnswerTypes == 3) // numbers { rbA.Visible = false; rbB.Visible = false; rbC.Visible = false; rbD.Visible = false; rbE.Visible = false; rbA.Enabled = false; rbB.Enabled = false; rbC.Enabled = false; rbD.Enabled = false; rbE.Enabled = false; NumberA.Validated += NumberA_Validated; NumberB.Validated += NumberB_Validated; NumberA.Width = 60; NumberB.Width = 60; TableLayoutColumnStyleCollection styles = tableFlowLayoutPanelAnswer.ColumnStyles; if (styles.Count == 5) { styles[0].Width = 84; styles[1].Width = 84; styles[2].Width = 0; styles[3].Width = 0; styles[4].Width = 0; } tableFlowLayoutPanelAnswer.Controls.Clear(); tableFlowLayoutPanelAnswer.Controls.Add(NumberA, 0, 0); //NumberB.Dock = DockStyle.Right; tableFlowLayoutPanelAnswer.Controls.Add(NumberB, 1, 0); TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles; styles2[0].Width = 170; styles2[1].Width = 170; styles2[2].Width = 170; styles2[3].Width = 170; NumberB.Invalidate(); } } void NumberA_Validated(object sender, EventArgs e) { decimal tmp; if (decimal.TryParse(NumberA.Text.ToString(), out tmp)) { if (tmp < 0 || tmp > 100) { NumberAInput = tmp; errorProvider.SetError(NumberA, "number is out of range"); } else { NumberAInput = tmp; errorProvider.SetError(NumberA, ""); } } else { NumberAInput = 0; errorProvider.SetError(NumberA, "Not a number"); } } void NumberB_Validated(object sender, EventArgs e) { decimal tmp; if (decimal.TryParse(NumberB.Text.ToString(), out tmp)) { if (tmp < 0 || tmp > 100) { NumberBInput = tmp; errorProvider.SetError(NumberB, "number is out of range"); } else { NumberBInput = tmp; errorProvider.SetError(NumberB, ""); } } else { NumberBInput = 0; errorProvider.SetError(NumberB, "Not a number"); } } }
Usage =>
radioButtonFiveTitle1.Refresh(); radioButtonFiveTitle1.Width = 400 + radioButtonFiveTitle1.TotalWidth; radioButtonFiveTitle1.Col2Width = 400; radioButtonFiveTitle1.Refresh(); radioButtonFive1.Col1Width = radioButtonFiveTitle1.Col1Width; radioButtonFive1.Col2Width = radioButtonFiveTitle1.Col2Width; radioButtonFive1.Col3Width = radioButtonFiveTitle1.Col3Width; radioButtonFive1.Col4Width = radioButtonFiveTitle1.Col4Width; radioButtonFive1.Col5Width = radioButtonFiveTitle1.Col5Width; radioButtonFive1.Width = radioButtonFiveTitle1.Width; radioButtonFive1.Refresh();