Dim s%, a%, b%
s = Val(Text1.Text)
a = Val(Text2.Text)
b = s - 105
If a >(1.1 * b) Then
Label3.Caption = "偏胖,加强锻炼雹旅,注意节食"
ElseIf a <(0.9 * b) Then
Label3.Caption = "偏瘦,增加备信营养"
Else
Label3.Caption = "正常,继续维持"
End If
End Sub
Private Sub Form_Load()
Text1.MaxLength = 3
Text2.MaxLength = 3
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <>8 And (KeyAscii <48 Or KeyAscii >57) Then
KeyAscii = 0
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii <>8 And (KeyAscii <48 Or KeyAscii >57) Then
KeyAscii = 0
End If
End Sub
根据我做仿肆轮的一定对的,我调试过的,不过要看仔细,有些分号这种标点也是很致命的哦
界面代码如下:
namespace HealthScale
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// 枯腔闭<param name="disposing">没裂如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose()
}
base.Dispose(disposing)
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label()
this.label2 = new System.Windows.Forms.Label()
this.txtHeight = new System.Windows.Forms.TextBox()
this.txtWeight = new System.Windows.Forms.TextBox()
this.btnOK = new System.Windows.Forms.Button()
this.btnCancel = new System.Windows.Forms.Button()
this.label3 = new System.Windows.Forms.Label()
this.label4 = new System.Windows.Forms.Label()
this.SuspendLayout()
//
// label1
//
this.label1.AutoSize = true
this.label1.Location = new System.Drawing.Point(33, 37)
this.label1.Name = "label1"
this.label1.Size = new System.Drawing.Size(29, 12)
this.label1.TabIndex = 0
this.label1.Text = "身高"
//
// label2
//
this.label2.AutoSize = true
this.label2.Location = new System.Drawing.Point(33, 87)
this.label2.Name = "label2"圆埋
this.label2.Size = new System.Drawing.Size(29, 12)
this.label2.TabIndex = 1
this.label2.Text = "体重"
//
// txtHeight
//
this.txtHeight.Location = new System.Drawing.Point(80, 34)
this.txtHeight.MaxLength = 6
this.txtHeight.Name = "txtHeight"
this.txtHeight.Size = new System.Drawing.Size(143, 21)
this.txtHeight.TabIndex = 2
this.txtHeight.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtHeight_KeyPress)
//
// txtWeight
//
this.txtWeight.Location = new System.Drawing.Point(80, 84)
this.txtWeight.MaxLength = 6
this.txtWeight.Name = "txtWeight"
this.txtWeight.Size = new System.Drawing.Size(143, 21)
this.txtWeight.TabIndex = 3
this.txtWeight.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtWeight_KeyPress)
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(40, 144)
this.btnOK.Name = "btnOK"
this.btnOK.Size = new System.Drawing.Size(75, 23)
this.btnOK.TabIndex = 4
this.btnOK.Text = "健康状况"
this.btnOK.UseVisualStyleBackColor = true
this.btnOK.Click += new System.EventHandler(this.btnOK_Click)
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(148, 144)
this.btnCancel.Name = "btnCancel"
this.btnCancel.Size = new System.Drawing.Size(75, 23)
this.btnCancel.TabIndex = 5
this.btnCancel.Text = "结束"
this.btnCancel.UseVisualStyleBackColor = true
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click)
//
// label3
//
this.label3.AutoSize = true
this.label3.Location = new System.Drawing.Point(229, 37)
this.label3.Name = "label3"
this.label3.Size = new System.Drawing.Size(17, 12)
this.label3.TabIndex = 6
this.label3.Text = "cm"
//
// label4
//
this.label4.AutoSize = true
this.label4.Location = new System.Drawing.Point(229, 87)
this.label4.Name = "label4"
this.label4.Size = new System.Drawing.Size(17, 12)
this.label4.TabIndex = 7
this.label4.Text = "kg"
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F)
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
this.ClientSize = new System.Drawing.Size(292, 213)
this.Controls.Add(this.label4)
this.Controls.Add(this.label3)
this.Controls.Add(this.btnCancel)
this.Controls.Add(this.btnOK)
this.Controls.Add(this.txtWeight)
this.Controls.Add(this.txtHeight)
this.Controls.Add(this.label2)
this.Controls.Add(this.label1)
this.Name = "Form1"
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
this.Text = "健康秤"
this.Load += new System.EventHandler(this.Form1_Load)
this.ResumeLayout(false)
this.PerformLayout()
}
#endregion
private System.Windows.Forms.Label label1
private System.Windows.Forms.Label label2
private System.Windows.Forms.TextBox txtHeight
private System.Windows.Forms.TextBox txtWeight
private System.Windows.Forms.Button btnOK
private System.Windows.Forms.Button btnCancel
private System.Windows.Forms.Label label3
private System.Windows.Forms.Label label4
}
}
后台处理代码如下:
using System
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.Text.RegularExpressions
namespace HealthScale
{
public partial class Form1 : Form
{
//正则表达式
private Regex regex
public Form1()
{
InitializeComponent()
}
private void Form1_Load(object sender, EventArgs e)
{
//初始化正则表达式,判断是否为数字
regex = new Regex(@"^\d+\.{0,1}\d*$")
}
/// <summary>
/// 健康状况按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOK_Click(object sender, EventArgs e)
{
//判断是否为空
if (String.IsNullOrEmpty(txtHeight.Text))
{
MessageBox.Show(this, "请输入身高", "健康秤", MessageBoxButtons.OK, MessageBoxIcon.Information)
return
}
if (String.IsNullOrEmpty(txtWeight.Text))
{
MessageBox.Show(this, "请输入体重", "健康秤", MessageBoxButtons.OK, MessageBoxIcon.Information)
return
}
//获取身高体重
float height = float.Parse(txtHeight.Text)
float weight = float.Parse(txtWeight.Text)
//判断体重范围给出结果
if (weight > (height - 105) * 1.1)
{
MessageBox.Show(this, "偏胖,注意节食", "健康秤", MessageBoxButtons.OK, MessageBoxIcon.Information)
}
else if (weight < (height - 105) * 0.9)
{
MessageBox.Show(this, "偏瘦,增加营养", "健康秤", MessageBoxButtons.OK, MessageBoxIcon.Information)
}
else
{
MessageBox.Show(this, "正常,继续保持", "健康秤", MessageBoxButtons.OK, MessageBoxIcon.Information)
}
}
/// <summary>
/// 结束按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close()
}
/// <summary>
/// 身高文本框键盘按下
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtHeight_KeyPress(object sender, KeyPressEventArgs e)
{
//如果不是数字并且不是退格键
if (!regex.IsMatch(txtHeight.Text + e.KeyChar.ToString()) && e.KeyChar != (char)Keys.Back)
{
MessageBox.Show(this, "非法字符", "健康秤", MessageBoxButtons.OK, MessageBoxIcon.Information)
e.Handled = true
}
}
/// <summary>
/// 体重文本框键盘按下
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtWeight_KeyPress(object sender, KeyPressEventArgs e)
{
//如果不是数字并且不是退格键
if (!regex.IsMatch(txtWeight.Text + e.KeyChar.ToString()) && e.KeyChar != (char)Keys.Back)
{
MessageBox.Show(this, "非法字符", "健康秤", MessageBoxButtons.OK, MessageBoxIcon.Information)
e.Handled = true
}
}
}
}
界面样式如图:
程序的启动界面是为了让需要较长时间的程序启动时,避免用户错误的以为程序没有打开或者没有响应,而设计的一个“小甜点”,但许多人设计时,却忽略了根本,反竖铅而将启动界面用Sleep等延时方法,强制在主屏上显示一段时间,以增加“存在感”,这显然是违背启动界面设计初衷的。
那么,这个启动界面,我们应该在什么时候创建和显示呢?这就需要我们从设计的初衷开始,讨论下启动界面的生存周期问题。
首先,启动界面应在程序一启动时就创建。在Delphi或C++Builder程序中,它应该在TApplication对象创建之后,由于我们一般不推荐修改项目的入口源码,所以我个人推荐是在主窗体的构造函数或OnCreate事件中创建启动画面。
其次,启动界面在主窗口初始化完成后,主窗体显示之前关闭。而不要故意加入Sleep一类的函数来延长用户的等待时间,除非你将启动界面当成是电视广告,否则没必要耽误用户宝贵的时间。
还有一个问题,如果程序很快就初始化完成,启动画面会一闪而过,怎么办?实际上这本身不是问题,毕竟没人不乐意程序快点进入,唯一需要解决的问题就是是否需要显示画面的问题。这里我个人一般推荐使用定时器来延迟显示启动画面,如果启动进程已经超过50%初始化完成,而只用了小于500ms的时间,那我个人认为完全没必要显示一个启动界面来显示自己的存在。
其实,这里牵涉到另一个问题,就是你的程序是否需要加入一个启动界面。如果你的程序的启动没有多少需要初始化的东西,那个人感觉就完全没有必要。启动界面的设计初衷是为了增强用户体验,避免用户在等待程序启动过程中发生错误的认知,态拆如果你很快启动完成,何必加入没必要的东西。
我们接下来讨论下,启动界面都要做些什么?
(1)、一幅制作精美的图片,给用户美好的印象。甚至可以在图片上加上一些 *** 作提示一类实用的技巧啥的;
(2)、应用程序初始化进度提示,以便告诉用户我还活着,不要着急;
至于其它的东西,那不属于启动界面应该 *** 心的事,就交给别的地方去做吧。
启动界面一般也是帆纤枣一个普通的窗体,不同的是我们一般会将其设计为无边的窗口,或者标新立异一点设计成不规则形状的窗口(设置一个背景图片,然后设置TransparentColor就可以实现),然后注意在显示时是用Show而不是ShowModal来显示,初学者容易卡在这一个小地方,提示一下。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)