不使用按钮。窗体内有一个手工输入用的TextBox、一个“计算”Button按钮、一个“结果”TextBox、一个显示计算步骤的RichTextBox。需求:
1、可手工在TextBox输入包含括号的加(+)、减(-)、乘(*)、除(/)的四则混合运算。
2、按“计算”Button,在“结果”TextBox中显示结果,小数点精确到后2位,未除尽需四舍五入,而不是舍去。
3、RichTextBox根据程序计算,列出每一项运算的步骤。这个和传统的计算器不同,就是没有按钮啊,只能在TextBox输入!请大家提供一个思路吧!或者直接上代码,谢谢!
1、可手工在TextBox输入包含括号的加(+)、减(-)、乘(*)、除(/)的四则混合运算。
2、按“计算”Button,在“结果”TextBox中显示结果,小数点精确到后2位,未除尽需四舍五入,而不是舍去。
3、RichTextBox根据程序计算,列出每一项运算的步骤。这个和传统的计算器不同,就是没有按钮啊,只能在TextBox输入!请大家提供一个思路吧!或者直接上代码,谢谢!
解决方案 »
- richTextBox显示数据问题求教
- C#如何调用delphi的DLL中无返回值函数
- winform ui方面资料
- [WinForm]如何捕获抛出的异常?
- notifyIcon怎么显示
- 如何取出gridview当前行中某个字段的值(急)
- treeview 设置image,我用ImageLIst ,选中的时候总是显示同一张 图片。
- 请教如何在WINFORM的DATAGRID的单元格里添加CHECKBOX或者其他控件???谢谢。。急。。
- 在一个项目下再放一个项目运行,即在一个虚拟目录下再放一个另一个项目,怎么让他运行正常
- 在C#中能不能直接使用OLE DB和ODBC,如果能用该怎么使用,如果不能,为什么?
- c# Socket中tcpListenr.stop 和直接结束监听进程有区别
- C#读取XML问题
http://www.cnblogs.com/rayrain/articles/1530646.html
http://www.codeproject.com/KB/cs/rpn_expressionparser.aspx
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Diagnostics;namespace Caculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Caculate ca = new Caculate();
ca.RegType(textBox1.Text);
ca.Compile();
IA a = ca.Create_A();
textBox2.Text = a.f().ToString() ;
}
}
public interface IA
{
int f();
} public class Caculate
{
public void RegType(string str) // 动态注册一个类型
{
StreamWriter sw = new StreamWriter("a.cs");
sw.WriteLine("public class A : Caculator.IA { public int f() { try { return " + str + "; } catch { return int.MinValue; } } } ");
sw.Close();
} // C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe
// C:\Windows\System32\cmd.exe
//在C盘根目录下 out.txt查看是否编译成功 public void Compile()//编译 下面的字符串写你的CMD 和 编译器路径
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = @"C:\Windows\System32\cmd.exe";
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
info.Arguments = @"/c C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /t:libirary " + path + @"\a.cs /r:"+ Assembly.GetExecutingAssembly().Location+@" >C:\out.txt";
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = Process.Start(info);
p.WaitForExit();
}
public IA Create_A()//创建A的对象
{
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Assembly asm = Assembly.LoadFrom(path + @"\a.dll");
IA a = asm.CreateInstance("A") as IA;
return a;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Diagnostics;namespace Caculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Caculate ca = new Caculate();
ca.RegType(textBox1.Text);
ca.Compile();
IA a = ca.Create_A();
textBox2.Text = a.f().ToString() ;
ca.UnloadAdm();
}
}
public interface IA
{
int f();
} public class Caculate:MarshalByRefObject
{
AppDomain adm;
public void RegType(string str) // 动态注册一个类型
{
StreamWriter sw = new StreamWriter("a.cs");
sw.WriteLine("public class A :System.MarshalByRefObject, Caculator.IA { public int f() { try { return " + str + "; } catch { return int.MinValue; } } } ");
sw.Close();
} // C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe
// C:\Windows\System32\cmd.exe
//在C盘根目录下 out.txt查看是否编译成功 public void Compile()//编译 下面的字符串写你的CMD 和 编译器路径
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = @"C:\Windows\System32\cmd.exe";
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
info.Arguments = @"/c C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /t:library " + path + @"\a.cs /r:"+ Assembly.GetExecutingAssembly().Location+@" >E:\out.txt";
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = Process.Start(info);
p.WaitForExit();
}
public IA Create_A()//创建A的对象
{
adm = AppDomain.CreateDomain("abc", null, new AppDomainSetup());
return adm.CreateInstanceFromAndUnwrap("a.dll", "A") as IA;
//string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
//Assembly asm = Assembly.LoadFrom(path + @"\a.dll");
//IA a = asm.CreateInstance("A") as IA;
//return a;
}
public void UnloadAdm()
{
AppDomain.Unload(adm);
}
}
}没什么问题了