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 = ;
private int oneCharWidth = ;
private int extraWidth = ;
private List<string> _titles;
private List<RadioButton> radiobuttons = new List<RadioButton>();
private int _radiobuttonsIndex = ; 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 > )
{
Titles = titles;
Rectangle rect = dgv.GetCellDisplayRectangle(columnIndex, rowIndex, true); this.Location = new Point(rect.X, rect.Y);
this.Size = new Size(rect.Width + , rect.Height + );
this.RowIndex = rowIndex; int position = minWidth;
int width = ;
int i = ;
foreach (string item in Titles)
{
RadioButton r = new RadioButton();
r.Text = item; r.Location = new Point(position, );
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 >= && index < radiobuttons.Count)
{
radiobuttons[index].Checked = true;
}
} void r_CheckedChanged(object sender, EventArgs e)
{
//int k = radiobuttons.Count - 1;
int k = ;
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 >= && 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(, );
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(, );
this.radioButton1.TabIndex = ;
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();
this.Name = "HorizontalRadioButtons";
this.Size = new System.Drawing.Size(, );
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", );
table.Rows.Add("Betty", ); bs.DataSource = table;
dataGridView1.DataSource = bs;
dataGridView1.AutoGenerateColumns = false; DataRowView row = (DataRowView)bs.Current; rbs = new HorizontalRadioButtons(titles, dataGridView1, , );
dataGridView1.Controls.Add(rbs);
rbs.CheckedChanged += rbs_CheckedChanged;
rbs.SetChecked((int)row[]); bs.MoveNext();
row = (DataRowView)bs.Current; rbs = new HorizontalRadioButtons(titles, dataGridView1, , );
dataGridView1.Controls.Add(rbs);
rbs.CheckedChanged += rbs_CheckedChanged;
rbs.SetChecked((int)row[]); 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 == )
{
bs.MoveFirst();
}
else
{
bs.Position = rdbTmp.RowIndex - ;
bs.MoveNext();
} DataRowView row = (DataRowView)bs.Current; row[] = 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 == )
{
//_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("", "How are you?", , );
table.Rows.Add("", "What is your favor?", , ); FlowLayoutPanel flp = new FlowLayoutPanel();
this.Controls.Add(flp); flp.Width = ;
int c = ;
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, );
rb.AnswerTypes = ;
rb.Col2Width = ;
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 = ;
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 % == )
{
//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 % == )
{
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 % == )
{
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[].SizeType = SizeType.Absolute;
tableLayoutPanel1.ColumnStyles[].Width = Col2Width; if (AnswerTypes == )
{
if (Score > 0.0001m)
{
int x = (int)Math.Round((( * Score) / AssignedValue)); if (x == )
{
rbA.Checked = true;
}
else if (x == )
{
rbB.Checked = true;
}
else if (x == )
{
rbC.Checked = true;
}
else if (x == )
{
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 == )
{
if (Score > 0.0001m)
{
int x = (int)Math.Round((Score / AssignedValue)); if (x == )
{
rbA.Checked = true;
}
else
{
rbB.Checked = true;
}
} if (AllowDataChanged == false)
{
rbA.Enabled = false;
rbB.Enabled = false;
}
} if (AnswerTypes == )
{
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 == )
{
if (rbA.Checked)
{
Value = ;
}
if (rbB.Checked)
{
Value = ;
}
if (rbC.Checked)
{
Value = ;
}
if (rbD.Checked)
{
Value = ;
}
if (rbE.Checked)
{
Value = ;
} Score = Value * AssignedValue / ; lbScore.Text = Score.ToString();
} if (AnswerTypes == )
{
if (rbA.Checked)
{
Value = ;
}
if (rbB.Checked)
{
Value = ;
} Score = Value * AssignedValue; lbScore.Text = Score.ToString();
} if (Value == )
{
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 == ) //default
{
return;
} if (AnswerTypes == ) // 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 == )
{
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
} TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles;
styles2[].Width = ;
} if (AnswerTypes == ) // 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 = ;
NumberB.Width = ; TableLayoutColumnStyleCollection styles = tableFlowLayoutPanelAnswer.ColumnStyles;
if (styles.Count == )
{
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
}
tableFlowLayoutPanelAnswer.Controls.Clear();
tableFlowLayoutPanelAnswer.Controls.Add(NumberA, , ); //NumberB.Dock = DockStyle.Right;
tableFlowLayoutPanelAnswer.Controls.Add(NumberB, , ); TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles;
styles2[].Width = ; NumberB.Invalidate();
} } void NumberA_Validated(object sender, EventArgs e)
{
decimal tmp;
if (decimal.TryParse(NumberA.Text.ToString(), out tmp))
{
if (tmp < || tmp > )
{
NumberAInput = tmp;
errorProvider.SetError(NumberA, "number is out of range");
}
else
{
NumberAInput = tmp;
errorProvider.SetError(NumberA, "");
}
}
else
{
NumberAInput = ;
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 < || tmp > )
{
NumberBInput = tmp;
errorProvider.SetError(NumberB, "number is out of range");
}
else
{
NumberBInput = tmp;
errorProvider.SetError(NumberB, "");
}
}
else
{
NumberBInput = ;
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(, );
this.rbA.Name = "rbA";
this.rbA.Size = new System.Drawing.Size(, );
this.rbA.TabIndex = ;
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(, );
this.rbB.Name = "rbB";
this.rbB.Size = new System.Drawing.Size(, );
this.rbB.TabIndex = ;
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(, );
this.rbC.Name = "rbC";
this.rbC.Size = new System.Drawing.Size(, );
this.rbC.TabIndex = ;
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(, );
this.rbD.Name = "rbD";
this.rbD.Size = new System.Drawing.Size(, );
this.rbD.TabIndex = ;
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(, );
this.rbE.Name = "rbE";
this.rbE.Size = new System.Drawing.Size(, );
this.rbE.TabIndex = ;
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 = ;
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, , );
this.tableLayoutPanel1.Controls.Add(this.lbValue, , );
this.tableLayoutPanel1.Controls.Add(this.lbQuestion, , );
this.tableLayoutPanel1.Controls.Add(this.tableFlowLayoutPanelAnswer, , );
this.tableLayoutPanel1.Controls.Add(this.lbSerialNo, , );
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Left;
this.tableLayoutPanel1.Location = new System.Drawing.Point(, );
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = ;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(, );
this.tableLayoutPanel1.TabIndex = ;
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(, );
this.lbScore.Name = "lbScore";
this.lbScore.Size = new System.Drawing.Size(, );
this.lbScore.TabIndex = ;
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(, );
this.lbValue.Name = "lbValue";
this.lbValue.Size = new System.Drawing.Size(, );
this.lbValue.TabIndex = ;
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(, );
this.lbQuestion.Name = "lbQuestion";
this.lbQuestion.Size = new System.Drawing.Size(, );
this.lbQuestion.TabIndex = ;
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 = ;
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, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbC, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbD, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbA, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbB, , );
this.tableFlowLayoutPanelAnswer.Location = new System.Drawing.Point(, );
this.tableFlowLayoutPanelAnswer.Name = "tableFlowLayoutPanelAnswer";
this.tableFlowLayoutPanelAnswer.RowCount = ;
this.tableFlowLayoutPanelAnswer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableFlowLayoutPanelAnswer.Size = new System.Drawing.Size(, );
this.tableFlowLayoutPanelAnswer.TabIndex = ;
//
// 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(, );
this.lbSerialNo.Name = "lbSerialNo";
this.lbSerialNo.Size = new System.Drawing.Size(, );
this.lbSerialNo.TabIndex = ;
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();
this.Name = "RadioButtonFive";
this.Size = new System.Drawing.Size(, );
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 = ;
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 % == )
{
//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 % == )
{
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 % == )
{
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[].SizeType = SizeType.Absolute;
tableLayoutPanel1.ColumnStyles[].Width = Col2Width; if (AnswerTypes == )
{
if (Score > 0.0001m)
{
int x = (int)Math.Round((( * Score) / AssignedValue)); if (x == )
{
rbA.Checked = true;
}
else if (x == )
{
rbB.Checked = true;
}
else if (x == )
{
rbC.Checked = true;
}
else if (x == )
{
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 == )
{
if (Score > 0.0001m)
{
int x = (int)Math.Round((Score / AssignedValue)); if (x == )
{
rbA.Checked = true;
}
else
{
rbB.Checked = true;
}
} if (AllowDataChanged == false)
{
rbA.Enabled = false;
rbB.Enabled = false;
} } if (AnswerTypes == )
{
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 == )
{
if (rbA.Checked)
{
Value = ;
}
if (rbB.Checked)
{
Value = ;
}
if (rbC.Checked)
{
Value = ;
}
if (rbD.Checked)
{
Value = ;
}
if (rbE.Checked)
{
Value = ;
} Score = Value * AssignedValue / ; lbScore.Text = Score.ToString();
} if (AnswerTypes == )
{
if (rbA.Checked)
{
Value = ;
}
if (rbB.Checked)
{
Value = ;
} Score = Value * AssignedValue; lbScore.Text = Score.ToString();
} if (Value == )
{
tableLayoutPanel1.BackColor = Color.LightPink;
}
else
{
tableLayoutPanel1.BackColor = Color.LawnGreen;
} Clicked(sender, e);
} public void ProperAnswerType()
{
if (AnswerTypes == ) //default
{
return;
} if (AnswerTypes == ) // 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 == )
{
styles[].Width = AnswerWidth/ - ;
styles[].Width = AnswerWidth/ - ;
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
} TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles;
styles2[].Width = AnswerWidth;
} if (AnswerTypes == ) // 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/ - ;
NumberB.Width = AnswerWidth/ - ; TableLayoutColumnStyleCollection styles = tableFlowLayoutPanelAnswer.ColumnStyles;
if (styles.Count == )
{
styles[].Width = AnswerWidth/ - ;
styles[].Width = AnswerWidth/ - ;
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
}
tableFlowLayoutPanelAnswer.Controls.Clear();
tableFlowLayoutPanelAnswer.Controls.Add(NumberA, , );
tableFlowLayoutPanelAnswer.Controls.Add(NumberB, , ); TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles;
styles2[].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 > && NumberBInput >= && NumberAInput - NumberBInput >= )
{
NumberAInput = tmp;
Score = Math.Round((NumberAInput - NumberBInput) / NumberAInput, ) * AssignedValue;
lbScore.Text = Score.ToString();
errorProvider.SetError(NumberA, "");
}
else
{
lbScore.Text = "";
errorProvider.SetError(NumberA, "该行数据有错");
} }
else
{
NumberAInput = ;
lbScore.Text = "";
errorProvider.SetError(NumberA, "该值不是一个数据。");
} if (Score == )
{
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 > && NumberBInput >= && NumberAInput - NumberBInput >= )
{
NumberBInput = tmp;
Score = Math.Round((NumberAInput - NumberBInput) / NumberAInput, ) * AssignedValue;
lbScore.Text = Score.ToString();
errorProvider.SetError(NumberB, "");
}
else
{
errorProvider.SetError(NumberB, "该行数据有错");
lbScore.Text = "";
}
}
else
{
NumberBInput = ;
lbScore.Text = "";
MessageBox.Show("该值不是一个数据。");
} if (Score == )
{
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(, );
this.rbA.Name = "rbA";
this.rbA.Size = new System.Drawing.Size(, );
this.rbA.TabIndex = ;
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(, );
this.rbB.Name = "rbB";
this.rbB.Size = new System.Drawing.Size(, );
this.rbB.TabIndex = ;
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(, );
this.rbC.Name = "rbC";
this.rbC.Size = new System.Drawing.Size(, );
this.rbC.TabIndex = ;
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(, );
this.rbD.Name = "rbD";
this.rbD.Size = new System.Drawing.Size(, );
this.rbD.TabIndex = ;
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(, );
this.rbE.Name = "rbE";
this.rbE.Size = new System.Drawing.Size(, );
this.rbE.TabIndex = ;
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 = ;
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, , );
this.tableLayoutPanel1.Controls.Add(this.lbValue, , );
this.tableLayoutPanel1.Controls.Add(this.lbQuestion, , );
this.tableLayoutPanel1.Controls.Add(this.tableFlowLayoutPanelAnswer, , );
this.tableLayoutPanel1.Controls.Add(this.lbSerialNo, , );
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Left;
this.tableLayoutPanel1.Location = new System.Drawing.Point(, );
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = ;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(, );
this.tableLayoutPanel1.TabIndex = ;
//
// 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(, );
this.lbScore.Name = "lbScore";
this.lbScore.Size = new System.Drawing.Size(, );
this.lbScore.TabIndex = ;
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(, );
this.lbValue.Name = "lbValue";
this.lbValue.Size = new System.Drawing.Size(, );
this.lbValue.TabIndex = ;
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(, );
this.lbQuestion.Name = "lbQuestion";
this.lbQuestion.Size = new System.Drawing.Size(, );
this.lbQuestion.TabIndex = ;
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 = ;
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, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbC, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbD, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbA, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbB, , );
this.tableFlowLayoutPanelAnswer.Location = new System.Drawing.Point(, );
this.tableFlowLayoutPanelAnswer.Name = "tableFlowLayoutPanelAnswer";
this.tableFlowLayoutPanelAnswer.RowCount = ;
this.tableFlowLayoutPanelAnswer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableFlowLayoutPanelAnswer.Size = new System.Drawing.Size(, );
this.tableFlowLayoutPanelAnswer.TabIndex = ;
//
// 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(, );
this.lbSerialNo.Name = "lbSerialNo";
this.lbSerialNo.Size = new System.Drawing.Size(, );
this.lbSerialNo.TabIndex = ;
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();
this.Name = "RadioButtonFive";
this.Size = new System.Drawing.Size(, );
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 = ;
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, , );
this.tableLayoutPanel1.Controls.Add(this.lbQuestion, , );
this.tableLayoutPanel1.Controls.Add(this.lbValue, , );
this.tableLayoutPanel1.Controls.Add(this.lbSerialNo, , );
this.tableLayoutPanel1.Controls.Add(this.label1, , );
this.tableLayoutPanel1.Location = new System.Drawing.Point(, );
this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding();
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = ;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(, );
this.tableLayoutPanel1.TabIndex = ;
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(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
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(, );
this.lbScore.Name = "lbScore";
this.lbScore.Size = new System.Drawing.Size(, );
this.lbScore.TabIndex = ;
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(, );
this.lbValue.Name = "lbValue";
this.lbValue.Size = new System.Drawing.Size(, );
this.lbValue.TabIndex = ;
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(, );
this.lbQuestion.Name = "lbQuestion";
this.lbQuestion.Size = new System.Drawing.Size(, );
this.lbQuestion.TabIndex = ;
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(, );
this.lbSerialNo.Name = "lbSerialNo";
this.lbSerialNo.Size = new System.Drawing.Size(, );
this.lbSerialNo.TabIndex = ;
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();
this.Name = "RadioButtonFiveTitle";
this.Size = new System.Drawing.Size(, );
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[].SizeType = SizeType.Absolute;
Col1Width = (int)tableLayoutPanel1.ColumnStyles[].Width;
Col3Width = (int)tableLayoutPanel1.ColumnStyles[].Width;
Col4Width = (int)tableLayoutPanel1.ColumnStyles[].Width;
Col5Width = (int)tableLayoutPanel1.ColumnStyles[].Width; tableLayoutPanel1.ColumnStyles[].Width = Col1Width;
tableLayoutPanel1.ColumnStyles[].Width = Col2Width;
tableLayoutPanel1.ColumnStyles[].Width = Col3Width;
tableLayoutPanel1.ColumnStyles[].Width = Col4Width;
tableLayoutPanel1.ColumnStyles[].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(, );
this.rbA.Name = "rbA";
this.rbA.Size = new System.Drawing.Size(, );
this.rbA.TabIndex = ;
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(, );
this.rbB.Name = "rbB";
this.rbB.Size = new System.Drawing.Size(, );
this.rbB.TabIndex = ;
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(, );
this.rbC.Name = "rbC";
this.rbC.Size = new System.Drawing.Size(, );
this.rbC.TabIndex = ;
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(, );
this.rbD.Name = "rbD";
this.rbD.Size = new System.Drawing.Size(, );
this.rbD.TabIndex = ;
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(, );
this.rbE.Name = "rbE";
this.rbE.Size = new System.Drawing.Size(, );
this.rbE.TabIndex = ;
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 = ;
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, , );
this.tableLayoutPanel1.Controls.Add(this.lbValue, , );
this.tableLayoutPanel1.Controls.Add(this.lbQuestion, , );
this.tableLayoutPanel1.Controls.Add(this.tableFlowLayoutPanelAnswer, , );
this.tableLayoutPanel1.Controls.Add(this.lbSerialNo, , );
this.tableLayoutPanel1.Location = new System.Drawing.Point(, );
this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding();
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = ;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(, );
this.tableLayoutPanel1.TabIndex = ;
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(, );
this.lbScore.Name = "lbScore";
this.lbScore.Size = new System.Drawing.Size(, );
this.lbScore.TabIndex = ;
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(, );
this.lbValue.Name = "lbValue";
this.lbValue.Size = new System.Drawing.Size(, );
this.lbValue.TabIndex = ;
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(, );
this.lbQuestion.Name = "lbQuestion";
this.lbQuestion.Size = new System.Drawing.Size(, );
this.lbQuestion.TabIndex = ;
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 = ;
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, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbC, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbD, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbA, , );
this.tableFlowLayoutPanelAnswer.Controls.Add(this.rbB, , );
this.tableFlowLayoutPanelAnswer.Location = new System.Drawing.Point(, );
this.tableFlowLayoutPanelAnswer.Name = "tableFlowLayoutPanelAnswer";
this.tableFlowLayoutPanelAnswer.RowCount = ;
this.tableFlowLayoutPanelAnswer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableFlowLayoutPanelAnswer.Size = new System.Drawing.Size(, );
this.tableFlowLayoutPanelAnswer.TabIndex = ;
//
// 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(, );
this.lbSerialNo.Name = "lbSerialNo";
this.lbSerialNo.Size = new System.Drawing.Size(, );
this.lbSerialNo.TabIndex = ;
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();
this.Name = "RadioButtonFive";
this.Size = new System.Drawing.Size(, );
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 = ;
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 % == )
{
//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 % == )
{
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 % == )
{
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[].SizeType = SizeType.Absolute;
tableLayoutPanel1.ColumnStyles[].Width = Col2Width; tableLayoutPanel1.ColumnStyles[].Width = Col1Width;
tableLayoutPanel1.ColumnStyles[].Width = Col2Width;
tableLayoutPanel1.ColumnStyles[].Width = Col3Width;
tableLayoutPanel1.ColumnStyles[].Width = Col4Width;
tableLayoutPanel1.ColumnStyles[].Width = Col5Width; if (AnswerTypes == )
{
if (Score > 0.0001m)
{
int x = (int)Math.Round((( * Score) / AssignedValue)); if (x == )
{
rbA.Checked = true;
}
else if (x == )
{
rbB.Checked = true;
}
else if (x == )
{
rbC.Checked = true;
}
else if (x == )
{
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 == )
{
if (Score > 0.0001m)
{
int x = (int)Math.Round((Score / AssignedValue)); if (x == )
{
rbA.Checked = true;
}
else
{
rbB.Checked = true;
}
} if (AllowDataChanged == false)
{
rbA.Enabled = false;
rbB.Enabled = false;
}
} if (AnswerTypes == )
{
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 == )
{
if (rbA.Checked)
{
Value = ;
}
if (rbB.Checked)
{
Value = ;
}
if (rbC.Checked)
{
Value = ;
}
if (rbD.Checked)
{
Value = ;
}
if (rbE.Checked)
{
Value = ;
} Score = Value * AssignedValue / ; lbScore.Text = Score.ToString();
} if (AnswerTypes == )
{
if (rbA.Checked)
{
Value = ;
}
if (rbB.Checked)
{
Value = ;
} Score = Value * AssignedValue; lbScore.Text = Score.ToString();
} if (Value == )
{
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 == ) //default
{
return;
} if (AnswerTypes == ) // 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 == )
{
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
} TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles;
styles2[].Width = ;
} if (AnswerTypes == ) // 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 = ;
NumberB.Width = ; TableLayoutColumnStyleCollection styles = tableFlowLayoutPanelAnswer.ColumnStyles;
if (styles.Count == )
{
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
styles[].Width = ;
}
tableFlowLayoutPanelAnswer.Controls.Clear();
tableFlowLayoutPanelAnswer.Controls.Add(NumberA, , ); //NumberB.Dock = DockStyle.Right;
tableFlowLayoutPanelAnswer.Controls.Add(NumberB, , ); TableLayoutColumnStyleCollection styles2 = tableLayoutPanel1.ColumnStyles; styles2[].Width = ;
styles2[].Width = ;
styles2[].Width = ;
styles2[].Width = ; NumberB.Invalidate();
} } void NumberA_Validated(object sender, EventArgs e)
{
decimal tmp;
if (decimal.TryParse(NumberA.Text.ToString(), out tmp))
{
if (tmp < || tmp > )
{
NumberAInput = tmp;
errorProvider.SetError(NumberA, "number is out of range");
}
else
{
NumberAInput = tmp;
errorProvider.SetError(NumberA, "");
}
}
else
{
NumberAInput = ;
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 < || tmp > )
{
NumberBInput = tmp;
errorProvider.SetError(NumberB, "number is out of range");
}
else
{
NumberBInput = tmp;
errorProvider.SetError(NumberB, "");
}
}
else
{
NumberBInput = ;
errorProvider.SetError(NumberB, "Not a number");
}
} }

Usage =>

radioButtonFiveTitle1.Refresh();
radioButtonFiveTitle1.Width = + radioButtonFiveTitle1.TotalWidth;
radioButtonFiveTitle1.Col2Width = ;
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();

RadioButton Control的更多相关文章

  1. 记录ASP.NET页面表单初始状态(主要是为了前台可以根据这个判断页面是否变动了)

    把页面表单状态记录到HiddenField中. 这里只提供后台代码, 前台逻辑根据需求自由定义. 存放值的ViewState: protected Dictionary<string, stri ...

  2. asp.net遍历页面中所有TextBox,并赋值为String.Empty的方法

    本文介绍下,如何用.net遍历页面中的所有TextBox控件,并赋值为string.empty的方法,通过实例学习具体操作.有需要的朋友可以参考下.   一.遍历窗体控件 1,普通页面遍历TextBo ...

  3. MFC 控件用法

    1:IP Control 变量CIPAddressCtrl m_iAddr 关联DDX_Control(pDX,IDC_IPADDRESS1,m_iAddr); 设置地址:m_iAddr.SetAdd ...

  4. FastReport报表设计(仔细看)

    FastReport报表设计 2011-06-16 16:56:19|  分类: 系统开发|举报|字号 订阅     下载LOFTER我的照片书  |     目录 5.1 前言 5.2 基本概念及操 ...

  5. FastReport报表设计

    [转载]FastReport报表设计 (2012-10-24 20:37:26) 转载▼ 标签: 转载   原文地址:FastReport报表设计作者:小黑 FastReport报表设计 目录 5.1 ...

  6. 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

    [源码下载] 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 作者:webabcd 介绍背水一 ...

  7. cocos2dx 3.x (单选,多选,复选checkBox按钮的实现) RadioButton

    // //  LandLordsMakeNewRoom.hpp //  MalaGame39 // //  Created by work on 2016/12/19. // //   #ifndef ...

  8. 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

    1.ListBox 的示例Controls/SelectionControl/ListBoxDemo.xaml <Page x:Class="Windows10.Controls.Se ...

  9. 仿iOS Segmented Control样式"

    同步发表于http://avenwu.net/2015/02/05/styled_radiogroup_segmented_control Fork on github https://github. ...

随机推荐

  1. MapReduce应用案例--单表关联

    1. 实例描述 单表关联这个实例要求从给出的数据中寻找出所关心的数据,它是对原始数据所包含信息的挖掘. 实例中给出child-parent 表, 求出grandchild-grandparent表. ...

  2. Codeforces Round #341 (Div. 2)

    在家都变的懒惰了,好久没写题解了,补补CF 模拟 A - Wet Shark and Odd and Even #include <bits/stdc++.h> typedef long ...

  3. Robotium ant 报错Unable to find instrumentation info for: ComponentInfo{project/android.test.InstrumentationTestRunner}

    [echo] Running tests ... [exec] INSTRUMENTATION_STATUS: id=ActivityManagerService [exec] INSTRUMENTA ...

  4. C# 词法分析器(七)总结

    系列导航 (一)词法分析介绍 (二)输入缓冲和代码定位 (三)正则表达式 (四)构造 NFA (五)转换 DFA (六)构造词法分析器 (七)总结 在之前的六篇文章中,我比较详细的介绍了与词法分析器相 ...

  5. LightOJ1017 Brush (III)(DP)

    题目大概说一个平面上分布n个灰尘,现在要用一个宽w的刷子清理灰尘:选择一个起点,往水平线上扫过去这个水平线上的灰尘就消失了.问最多进行k次这样的操作能清理最多多少灰尘. 没什么的DP. 先按垂直坐标给 ...

  6. excel VLOOKUP函数的使用方法 .

    VLOOKUP函数是Excel中几个最重函数之一,为了方便大家学习,兰色幻想特针对VLOOKUP函数的使用和扩展应用,进行一次全面综合的说明.本文为入门部分 一.入门级 VLOOKUP是一个查找函数, ...

  7. Windows下安装Docker

    放在三年前,你不认识Docker情有可原,但如果现在你还这么说,不好意思,只能说明你OUT了,行动起来吧骚年,很可能你们公司或者你即将要去的公司,或者你想去的公司很可能就会引入Docker,或者已经引 ...

  8. 【HDU】1536 S-Nim

    http://acm.hdu.edu.cn/showproblem.php?pid=1536 题意:同nim...多堆多询问...单堆n<=10000,每次取的是给定集合的数= = #inclu ...

  9. 【BZOJ3223】 Tyvj 1729 文艺平衡树 Splay

    Description   您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2  ...

  10. AIX日常维护

    1  /etc/security/limits与limit命令 AIX 5.3上 下面是文件/etc/security/limits文件里面有关软限制和硬限制的部分. * * Sizes are in ...