Code Snippet:

  http://msdn.microsoft.com/en-us/library/z41h7fat.aspx

CodePlex.Snippets 4.0 - Visual Studio 2010 Code Snippets for C# Developers

  http://blogs.msdn.com/b/dohollan/archive/2010/07/12/codeplex-snippets-4-0-visual-studio-2010-code-snippets-for-c-developers.aspx

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的更多相关文章

  1. 使用 Code Snippet 简化 Coding

    在开发的项目的时候,你是否经常遇到需要重复编写一些类似的代码,比如是否经常会使用 for.foreach ? 在编写这两个循环语句的时候,你是一个字符一个字符敲还是使用 Visual Studio 提 ...

  2. Visual Studio 如何使用代码片段Code Snippet提高编程速度!!!

      使用Code Snippet简化Coding 在开发的项目的时候,你是否经常遇到需要重复编写一些类似的代码,比如是否经常会使用 for.foreach ? 在编写这两个循环语句的时候,你是一个字符 ...

  3. 如何创建 Code Snippet

    比如有一行自定义代码段: @property (nonatomic,copy) NSString *<#string#>; 需要添加到 Code Snippet 上,以帮助开发人员开发更便 ...

  4. 善用VS中的Code Snippet来提高开发效率

    http://www.cnblogs.com/anderslly/archive/2009/02/16/vs2008-code-snippets.html http://www.cnblogs.com ...

  5. 介绍 .Net工具Code Snippet 与 Sql Server2008工具SSMS Tools Pack

    不久前,某某在微软写了一个很酷的工具:Visual Stuido2008可视化代码片断工具,这个工具可以在http://www.codeplex.com/SnippetDesigner上免费下载,用它 ...

  6. iOS 学习笔记 七 (2015.03.29)code snippet操作

    1.code snippet 备份路径:~/Library/Developer/Xcode/UserData/CodeSnippets/

  7. 善用VS中的Code Snippet来提高开发效率 分类: C# 2015-01-22 11:06 69人阅读 评论(0) 收藏

    前言  在谈谈VS中的模板中,我介绍了如何创建项目/项模板,这种方式可以在创建项目时省却不少重复性的工作,从而提高开发效率.在创建好了项目和文件后,就得开始具体的编码了,这时又有了新的重复性工作,就是 ...

  8. Code Snippet Library

    你可以将自己常用的代码放到里面,给它命名,设置快捷键,以后想用这段代码的时候只要按快捷键,就会出现提示,直接将这段代码显示出来,十分高效. 比如我经常会用到一个动画:[UIView beginAnim ...

  9. Xcode的代码片段快捷方式-Code Snippet Library(代码片段库)

    最近换了新电脑,装上Xcode敲代码发现很多以前攒的Code Snippet忘记备份了,总结了一下Code Snippet的设置方法,且行且添加,慢慢积累吧. 如下图:   Title - Code ...

随机推荐

  1. SQL 最基本使用

    --创建表 CREATE TABLE TreeData (id INT IDENTITY(1,1) PRIMARY KEY , pid INT ) --为表添加列 ALTER TABLE treeda ...

  2. CocoaPods安装和使用教程

    Code4App 原创文章.转载请注明出处:http://code4app.com/article/cocoapods-install-usage 目录 CocoaPods是什么? 如何下载和安装Co ...

  3. 疯狂java学习笔记之面向对象(五) - 封装、继承、多态

    一.封装: 封装的概念: - 合理的隐藏:隐藏不想被外界操作的Field.方法.构造器 - 合理的暴露:一般就是希望给别人调用的方法 e.g:显示器(按键暴露出来操作,但实际的东西/细节方法被隐藏起来 ...

  4. webvnc利器-noVNC集成实战

    我们在做一个虚拟机管理平台,底层虚拟化使用KVM,我们希望在网页上操作虚拟机. 一开始用applet嵌在网页内实现webvnc,不过由于applet的在浏览器上运行安全性限制,我们需要一个新的方案.此 ...

  5. three.js 显示一个绿色的正方体

    第一个框架的效果是显示一个绿色的正方体 <!DOCTYPE html> <html> <head> <title></title> < ...

  6. SQLite错误码

    在SQLite中,执行SQL语句的sqlite3_exec()和sqlite3_prepare()两个核心方法的返回值都是一个整型数据,因此,当程序执行出现错误时,我们可以根据执行返回的整型数据来判断 ...

  7. BZOJ3072 : [Pa2012]Two Cakes

    考虑DP,设$f[i][j]$表示考虑了$a[1..i]$和$b[1..j]$的最小代价. 若$a[i]==b[j]$,则$f[i][j]=\min(f[i-1][j],f[i][j-1])+1$. ...

  8. HDU 2831 (贪心)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2831 题目大意:植物大战僵尸.给定种植植物时间间隔t,以及每个僵尸的到达时间v,生命d.问是否能赢. ...

  9. LinearLayout 垂直滚动条

    <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android=" ...

  10. BZOJ3172[Tjoi2013]单词 题解

    题目大意: 求一些字符串在一段文章中出现的次数. 思路: AC自动机的经典应用,建完自动机直接将队列里的元素调Fail指针记录即可. 代码: #include<cstdio> #inclu ...