| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1348 人关注过本帖
标题:[求助]求助计数器怎么做呢
只看楼主 加入收藏
xyb157
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-11-21
收藏
 问题点数:0 回复次数:8 
[求助]求助计数器怎么做呢

我要做一个计数器,可是做到这个MyNumberBox控件,
我的编写的软件就是没有这个控件,该怎么做才有呢?

大家来帮帮忙啊!

搜索更多相关主题的帖子: 计数器 控件 软件 MyNumberBox 
2006-11-26 12:47
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 

MyNumberBox   ???
你是想仿照别人的做吧?
那个应该是别人把某个控件改了一个名字而已。

要不就自己写一个控件,呵呵。


飘过~~
2006-11-26 14:23
mnfmnf
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2006-12-13
收藏
得分:0 
上面说得对哈,可能就是人家改了名字的哦!呵呵
2006-12-14 17:29
无聊的爱
Rank: 1
等 级:新手上路
帖 子:74
专家分:0
注 册:2006-12-6
收藏
得分:0 

看一下控键的属性,就有可能知道他的是什么空间了。


2006-12-15 10:12
梦幻情缘
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:769
专家分:20
注 册:2005-4-4
收藏
得分:0 
最简单的就是文件读写操作,再加一些绘图。
2006-12-15 13:07
liuhaiyan
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-12-15
收藏
得分:0 

是TextBox控件吧!
楼主!
在那里改下名(MyNumberBox)就可以了!


这是我做你,你看下吧!

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 计算器
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{

protected long iNum1;
protected char cOperator;
protected bool bNumBegins;

private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.Button btnSubstract;
private System.Windows.Forms.Button btnMultiply;
private System.Windows.Forms.Button btnDivide;
private System.Windows.Forms.Button btnEquals;
protected System.Windows.Forms.TextBox txtOutput;
private System.Windows.Forms.Button button0;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
EventHandler eh = new EventHandler(this.Numbers_Click);
button0.Click += eh;
button1.Click += eh;
button2.Click += eh;
button3.Click += eh;
button4.Click += eh;
button5.Click += eh;
button6.Click += eh;
button7.Click += eh;
button8.Click += eh;
button9.Click += eh;
eh = new EventHandler(this.Operators_Click);
btnAdd.Click += eh;
btnSubstract.Click += eh;
btnMultiply.Click += eh;
btnDivide.Click += eh;
btnEquals.Click += eh;
InitMembers();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitMembers()
{
iNum1 = 0;
cOperator = '=';
bNumBegins = true;
}
private void Numbers_Click(object sender, System.EventArgs e)
{
if(txtOutput.Text == "Error")
{
txtOutput.Text = "0";
}
try
{
long iCurrent = long.Parse(txtOutput.Text);
long i = long.Parse(((Button)sender).Text);
if(bNumBegins)
{
iCurrent = i;
bNumBegins = false;
}
else
{
checked{iCurrent = (iCurrent * 10) + i;}
}
txtOutput.Text = iCurrent.ToString();
}
catch
{

}
}

private void Operators_Click(object sender, System.EventArgs e)
{
char op = ((Button)sender).Text[0];
long iCurrent;
try
{
iCurrent = long.Parse(txtOutput.Text);
}
catch
{
txtOutput.Text = "Error";
InitMembers();
return;
}

long iResult;
try
{
switch(cOperator)
{
case '+':
checked{iResult = iNum1 + iCurrent;}
break;
case '-':
checked{iResult = iNum1 - iCurrent;}
break;
case '*':
checked{iResult = iNum1 * iCurrent;}
break;
case '/':
checked{iResult = iNum1 / iCurrent;}
break;
default:
iResult = iCurrent;
break;
}
}
catch
{

txtOutput.Text = "Error";
InitMembers();
return;
}

txtOutput.Text = iResult.ToString();
iNum1 = iResult;
bNumBegins = true;
// 保存符号
cOperator = op;
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtOutput = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.btnAdd = new System.Windows.Forms.Button();
this.btnSubstract = new System.Windows.Forms.Button();
this.btnMultiply = new System.Windows.Forms.Button();
this.btnDivide = new System.Windows.Forms.Button();
this.btnEquals = new System.Windows.Forms.Button();
this.button0 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtOutput
//
this.txtOutput.Location = new System.Drawing.Point(8, 8);
this.txtOutput.MaxLength = 19;
this.txtOutput.Name = "txtOutput";
this.txtOutput.ReadOnly = true;
this.txtOutput.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.txtOutput.Size = new System.Drawing.Size(232, 21);
this.txtOutput.TabIndex = 0;
this.txtOutput.Text = "0";
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(8, 40);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(48, 48);
this.button1.TabIndex = 1;
this.button1.Text = "1";
//
// button2
//
this.button2.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button2.Location = new System.Drawing.Point(64, 40);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(48, 48);
this.button2.TabIndex = 1;
this.button2.Text = "2";
//
// button3
//
this.button3.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button3.Location = new System.Drawing.Point(120, 40);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(48, 48);
this.button3.TabIndex = 1;
this.button3.Text = "3";
//
// button4
//
this.button4.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button4.Location = new System.Drawing.Point(8, 96);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(48, 48);
this.button4.TabIndex = 1;
this.button4.Text = "4";
//
// button5
//
this.button5.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button5.Location = new System.Drawing.Point(64, 96);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(48, 48);
this.button5.TabIndex = 1;
this.button5.Text = "5";
//
// button6
//
this.button6.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button6.Location = new System.Drawing.Point(120, 96);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(48, 48);
this.button6.TabIndex = 1;
this.button6.Text = "6";

//
// button7
//
this.button7.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button7.Location = new System.Drawing.Point(8, 152);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(48, 48);
this.button7.TabIndex = 1;
this.button7.Text = "7";
//
// button8
//
this.button8.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button8.Location = new System.Drawing.Point(64, 152);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(48, 48);
this.button8.TabIndex = 1;
this.button8.Text = "8";
//
// button9
//
this.button9.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button9.Location = new System.Drawing.Point(120, 152);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(48, 48);
this.button9.TabIndex = 1;
this.button9.Text = "9";
//
// btnAdd
//
this.btnAdd.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.btnAdd.Location = new System.Drawing.Point(176, 40);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(64, 48);
this.btnAdd.TabIndex = 1;
this.btnAdd.Text = "+";
//
// btnSubstract
//
this.btnSubstract.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.btnSubstract.Location = new System.Drawing.Point(176, 96);
this.btnSubstract.Name = "btnSubstract";
this.btnSubstract.Size = new System.Drawing.Size(64, 48);
this.btnSubstract.TabIndex = 1;
this.btnSubstract.Text = "-";
//
// btnMultiply
//
this.btnMultiply.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.btnMultiply.Location = new System.Drawing.Point(176, 152);
this.btnMultiply.Name = "btnMultiply";
this.btnMultiply.Size = new System.Drawing.Size(64, 48);
this.btnMultiply.TabIndex = 1;
this.btnMultiply.Text = "*";

//
// btnDivide
//
this.btnDivide.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.btnDivide.Location = new System.Drawing.Point(176, 208);
this.btnDivide.Name = "btnDivide";
this.btnDivide.Size = new System.Drawing.Size(64, 48);
this.btnDivide.TabIndex = 1;
this.btnDivide.Text = "/";
//
// btnEquals
//
this.btnEquals.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.btnEquals.Location = new System.Drawing.Point(64, 208);
this.btnEquals.Name = "btnEquals";
this.btnEquals.Size = new System.Drawing.Size(104, 48);
this.btnEquals.TabIndex = 1;
this.btnEquals.Text = "=";
//
// button0
//
this.button0.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button0.Location = new System.Drawing.Point(8, 208);
this.button0.Name = "button0";
this.button0.Size = new System.Drawing.Size(48, 48);
this.button0.TabIndex = 1;
this.button0.Text = "0";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(248, 270);
this.Controls.Add(this.button1);
this.Controls.Add(this.txtOutput);
this.Controls.Add(this.button2);
this.Controls.Add(this.button3);
this.Controls.Add(this.button4);
this.Controls.Add(this.button5);
this.Controls.Add(this.button6);
this.Controls.Add(this.button7);
this.Controls.Add(this.button8);
this.Controls.Add(this.button9);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.btnSubstract);
this.Controls.Add(this.btnMultiply);
this.Controls.Add(this.btnDivide);
this.Controls.Add(this.btnEquals);
this.Controls.Add(this.button0);
this.Name = "Form1";
this.Text = "计算器";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

}
}


我有我的个性!
2006-12-15 13:15
刚来
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-11-21
收藏
得分:0 
有一个小小的缺憾,没有归零按钮,好像只能通过0按钮实现归零。
2006-12-16 17:20
hhuosheng
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-9-23
收藏
得分:0 
好啊
我以前也做过啊
但我们用的是布局以及组件。

坚持到底,相信自己 忘掉昨天、珍惜今天、期待明天
2006-12-17 07:44
skyland84
Rank: 2
等 级:新手上路
威 望:4
帖 子:544
专家分:0
注 册:2006-10-9
收藏
得分:0 
我的天哪~ 你们把主要代码发上来就可以了嘛~!

决定人生~
2006-12-18 09:07
快速回复:[求助]求助计数器怎么做呢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028705 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved