修改windows计算器使其中文显示数字

看到逆向工程核心原理上用钩子修改计算器使其显示中文,自己试着不用钩子做一个显示中文的计算器,把过程写出来跟大家分享一下。

一、环境准备

1、WINDOW_XP_SP3

2、OllyDbg

3、UltraEdit

4、VS2008

二、调试过程

利用OD很容易发现,calc使用SetWindowTextW显示,该函数有两个参数,第一个参数是窗口或者空间的句柄,第二个参数是指向字符串的指针。

栈:

CallSetWindowTextW的二进制代码是 FF 15 10 11 00 01,这里地址01001110是calc的IAT表,对应的函数是SetWindowTextW。</

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
用C#编写的计算器 超详细 因为计算器设计的控件太多,不便使用控制台应用程序完成,所以这里使用Windows窗体应用程序,并命名为Calc,如下图所示: 向窗体中拖入需要的控件,如下图所示: (完成效果图) 结果显示区(作者博客左边的本框)是TextBox控件,并修改其name为txtShow ,按键0~9为Button控件,并将其name分别修改为btn_0、btn_1、btn_2、btn_3、btn_4、btn_5、btn_6、btn_7、btn_8、btn_9;按键【负数】的name值修改为btn_sign,按键【.】的name修改为btn_dot,按键【+ - * /】的name值分别修改为btn_add、btn_sub、btn_mul、btn_div,按键【=】的name值修改为btn_equ,按键【倒数】的name值修改为btn_rev,按键【平方】的name值修改为btn_sqr,按键【开方】的name值修改为btn_sqrt。右边的计算器图片空间是PictureBox,作者博客控件是LinkLabel,可以不添加,以上所有控件均可按照需求添加,只保留自己需要的按钮控件和textbox控件即可。 代码部分(含解释),采用switch多分支语句编写 using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Calc { /// <summary> /// QQ:479340056 温柔一刀C#简易计算器实现 /// </summary> public class CalcForm : System.Windows.Forms.Form { private System.Windows.Forms.Button btn_0; private System.Windows.Forms.Button btn_1; private System.Windows.Forms.Button btn_2; private System.Windows.Forms.Button btn_3; private System.Windows.Forms.Button btn_4; private System.Windows.Forms.Button btn_5; private System.Windows.Forms.Button btn_6; private System.Windows.Forms.Button btn_7; private System.Windows.Forms.Button btn_8; private System.Windows.Forms.Button btn_9; private System.Windows.Forms.Button btn_add; private System.Windows.Forms.Button btn_sub; private System.Windows.Forms.Button btn_mul; private System.Windows.Forms.Button btn_div; private System.Windows.Forms.Button btn_sqrt; private System.Windows.Forms.Button btn_sign; private System.Windows.Forms.Button btn_equ; private System.Windows.Forms.Button btn_dot; private System.Windows.Forms.Button btn_rev; private System.Windows.Forms.TextBox txtShow; private System.Windows.Forms.Button btn_sqr; private PictureBox pictureBox1; private LinkLabel linkLabel1; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public CalcForm() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法- 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CalcForm)); this.btn_9 = new System.Windows.Forms.Button(); this.txtShow = new System.Windows.Forms.TextBox(); this.btn_8 = new System.Windows.Forms.Button(); this.btn_7 = new System.Windows.Forms.Button(); this.btn_div = new System.Windows.Forms.Button(); this.btn_sqrt = new System.Windows.Forms.Button(); this.btn_4 = new System.Windows.Forms.Button(); this.btn_5 = new System.Windows.Forms.Button(); this.btn_6 = new System.Windows.Forms.Button(); this.btn_1 = new System.Windows.Forms.Button(); this.btn_2 = new System.Windows.Forms.Button(); this.btn_3 = new System.Windows.Forms.Button(); this.btn_0 = new System.Windows.Forms.Button(); this.btn_mul = new System.Windows.Forms.Button(); this.btn_sub = new System.Windows.Forms.Button(); this.btn_sign = new System.Windows.Forms.Button(); this.btn_equ = new System.Windows.Forms.Button(); this.btn_add = new System.Windows.Forms.Button(); this.btn_dot = new System.Windows.Forms.Button(); this.btn_sqr = new System.Windows.Forms.Button(); this.btn_rev = new System.Windows.Forms.Button(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // btn_9 // this.btn_9.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_9.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_9.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_9.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_9.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_9.ForeColor = System.Drawing.Color.Black; this.btn_9.Location = new System.Drawing.Point(126, 37); this.btn_9.Name = "btn_9"; this.btn_9.Size = new System.Drawing.Size(59, 31); this.btn_9.TabIndex = 0; this.btn_9.Tag = "9"; this.btn_9.Text = "9"; this.btn_9.UseVisualStyleBackColor = false; this.btn_9.Click += new System.EventHandler(this.btn_0_Click); // // txtShow // this.txtShow.Location = new System.Drawing.Point(4, 6); this.txtShow.Name = "txtShow"; this.txtShow.ReadOnly = true; this.txtShow.Size = new System.Drawing.Size(242, 21); this.txtShow.TabIndex = 1; this.txtShow.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // // btn_8 // this.btn_8.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_8.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_8.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_8.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_8.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_8.ForeColor = System.Drawing.Color.Black; this.btn_8.Location = new System.Drawing.Point(66, 37); this.btn_8.Name = "btn_8"; this.btn_8.Size = new System.Drawing.Size(59, 31); this.btn_8.TabIndex = 2; this.btn_8.Tag = "8"; this.btn_8.Text = "8"; this.btn_8.UseVisualStyleBackColor = false; this.btn_8.Click += new System.EventHandler(this.btn_0_Click); // // btn_7 // this.btn_7.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_7.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_7.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_7.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_7.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_7.ForeColor = System.Drawing.Color.Black; this.btn_7.Location = new System.Drawing.Point(4, 37); this.btn_7.Name = "btn_7"; this.btn_7.Size = new System.Drawing.Size(59, 31); this.btn_7.TabIndex = 3; this.btn_7.Tag = "7"; this.btn_7.Text = "7"; this.btn_7.UseVisualStyleBackColor = false; this.btn_7.Click += new System.EventHandler(this.btn_0_Click); // // btn_div // this.btn_div.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_div.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_div.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_div.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_div.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_div.ForeColor = System.Drawing.Color.Red; this.btn_div.Location = new System.Drawing.Point(187, 37); this.btn_div.Name = "btn_div"; this.btn_div.Size = new System.Drawing.Size(59, 31); this.btn_div.TabIndex = 4; this.btn_div.Text = "/"; this.btn_div.UseVisualStyleBackColor = false; this.btn_div.Click += new System.EventHandler(this.btn_div_Click); // // btn_sqrt // this.btn_sqrt.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_sqrt.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_sqrt.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_sqrt.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_sqrt.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_sqrt.ForeColor = System.Drawing.Color.Black; this.btn_sqrt.Location = new System.Drawing.Point(253, 37); this.btn_sqrt.Name = "btn_sqrt"; this.btn_sqrt.Size = new System.Drawing.Size(59, 31); this.btn_sqrt.TabIndex = 5; this.btn_sqrt.Text = "开方"; this.btn_sqrt.UseVisualStyleBackColor = false; this.btn_sqrt.Click += new System.EventHandler(this.btn_sqrt_Click); // // btn_4 // this.btn_4.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_4.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_4.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_4.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_4.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_4.ForeColor = System.Drawing.Color.Black; this.btn_4.Location = new System.Drawing.Point(4, 72); this.btn_4.Name = "btn_4"; this.btn_4.Size = new System.Drawing.Size(59, 31); this.btn_4.TabIndex = 6; this.btn_4.Tag = "4"; this.btn_4.Text = "4"; this.btn_4.UseVisualStyleBackColor = false; this.btn_4.Click += new System.EventHandler(this.btn_0_Click); // // btn_5 // this.btn_5.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_5.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_5.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_5.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_5.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_5.ForeColor = System.Drawing.Color.Black; this.btn_5.Location = new System.Drawing.Point(66, 72); this.btn_5.Name = "btn_5"; this.btn_5.Size = new System.Drawing.Size(59, 31); this.btn_5.TabIndex = 7; this.btn_5.Tag = "5"; this.btn_5.Text = "5"; this.btn_5.UseVisualStyleBackColor = false; this.btn_5.Click += new System.EventHandler(this.btn_0_Click); // // btn_6 // this.btn_6.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_6.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_6.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_6.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_6.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_6.ForeColor = System.Drawing.Color.Black; this.btn_6.Location = new System.Drawing.Point(126, 72); this.btn_6.Name = "btn_6"; this.btn_6.Size = new System.Drawing.Size(59, 31); this.btn_6.TabIndex = 8; this.btn_6.Tag = "6"; this.btn_6.Text = "6"; this.btn_6.UseVisualStyleBackColor = false; this.btn_6.Click += new System.EventHandler(this.btn_0_Click); // // btn_1 // this.btn_1.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_1.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_1.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_1.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_1.ForeColor = System.Drawing.Color.Black; this.btn_1.Location = new System.Drawing.Point(4, 108); this.btn_1.Name = "btn_1"; this.btn_1.Size = new System.Drawing.Size(59, 31); this.btn_1.TabIndex = 9; this.btn_1.Tag = "1"; this.btn_1.Text = "1"; this.btn_1.UseVisualStyleBackColor = false; this.btn_1.Click += new System.EventHandler(this.btn_0_Click); // // btn_2 // this.btn_2.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_2.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_2.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_2.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_2.ForeColor = System.Drawing.Color.Black; this.btn_2.Location = new System.Drawing.Point(66, 108); this.btn_2.Name = "btn_2"; this.btn_2.Size = new System.Drawing.Size(59, 31); this.btn_2.TabIndex = 10; this.btn_2.Tag = "2"; this.btn_2.Text = "2"; this.btn_2.UseVisualStyleBackColor = false; this.btn_2.Click += new System.EventHandler(this.btn_0_Click); // // btn_3 // this.btn_3.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_3.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_3.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_3.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_3.ForeColor = System.Drawing.Color.Black; this.btn_3.Location = new System.Drawing.Point(126, 108); this.btn_3.Name = "btn_3"; this.btn_3.Size = new System.Drawing.Size(59, 31); this.btn_3.TabIndex = 11; this.btn_3.Tag = "3"; this.btn_3.Text = "3"; this.btn_3.UseVisualStyleBackColor = false; this.btn_3.Click += new System.EventHandler(this.btn_0_Click); // // btn_0 // this.btn_0.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_0.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_0.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_0.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_0.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_0.ForeColor = System.Drawing.Color.Black; this.btn_0.Location = new System.Drawing.Point(4, 143); this.btn_0.Name = "btn_0"; this.btn_0.Size = new System.Drawing.Size(59, 31); this.btn_0.TabIndex = 12; this.btn_0.Tag = "0"; this.btn_0.Text = "0"; this.btn_0.UseVisualStyleBackColor = false; this.btn_0.Click += new System.EventHandler(this.btn_0_Click); // // btn_mul // this.btn_mul.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_mul.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_mul.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_mul.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_mul.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_mul.ForeColor = System.Drawing.Color.Red; this.btn_mul.Location = new System.Drawing.Point(187, 72); this.btn_mul.Name = "btn_mul"; this.btn_mul.Size = new System.Drawing.Size(59, 31); this.btn_mul.TabIndex = 13; this.btn_mul.Text = "*"; this.btn_mul.UseVisualStyleBackColor = false; this.btn_mul.Click += new System.EventHandler(this.btn_mul_Click); // // btn_sub // this.btn_sub.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_sub.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_sub.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_sub.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_sub.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_sub.ForeColor = System.Drawing.Color.Red; this.btn_sub.Location = new System.Drawing.Point(187, 108); this.btn_sub.Name = "btn_sub"; this.btn_sub.Size = new System.Drawing.Size(59, 31); this.btn_sub.TabIndex = 14; this.btn_sub.Text = "-"; this.btn_sub.UseVisualStyleBackColor = false; this.btn_sub.Click += new System.EventHandler(this.btn_sub_Click); // // btn_sign // this.btn_sign.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_sign.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_sign.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_sign.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_sign.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_sign.ForeColor = System.Drawing.Color.Red; this.btn_sign.Location = new System.Drawing.Point(66, 143); this.btn_sign.Name = "btn_sign"; this.btn_sign.Size = new System.Drawing.Size(59, 31); this.btn_sign.TabIndex = 15; this.btn_sign.Text = "负数"; this.btn_sign.UseVisualStyleBackColor = false; this.btn_sign.Click += new System.EventHandler(this.btn_sign_Click); // // btn_equ // this.btn_equ.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_equ.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_equ.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_equ.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_equ.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_equ.ForeColor = System.Drawing.Color.Red; this.btn_equ.Location = new System.Drawing.Point(253, 143); this.btn_equ.Name = "btn_equ"; this.btn_equ.Size = new System.Drawing.Size(59, 31); this.btn_equ.TabIndex = 16; this.btn_equ.Text = "="; this.btn_equ.UseVisualStyleBackColor = false; this.btn_equ.Click += new System.EventHandler(this.btn_equ_Click); // // btn_add // this.btn_add.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_add.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_add.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_add.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_add.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_add.ForeColor = System.Drawing.Color.Red; this.btn_add.Location = new System.Drawing.Point(187, 143); this.btn_add.Name = "btn_add"; this.btn_add.Size = new System.Drawing.Size(59, 31); this.btn_add.TabIndex = 17; this.btn_add.Text = "+"; this.btn_add.UseVisualStyleBackColor = false; this.btn_add.Click += new System.EventHandler(this.btn_add_Click); // // btn_dot // this.btn_dot.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_dot.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_dot.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_dot.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_dot.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_dot.ForeColor = System.Drawing.Color.Black; this.btn_dot.Location = new System.Drawing.Point(126, 143); this.btn_dot.Name = "btn_dot"; this.btn_dot.Size = new System.Drawing.Size(59, 31); this.btn_dot.TabIndex = 18; this.btn_dot.Text = "."; this.btn_dot.UseVisualStyleBackColor = false; this.btn_dot.Click += new System.EventHandler(this.btn_dot_Click); // // btn_sqr // this.btn_sqr.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_sqr.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_sqr.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_sqr.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_sqr.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_sqr.ForeColor = System.Drawing.Color.Black; this.btn_sqr.Location = new System.Drawing.Point(253, 72); this.btn_sqr.Name = "btn_sqr"; this.btn_sqr.Size = new System.Drawing.Size(59, 31); this.btn_sqr.TabIndex = 19; this.btn_sqr.Text = "平方"; this.btn_sqr.UseVisualStyleBackColor = false; this.btn_sqr.Click += new System.EventHandler(this.btn_sqr_Click); // // btn_rev // this.btn_rev.BackColor = System.Drawing.SystemColors.ActiveBorder; this.btn_rev.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btn_rev.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_rev.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_rev.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_rev.ForeColor = System.Drawing.Color.Red; this.btn_rev.Location = new System.Drawing.Point(253, 108); this.btn_rev.Name = "btn_rev"; this.btn_rev.Size = new System.Drawing.Size(59, 31); this.btn_rev.TabIndex = 20; this.btn_rev.Text = "倒数"; this.btn_rev.UseVisualStyleBackColor = false; this.btn_rev.Click += new System.EventHandler(this.btn_rev_Click); // // pictureBox1 // this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); this.pictureBox1.Location = new System.Drawing.Point(319, 6); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(100, 168); this.pictureBox1.TabIndex = 21; this.pictureBox1.TabStop = false; // // linkLabel1 // this.linkLabel1.AutoSize = true; this.linkLabel1.Location = new System.Drawing.Point(253, 13); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.Size = new System.Drawing.Size(53, 12); this.linkLabel1.TabIndex = 22; this.linkLabel1.TabStop = true; this.linkLabel1.Text = "作者博客"; this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); // // CalcForm // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(427, 181); this.Controls.Add(this.linkLabel1); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.btn_rev); this.Controls.Add(this.btn_sqr); this.Controls.Add(this.btn_dot); this.Controls.Add(this.btn_add); this.Controls.Add(this.btn_equ); this.Controls.Add(this.btn_sign); this.Controls.Add(this.btn_sub); this.Controls.Add(this.btn_mul); this.Controls.Add(this.btn_0); this.Controls.Add(this.btn_3); this.Controls.Add(this.btn_2); this.Controls.Add(this.btn_1); this.Controls.Add(this.btn_6); this.Controls.Add(this.btn_5); this.Controls.Add(this.btn_4); this.Controls.Add(this.btn_sqrt); this.Controls.Add(this.btn_div); this.Controls.Add(this.btn_7); this.Controls.Add(this.btn_8); this.Controls.Add(this.txtShow); this.Controls.Add(this.btn_9); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.Name = "CalcForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "C#编写计算器by QQ:479340056 "; this.Load += new System.EventHandler(this.CalcForm_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion public const int NULL = 0; // 定义操作码 public const int ADD = 1; public const int SUB = 2; public const int MUL = 3; public const int DIV = 4; public const int SQR = 5; public const int SQRT = 6; public const int NODOT = 0; // 定义是否点击了小数点 public const int HASDOT = 1; private double res = 0; // 记录结果数 private double tmp = 0; // 当前输入的操作数 private int opt = NULL; // 记录操作码 private int dot = NODOT; // 记录是否点击了小数点 private int num = 0; // 记录输入操作数的个数 private int dotnum = 0; // 记录小数点部分的个数 /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new CalcForm()); } /// <summary> /// 当点击一个数字按钮的时候,需要进行判断,如果没有点击 /// 小数点,那么就把原来的数值扩大倍后再加上当前的数值, /// 如果点击了小数点,那么就将当前的数值除以一个权数,再 /// 加上原来的数值,得到新的数值。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_0_Click(object sender, System.EventArgs e) { System.Windows.Forms.Button btnTmp; double i; btnTmp = sender as System.Windows.Forms.Button; if (btnTmp != null) { if (dot == NODOT) { // 没有点击小数点 i = double.Parse(btnTmp.Tag.ToString()); tmp = tmp * 10 + i; txtShow.Text = tmp.ToString(); } else { // 点击了小数点 dotnum++; // 生成小数部分的新的数值 i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum); tmp = tmp + i; txtShow.Text = tmp.ToString(); } } } private void btn_equ_Click(object sender, System.EventArgs e) { // 生成结果 if (num == 0) { res = 0; tmp = 0; txtShow.Text = res.ToString(); return; } switch (opt) { // 加法 case ADD: res = res + tmp; break; // 减法 case SUB: res = res - tmp; break; // 乘法 case MUL: res = res * tmp; break; // 除法 case DIV: res = res / tmp; break; // 平方 case SQR: res = tmp * tmp; break; // 平方根 case SQRT: res = System.Math.Sqrt(tmp); break; default: return; } txtShow.Text = res.ToString(); opt = NULL; res = 0; num = 0; } private void btn_div_Click(object sender, System.EventArgs e) { // 除法运算 opt = DIV; if (num != 0) { if (tmp != 0) res = res / tmp; } else res = tmp; num++; tmp = 0; txtShow.Text = res.ToString(); } private void btn_mul_Click(object sender, System.EventArgs e) { // 乘法运算 opt = MUL; if (num != 0) res = res * tmp; else res = tmp; num++; tmp = 0; txtShow.Text = res.ToString(); } private void btn_sub_Click(object sender, System.EventArgs e) { // 减法运算 opt = SUB; if (num != 0) res = res - tmp; else res = tmp; num++; tmp = 0; txtShow.Text = res.ToString(); } private void btn_add_Click(object sender, System.EventArgs e) { // 加法运算 opt = ADD; if (num != 0) res = res + tmp; else res = tmp; num++; tmp = 0; txtShow.Text = res.ToString(); } private void btn_sqrt_Click(object sender, System.EventArgs e) { // 开方运算 if (tmp > 0) { tmp = Math.Sqrt(tmp); txtShow.Text = tmp.ToString(); } } private void btn_sqr_Click(object sender, System.EventArgs e) { // 平方运算 tmp = tmp * tmp; txtShow.Text = tmp.ToString(); } private void btn_rev_Click(object sender, System.EventArgs e) { // 求倒数运算 tmp = 1 / tmp; txtShow.Text = tmp.ToString(); } private void btn_dot_Click(object sender, System.EventArgs e) { // 点击了小数点 dot = HASDOT; dotnum = 0; } private void btn_sign_Click(object sender, System.EventArgs e) { // 点击了符号运算 tmp = -tmp; txtShow.Text = tmp.ToString(); } private void CalcForm_Load(object sender, EventArgs e) { } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://479340056.qzone.qq.com"); } } } 说明 这里只提供了一种方法,另外以上代码中有很多是用于字体颜色设置,可以精简掉,很容易分辨 。 linkLabel1单击打开网页的事件 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://479340056.qzone.qq.com"); } 是一般用不到的。 尽量不要直接粘贴代码到Form1.cs,自己动手,丰衣足食···
软件介绍: 科学计算器软件是一款真实的计算器界面,真正的绿色软件不需安装,一个件集全部功能于一身,不占用系统资源。    中语音提示,键盘与鼠标操作,操作方式与现实生活中普遍使用的计算器完全相同,所以非常容易上手,尤其对经常使用小键盘数字输入的用户来说更加方便。省去了以前一边看电脑屏幕一边看计算器的尴尬。显示数字可随时转换为下列形式进行计算:十六进制、十进制、八进制、二进制、人民币中大写形式、人民币数字形式。以上各种转换与计算结果可选择是否自动存入WINDOWS剪贴板,并可自动输出在其它程序窗口的当前光标位置,省去了按"Ctrl V"的不便,方便用户使用。还可以随时抓取其它程序窗口中选中的公式或数据来参加计算。如果觉得计算器覆盖了屏幕显示的内容,可用鼠标单击液晶屏幕转为小窗口方式,小窗口可任意拖放,并可自动吸附在屏幕边缘,再次单击鼠标可恢复原状,非常方便。该计算器可进行多种科学与逻辑运算、公式运算、个人所得税计算、各种单位换算,增加了各种常用常数表,加入了角度与弧度计算,功能非常强大,是工程建筑、科学计算、理财等各方面应用的得力助手!对程序设计和游戏修改也有不错的作用注意:鼠标单击液晶屏幕转为小窗口方式,小窗口可任意拖放,在此方式下只能用键盘输入,再次单击鼠标可恢复原状。键盘操作说明:"1,2,3,4,5,6,7,8,9,0"为相应数字按钮。" ,-,. ,*,/"为相应运算按钮。Ctrl " 、-、*、/"为存储加、减、乘、除。Ctrl "C"为存储清除。Ctrl "R或回车"为存储显示。Ctrl "S"为存储。"[ ,]"为左、右位移操作。"←"为退格键。"F1"为软件帮助!"Esc,PageDown"为归零。"End"为清除。"Enter"为"="号按钮。"Esc"为关闭计算器
Advanced Date Time Calculator(高级日期时间计算器)是一个全功能的日期时间计算器,集多种实用的功能于一身,时间计算,纪念日,统计天数,时间换算等功能。原价29.99美元。Advanced Date Time Calculator 属于一款在 Windows 平台下的时间计算器,拥有多种实用的功能于一身,该软件支持英,繁体与简体中。与 PDF to X 同属于一个优秀的开发商。 Advanced Date Time Calculator(高级日期时间计算器)Advanced Date Time Calculator(高级日期时间计算器) 其中包含6个主要功能: 计算结果日期时间方法是在基准时间内添加/减去几年,几个月,几周,几天,几小时,几分钟和/或几秒钟,例如:通过添加3.29年,1.8周和982秒得到结果时间当前时间。还支持添加/减少工作日/周末的某些日期以获得目标日期。 计算两次之间的差异(年,月,周,天,小时,分钟,秒和综合差),通常用于计算过去/未来事件的年/月/周/天/小时/分计数根据当前的日期时间,例如出生,结婚和周年纪念。因此,它已经将开始日期和结束日期时间初始化为您当前的日期时间,只需更改一个日期时间以根据当前日期来计算过去/未来事件的年/月/周/日/小时/分钟/秒例如:你可以很快得到“你活着多少秒/天”。 统计两个日期之间的星期几,星期几,星期几,轻松获得1981年1月29日至1981年10月14日之间的一周的日子。 获取各种日期时间元素(日,年,月,周,分,秒,小时)之间的转换,使用此工具,您可以轻松快速地了解某些时间转换问题的答案,例如“一年”。 比较基准时区和其他四个特殊时区之间的指定时间,并列出指定基准时间内全球所有时区的时间。 计算从UNIX基准日期(1970年1月1日)开始传送的大日/秒数字所指示的确切日期,或者通过指定一般日期(例如,日期)来获得相应的UNIX / Linux日/秒数。 2012年7月30日为15,551天。 以上所有结果都会在更改任何条件后立即显示出来,无需点击任何按钮,如<计算>,<计数>。 此外,它支持所有数字字段(年,月,周,日,小时,分钟,秒,星期几,平日和周末)中的千位分隔符和小数位。
好的,我明白了。你可以使用JavaFX的图形用户界面库来构建计算器实现基本的算术运算。以下是实现的步骤: 1. 创建一个JavaFX项目并添加所需的库件。 2. 创建一个Calculator类,该类包含GUI组件和处理计算逻辑的方法。 3. 在Calculator类中创建一个布局,包括本框和按钮。 4. 为每个按钮添加事件处理程序,以便在单击按钮时执行相应的操作。 5. 创建一个计算方法,该方法接受两个数和一个运算操作符,并返回结果。 6. 在事件处理程序中调用计算方法,并将结果显示本框中。 以下是一个简单的实现示例: ```java import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class Calculator extends Application { private TextField textField; private double num1 = 0; private double num2 = 0; private String operator = ""; @Override public void start(Stage primaryStage) throws Exception { GridPane gridPane = new GridPane(); gridPane.setPadding(new Insets(20)); gridPane.setHgap(10); gridPane.setVgap(10); textField = new TextField(); textField.setEditable(false); textField.setPrefWidth(200); gridPane.add(textField, 0, 0, 4, 1); Button button1 = new Button("1"); button1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(textField.getText() + "1"); } }); gridPane.add(button1, 0, 1); Button button2 = new Button("2"); button2.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(textField.getText() + "2"); } }); gridPane.add(button2, 1, 1); Button button3 = new Button("3"); button3.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(textField.getText() + "3"); } }); gridPane.add(button3, 2, 1); Button buttonAdd = new Button("+"); buttonAdd.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { num1 = Double.parseDouble(textField.getText()); operator = "+"; textField.setText(""); } }); gridPane.add(buttonAdd, 3, 1); Button button4 = new Button("4"); button4.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(textField.getText() + "4"); } }); gridPane.add(button4, 0, 2); Button button5 = new Button("5"); button5.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(textField.getText() + "5"); } }); gridPane.add(button5, 1, 2); Button button6 = new Button("6"); button6.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(textField.getText() + "6"); } }); gridPane.add(button6, 2, 2); Button buttonSubtract = new Button("-"); buttonSubtract.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { num1 = Double.parseDouble(textField.getText()); operator = "-"; textField.setText(""); } }); gridPane.add(buttonSubtract, 3, 2); Button button7 = new Button("7"); button7.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(textField.getText() + "7"); } }); gridPane.add(button7, 0, 3); Button button8 = new Button("8"); button8.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(textField.getText() + "8"); } }); gridPane.add(button8, 1, 3); Button button9 = new Button("9"); button9.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(textField.getText() + "9"); } }); gridPane.add(button9, 2, 3); Button buttonMultiply = new Button("*"); buttonMultiply.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { num1 = Double.parseDouble(textField.getText()); operator = "*"; textField.setText(""); } }); gridPane.add(buttonMultiply, 3, 3); Button buttonClear = new Button("C"); buttonClear.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(""); num1 = 0; num2 = 0; operator = ""; } }); gridPane.add(buttonClear, 0, 4); Button button0 = new Button("0"); button0.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textField.setText(textField.getText() + "0"); } }); gridPane.add(button0, 1, 4); Button buttonEquals = new Button("="); buttonEquals.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { num2 = Double.parseDouble(textField.getText()); double result = calculate(num1, num2, operator); textField.setText(Double.toString(result)); num1 = result; num2 = 0; operator = ""; } }); gridPane.add(buttonEquals, 2, 4); Button buttonDivide = new Button("/"); buttonDivide.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { num1 = Double.parseDouble(textField.getText()); operator = "/"; textField.setText(""); } }); gridPane.add(buttonDivide, 3, 4); Scene scene = new Scene(gridPane, 250, 200); primaryStage.setScene(scene); primaryStage.setTitle("Calculator"); primaryStage.show(); } private double calculate(double num1, double num2, String operator) { switch (operator) { case "+": return num1 + num2; case "-": return num1 - num2; case "*": return num1 * num2; case "/": return num1 / num2; default: return 0; } } public static void main(String[] args) { launch(args); } } ``` 这个计算器可以执行基本的加、减、乘、除运算,并且具有清除、等于和数字键的功能。你可以根据自己的需要对其进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值