发布网友 发布时间:2022-07-29 11:49
共4个回答
热心网友 时间:2023-11-22 23:12
如图:勾选了年利率则按年利率计算,存款天数会折算为年限。否则按日利率计算。
代码如下:
using System;using System.Windows.Forms;
namespace BankLiLv
{
public partial class Form1 : Form
{
#region === 必须的窗体变量 ===
/// <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.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.textBox5 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(87, 52);
this.textBox1.MaxLength = 6;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(102, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "0.5";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(87, 94);
this.textBox2.MaxLength = 20;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(184, 21);
this.textBox2.TabIndex = 0;
this.textBox2.Text = "10000";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(87, 132);
this.textBox3.MaxLength = 10;
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(184, 21);
this.textBox3.TabIndex = 0;
this.textBox3.Text = "365";
//
// button1
//
this.button1.Location = new System.Drawing.Point(114, 267);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "(&C)计算";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 55);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(59, 12);
this.label1.TabIndex = 2;
this.label1.Text = "利 率:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 97);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(59, 12);
this.label2.TabIndex = 2;
this.label2.Text = "本 金:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(13, 135);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(65, 12);
this.label3.TabIndex = 2;
this.label3.Text = "存款天数:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 193);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(59, 12);
this.label4.TabIndex = 4;
this.label4.Text = "利 息:";
//
// textBox4
//
this.textBox4.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.textBox4.Location = new System.Drawing.Point(87, 190);
this.textBox4.Name = "textBox4";
this.textBox4.ReadOnly = true;
this.textBox4.Size = new System.Drawing.Size(184, 21);
this.textBox4.TabIndex = 3;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 224);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(59, 12);
this.label5.TabIndex = 6;
this.label5.Text = "本 息:";
//
// textBox5
//
this.textBox5.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.textBox5.Location = new System.Drawing.Point(87, 221);
this.textBox5.Name = "textBox5";
this.textBox5.ReadOnly = true;
this.textBox5.Size = new System.Drawing.Size(184, 21);
this.textBox5.TabIndex = 5;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label6.ForeColor = System.Drawing.Color.Red;
this.label6.Location = new System.Drawing.Point(198, 52);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(25, 22);
this.label6.TabIndex = 6;
this.label6.Text = "%";
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Checked = true;
this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox1.Location = new System.Drawing.Point(229, 54);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(60, 16);
this.checkBox1.TabIndex = 7;
this.checkBox1.Text = "年利率";
this.checkBox1.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 318);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.label4);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.CheckBox checkBox1;
#endregion
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string temLiLv = this.textBox1.Text.Trim();
string temBenJin = this.textBox2.Text.Trim();
string temDays = this.textBox3.Text.Trim();
if (string.IsNullOrEmpty(temLiLv))
{
MessageBox.Show("利率不能为空!");
textBox1.Focus();
return;
}
if (string.IsNullOrEmpty(temBenJin))
{
MessageBox.Show("本金不能为空!");
textBox2.Focus();
return;
}
if (string.IsNullOrEmpty(temDays))
{
MessageBox.Show("存款天数不能为空!");
textBox3.Focus();
return;
}
decimal lilv = Convert.ToDecimal((temLiLv)) / 100;
decimal benjin = Convert.ToDecimal(temBenJin);
int days = Convert.ToInt32(temDays); //Math.Floor(Convert.ToDouble(temDays));
decimal lixi;
if (checkBox1.Checked)
{
int year = days / 365;
lixi = benjin * lilv * year;
}
else
{
lixi = benjin * lilv * days;
}
textBox4.Text = lixi.ToString();
textBox5.Text = (benjin + lixi).ToString();
}}
}
热心网友 时间:2023-11-22 23:12
我没有winfrom的程序,我那Webfrom给你写吧,代码是一样的追答加我QQ,909588372我给你远程
热心网友 时间:2023-11-22 23:12
Conscle.WileLine("利率计算器”);热心网友 时间:2023-11-22 23:13
两个文本框,再转换成数值,再计算就行了.