Salut , je voudrais gérer une petite calculatrice . Dans mon programme je dois gérer un nombre a virgule ( ex: 10.20) dans une textbox et ensuite faire des calculs avec le chiffre . Mais lorsque je met mon point "." pour faire ma virgule , mon programme n'arrive pas a faire la conversion en double et ca bloque mon programme. voila mon code source.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace EgliseVieNouvelle
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button boutonTaxe1;
private System.Windows.Forms.Button boutonTaxe2;
private System.Windows.Forms.TextBox PrixSansTaxe;
private System.Windows.Forms.TextBox PrixTaxé;
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.boutonTaxe1 = new System.Windows.Forms.Button();
this.boutonTaxe2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.PrixSansTaxe = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.PrixTaxé = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// boutonTaxe1
//
this.boutonTaxe1.Font = new System.Drawing.Font("Verdana", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.boutonTaxe1.Location = new System.Drawing.Point(408, 104);
this.boutonTaxe1.Name = "boutonTaxe1";
this.boutonTaxe1.Size = new System.Drawing.Size(136, 40);
this.boutonTaxe1.TabIndex = 0;
this.boutonTaxe1.Text = "1 Taxe";
this.boutonTaxe1.Click += new System.EventHandler(this.boutonTaxe1_Click);
//
// boutonTaxe2
//
this.boutonTaxe2.Font = new System.Drawing.Font("Verdana", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.boutonTaxe2.Location = new System.Drawing.Point(408, 160);
this.boutonTaxe2.Name = "boutonTaxe2";
this.boutonTaxe2.Size = new System.Drawing.Size(136, 40);
this.boutonTaxe2.TabIndex = 2;
this.boutonTaxe2.Text = "2 Taxes";
this.boutonTaxe2.Click += new System.EventHandler(this.boutonTaxe2_Click_1);
//
// label1
//
this.label1.Font = new System.Drawing.Font("Verdana", 15.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(16, 48);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(432, 32);
this.label1.TabIndex = 3;
this.label1.Text = "Veuillez entrer le prix de l\'article";
//
// PrixSansTaxe
//
this.PrixSansTaxe.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.PrixSansTaxe.Location = new System.Drawing.Point(64, 112);
this.PrixSansTaxe.Multiline = true;
this.PrixSansTaxe.Name = "PrixSansTaxe";
this.PrixSansTaxe.Size = new System.Drawing.Size(264, 48);
this.PrixSansTaxe.TabIndex = 4;
this.PrixSansTaxe.Text = "";
//
// label2
//
this.label2.Font = new System.Drawing.Font("Verdana", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(72, 200);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(112, 40);
this.label2.TabIndex = 5;
this.label2.Text = "Total";
//
// PrixTaxé
//
this.PrixTaxé.Font = new System.Drawing.Font("Verdana", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.PrixTaxé.Location = new System.Drawing.Point(208, 192);
this.PrixTaxé.Multiline = true;
this.PrixTaxé.Name = "PrixTaxé";
this.PrixTaxé.ReadOnly = true;
this.PrixTaxé.Size = new System.Drawing.Size(120, 40);
this.PrixTaxé.TabIndex = 6;
this.PrixTaxé.Text = "";
//
// button1
//
this.button1.Font = new System.Drawing.Font("Verdana", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button1.Location = new System.Drawing.Point(408, 216);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(136, 40);
this.button1.TabIndex = 7;
this.button1.Text = "Effacer";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(560, 278);
this.Controls.Add(this.button1);
this.Controls.Add(this.PrixTaxé);
this.Controls.Add(this.label2);
this.Controls.Add(this.PrixSansTaxe);
this.Controls.Add(this.label1);
this.Controls.Add(this.boutonTaxe2);
this.Controls.Add(this.boutonTaxe1);
this.Name = "Form1";
this.Text = "Calculatrice Librairie Vie Nouvelle";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void boutonTaxe1_Click(object sender, System.EventArgs e)
{
String ValeurEntrée = PrixSansTaxe.Text;
double prix = Double.Parse(ValeurEntrée);
prix = prix+(prix*0.05);
this.PrixTaxé.Text = " "+prix.ToString();
}
private void boutonTaxe2_Click_1(object sender, System.EventArgs e)
{
String ValeurEntrée = PrixSansTaxe.Text;
double prix = Double.Parse(ValeurEntrée);
prix = prix+(prix*0.05);
prix = prix+(prix*0.075);
this.PrixTaxé.Text = " "+prix.ToString();
}
private void button1_Click(object sender, System.EventArgs e)
{
this.PrixSansTaxe.Text = " ";
this.PrixTaxé.Text = " ";
}
}
}
Dans mon cas la valeur ValeurEntrée doit etre transfomé en double pour pouvoir effectuer le cacul. merci de votre aide.
Yohan
Afficher la suite