学了C#已经快1个月了,想做点实际的东西,请各位告诉我一些题目以及主要实现的功能.
不管谁只要说了一个题目以及一些详细的东西的,都给10分以上的分.谢谢!!!!!!!
不管谁只要说了一个题目以及一些详细的东西的,都给10分以上的分.谢谢!!!!!!!
解决方案 »
- 【急求】c#跨域调试程序
- 微软发布Sample Browser for Windows 8版:数以千计示例代码,"触手可及"
- 模拟发送按键问题
- System.NullReferenceException: 未将对象引用设置到对象的实例。 帮忙看看,谢谢了!
- 为什么总是选不中treenode节点!!??
- webbrower控件屏蔽“文件下载”对话框,自动保存到指定目录??
- RSA 数字签名异常
- 用.net2010开发的winform,如何才能生成脱机安装的setup.exe程序?
- 开发一个IP过滤软件,哪位大侠给点思路
- DataGrid存储
- DataGridView的列如何与数据源的列绑定?
- C# 修改文本文件里的内容
http://www.cnblogs.com/skyiv/archive/2007/08/21/Calc.html
一个表达式计算器,用C#写的,利用了VB编译器的强劲性能,可以计算任何合法的VB表达式,可以有一个自变量(x),也可以不要自变量。
// 编译方法: csc /t:winexe Calc.cs VBExpression.csusing System;
using System.Windows.Forms;
using Skyiv.Util;namespace Skyiv
{
class Calc : Form
{
TextBox tbxA1, tbxA2, tbxA3; Calc()
{
Text = "表达式计算器";
StartPosition = FormStartPosition.CenterScreen;
Width = 400;
Height = 200; Label lblA1 = new Label();
lblA1.Text = "表达式(&E)";
lblA1.Parent = this;
lblA1.Top = 23;
lblA1.Left = 10;
lblA1.AutoSize = true; tbxA1 = new TextBox();
tbxA1.Parent = this;
tbxA1.Top = 20;
tbxA1.Left = 80;
tbxA1.Width = 300;
tbxA1.BorderStyle = BorderStyle.FixedSingle; Label lblA2 = new Label();
lblA2.Text = "自变量(&X)";
lblA2.Parent = this;
lblA2.Top = 48;
lblA2.Left = 10;
lblA2.AutoSize = true; tbxA2 = new TextBox();
tbxA2.Parent = this;
tbxA2.Top = 45;
tbxA2.Left = 80;
tbxA2.Width = 300;
tbxA2.BorderStyle = BorderStyle.FixedSingle; Button btnA3 = new Button();
btnA3.Text = "计算(&C)";
btnA3.Parent = this;
btnA3.Top = 70;
btnA3.Left = 10;
btnA3.Width = 62;
btnA3.Click += new EventHandler(Calc_Clicked); tbxA3 = new TextBox();
tbxA3.Parent = this;
tbxA3.Top = 70;
tbxA3.Left = 80;
tbxA3.Width = 300;
tbxA3.BorderStyle = BorderStyle.FixedSingle;
tbxA3.ReadOnly = true;
TextBox tbxA4 = new TextBox();
tbxA4.Text = @"
表达式使用 Visual Baisc 语法,可带一个的自变量(x)
可使用 pi、e 等常量,sin、cos、tan、log、sqrt 等函数
例子:x * cos(x * pi / sqrt(25 * 6^4)) + log(E^10)";
tbxA4.Parent = this;
tbxA4.Top = 95;
tbxA4.Left = 10;
tbxA4.Width = 370;
tbxA4.Height = 65;
tbxA4.BorderStyle = BorderStyle.None;
tbxA4.Multiline = true;
tbxA4.ReadOnly = true;
} void Calc_Clicked(object sender, EventArgs ea)
{
(sender as Control).Enabled = false;
try
{
double x = 0;
if (tbxA2.Text.Trim().Length != 0)
{
try
{
x = double.Parse(tbxA2.Text);
}
catch
{
try
{
x = (new Expression(tbxA2.Text)).Compute(0);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "自变量出错");
}
}
}
tbxA3.Text = (new Expression(tbxA1.Text)).Compute(x).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "表达式出错");
}
finally
{
(sender as Control).Enabled = true;
}
} [STAThread]
static void Main(string [] args)
{
Application.Run(new Calc());
}
}
}
http://www.cnblogs.com/skyivben/archive/2005/10/31/265861.html// VBExpression.cs - 动态生成数学表达式并计算其值
// 表达式使用 Visual Baisc 语法,可带一个的自变量(x)
// 可使用 pi、e 等常量,sin、cos、tan、log、sqrt 等函数
// 例子:e + sqrt(log(pi ^ e) * x) + sin(x * pi / 180)using System;
using System.CodeDom.Compiler;
using Microsoft.VisualBasic;
using System.Reflection;
using System.Text;
using System.Globalization;namespace Skyiv.Util
{
sealed class Expression
{
object instance;
MethodInfo method; public Expression(string expression)
{
if (expression.ToUpper(CultureInfo.InvariantCulture).IndexOf("RETURN") < 0) expression = "Return " + expression;
string className = "Expression";
string methodName = "Compute";
CompilerParameters p = new CompilerParameters();
p.GenerateInMemory = true;
CompilerResults cr = new VBCodeProvider().CompileAssemblyFromSource
(
p,
string.Format
(
@"Option Explicit Off
Option Strict Off
Imports System, System.Math, Microsoft.VisualBasic
NotInheritable Class {0}
Public Function {1}(x As Double) As Double
{2}
End Function
End Class",
className, methodName, expression
)
);
if(cr.Errors.Count > 0)
{
string msg = "Expression(\"" + expression + "\"): \n";
foreach (CompilerError err in cr.Errors) msg += err.ToString() + "\n";
throw new Exception(msg);
}
instance = cr.CompiledAssembly.CreateInstance(className);
method = instance.GetType().GetMethod(methodName);
} public double Compute(double x)
{
return (double)method.Invoke(instance, new object [] { x });
}
}
}