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();