Code Snippet
Code Snippet:
http://msdn.microsoft.com/en-us/library/z41h7fat.aspx
CodePlex.Snippets 4.0 - Visual Studio 2010 Code Snippets for C# Developers
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);
} }
}
Code Snippet的更多相关文章
- 使用 Code Snippet 简化 Coding
在开发的项目的时候,你是否经常遇到需要重复编写一些类似的代码,比如是否经常会使用 for.foreach ? 在编写这两个循环语句的时候,你是一个字符一个字符敲还是使用 Visual Studio 提 ...
- Visual Studio 如何使用代码片段Code Snippet提高编程速度!!!
使用Code Snippet简化Coding 在开发的项目的时候,你是否经常遇到需要重复编写一些类似的代码,比如是否经常会使用 for.foreach ? 在编写这两个循环语句的时候,你是一个字符 ...
- 如何创建 Code Snippet
比如有一行自定义代码段: @property (nonatomic,copy) NSString *<#string#>; 需要添加到 Code Snippet 上,以帮助开发人员开发更便 ...
- 善用VS中的Code Snippet来提高开发效率
http://www.cnblogs.com/anderslly/archive/2009/02/16/vs2008-code-snippets.html http://www.cnblogs.com ...
- 介绍 .Net工具Code Snippet 与 Sql Server2008工具SSMS Tools Pack
不久前,某某在微软写了一个很酷的工具:Visual Stuido2008可视化代码片断工具,这个工具可以在http://www.codeplex.com/SnippetDesigner上免费下载,用它 ...
- iOS 学习笔记 七 (2015.03.29)code snippet操作
1.code snippet 备份路径:~/Library/Developer/Xcode/UserData/CodeSnippets/
- 善用VS中的Code Snippet来提高开发效率 分类: C# 2015-01-22 11:06 69人阅读 评论(0) 收藏
前言 在谈谈VS中的模板中,我介绍了如何创建项目/项模板,这种方式可以在创建项目时省却不少重复性的工作,从而提高开发效率.在创建好了项目和文件后,就得开始具体的编码了,这时又有了新的重复性工作,就是 ...
- Code Snippet Library
你可以将自己常用的代码放到里面,给它命名,设置快捷键,以后想用这段代码的时候只要按快捷键,就会出现提示,直接将这段代码显示出来,十分高效. 比如我经常会用到一个动画:[UIView beginAnim ...
- Xcode的代码片段快捷方式-Code Snippet Library(代码片段库)
最近换了新电脑,装上Xcode敲代码发现很多以前攒的Code Snippet忘记备份了,总结了一下Code Snippet的设置方法,且行且添加,慢慢积累吧. 如下图: Title - Code ...
随机推荐
- iOS Xcode behaviors个人常用Debug配置
- LSM树由来、设计思想以及应用到HBase的索引
讲LSM树之前,需要提下三种基本的存储引擎,这样才能清楚LSM树的由来: 哈希存储引擎 是哈希表的持久化实现,支持增.删.改以及随机读取操作,但不支持顺序扫描,对应的存储系统为key-value存储 ...
- Modify a Stored Procedure using SQL Server Management Studio
In Object Explorer, connect to an instance of Database Engine and then expand that instance. Expand ...
- BZOJ3873 : [Ahoi2014]拼图
如果答案在某个碎片内部,那么直接悬线法解决,时间复杂度$O(n\sum)$. 如果$n$比较大,那么$\sum$比较小. 求出每个点向上能延伸的长度,枚举每个点向上这条线段作为短板. 算出完全可选的碎 ...
- PE-1 & 暴模|容斥
题意: 求1000以下3或5的倍数之和. SOL: 暴模也是兹瓷的啊... 那么就想到了初赛悲催的滚粗...容斥忘了加上多减的数了... 然后对着题...T = 3*333*(1+333)/2 + 5 ...
- float浮动问题:会造成父级元素高度坍塌;
float浮动问题:会造成父级元素高度坍塌: 解决办法:清除浮动:clear:both; 给父元素高度:height(不是很可取) 给父元素:display:inline-black:(问题:marg ...
- 【BZOJ】2086: [Poi2010]Blocks
题意 \(n(1 \le n \le 1000000)\)个数\(a_i(a_i \le 10^9)\).\(m(1 \le m \le 50)\)次询问,每次给出一个\(k(k \le 10^9)\ ...
- 【BZOJ】2333: [SCOI2011]棘手的操作
http://www.lydsy.com/JudgeOnline/problem.php?id=2333 题意: 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i], ...
- iOS 上线被拒收集
根据上线被拒的原因 自己 也在慢慢总结 希望对各位有所帮助 1)QQ 微信 等第三方平台 必须要做是否安装应用的检测
- PostgreSQL新手入门
自从MySQL被Oracle收购以后,PostgreSQL逐渐成为开源关系型数据库的首选. 本文介绍PostgreSQL的安装和基本用法,供初次使用者上手.以下内容基于Debian操作系统,其他操作系 ...