
具体代码
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace _16进制累加
{
public class Form1 : Form
{
public Form1()
{
this.InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void chaifen(string str)
{
try
{
string[] array = str.Split(new char[]
{
' '
});
int num = 0;
int num2 = 0;
while (!array[num2].Equals("#"))
{
num += Convert.ToInt32(array[num2], 16);
num2++;
}
this.richTextBox2.Text = Convert.ToString(num, 16);
bool flag = !this.radioButton1.Checked;
if (flag)
{
int num3 = int.Parse(this.textBox1.Text);
this.richTextBox2.Text = "运算结果:" + this.richTextBox2.Text.Substring(this.richTextBox2.Text.Length - num3);
}
else
{
this.richTextBox2.Text = "运算结果:" + this.richTextBox2.Text;
}
}
catch
{
MessageBox.Show("您输入的字符串格式错误", "格式错误");
}
}
private void button1_Click(object sender, EventArgs e)
{
this.chaifen(this.richTextBox1.Text + " #");
}
private void richTextBox2_TextChanged(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
this.textBox1.ReadOnly = true;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
this.textBox1.ReadOnly = false;
}
private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("作者:小杉杉\nQQ:764854759", "作者信息");
}
protected override void Dispose(bool disposing)
{
bool flag = disposing && this.components != null;
if (flag)
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(Form1));
this.button1 = new Button();
this.richTextBox1 = new RichTextBox();
this.richTextBox2 = new RichTextBox();
this.radioButton1 = new RadioButton();
this.radioButton2 = new RadioButton();
this.textBox1 = new TextBox();
this.menuStrip1 = new MenuStrip();
this.程序ToolStripMenuItem = new ToolStripMenuItem();
this.关于ToolStripMenuItem = new ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
base.SuspendLayout();
this.button1.Font = new Font("宋体", 15f);
this.button1.Location = new Point(411, 358);
this.button1.Name = "button1";
this.button1.Size = new Size(104, 80);
this.button1.TabIndex = 0;
this.button1.Text = "运算";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += this.button1_Click;
this.richTextBox1.Location = new Point(12, 30);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new Size(503, 300);
this.richTextBox1.TabIndex = 1;
this.richTextBox1.Text = "";
this.richTextBox2.Location = new Point(12, 358);
this.richTextBox2.Name = "richTextBox2";
this.richTextBox2.ReadOnly = true;
this.richTextBox2.Size = new Size(393, 80);
this.richTextBox2.TabIndex = 2;
this.richTextBox2.Text = "";
this.richTextBox2.TextChanged += this.richTextBox2_TextChanged;
this.radioButton1.AutoSize = true;
this.radioButton1.Checked = true;
this.radioButton1.Location = new Point(12, 336);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new Size(71, 16);
this.radioButton1.TabIndex = 3;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "全局截取";
this.radioButton1.UseVisualStyleBackColor = true;
this.radioButton1.CheckedChanged += this.radioButton1_CheckedChanged;
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new Point(113, 336);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new Size(83, 16);
this.radioButton2.TabIndex = 4;
this.radioButton2.Text = "截取后几位";
this.radioButton2.UseVisualStyleBackColor = true;
this.radioButton2.CheckedChanged += this.radioButton2_CheckedChanged;
this.textBox1.Location = new Point(200, 334);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new Size(60, 21);
this.textBox1.TabIndex = 5;
this.textBox1.TextAlign = HorizontalAlignment.Center;
this.menuStrip1.Items.AddRange(new ToolStripItem[]
{
this.程序ToolStripMenuItem
});
this.menuStrip1.Location = new Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new Size(527, 25);
this.menuStrip1.TabIndex = 6;
this.menuStrip1.Text = "menuStrip1";
this.程序ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[]
{
this.关于ToolStripMenuItem
});
this.程序ToolStripMenuItem.Name = "程序ToolStripMenuItem";
this.程序ToolStripMenuItem.Size = new Size(44, 21);
this.程序ToolStripMenuItem.Text = "程序";
this.关于ToolStripMenuItem.Name = "关于ToolStripMenuItem";
this.关于ToolStripMenuItem.Size = new Size(180, 22);
this.关于ToolStripMenuItem.Text = "关于";
this.关于ToolStripMenuItem.Click += this.关于ToolStripMenuItem_Click;
base.AutoScaleDimensions = new SizeF(6f, 12f);
base.AutoScaleMode = AutoScaleMode.Font;
base.ClientSize = new Size(527, 450);
base.Controls.Add(this.textBox1);
base.Controls.Add(this.radioButton2);
base.Controls.Add(this.radioButton1);
base.Controls.Add(this.richTextBox2);
base.Controls.Add(this.richTextBox1);
base.Controls.Add(this.button1);
base.Controls.Add(this.menuStrip1);
base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
base.MainMenuStrip = this.menuStrip1;
base.Name = "Form1";
base.StartPosition = FormStartPosition.CenterScreen;
this.Text = "十六进制累加器";
base.Load += this.Form1_Load;
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
base.ResumeLayout(false);
base.PerformLayout();
}
private IContainer components = null;
private Button button1;
private RichTextBox richTextBox1;
private RichTextBox richTextBox2;
private RadioButton radioButton1;
private RadioButton radioButton2;
private TextBox textBox1;
private MenuStrip menuStrip1;
private ToolStripMenuItem 程序ToolStripMenuItem;
private ToolStripMenuItem 关于ToolStripMenuItem;
}
}