[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

How do I make the C# windows application solution calculate when I press the button?

I am having problems making the following solution execute is C# windows applications.  When I press the button I do not get any answers from my calculations.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace VolumeConeWindows
{
      /// <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 btnPress;
            private System.Windows.Forms.Label label3;
            private System.Windows.Forms.Label label4;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.Button button2;
            private System.Windows.Forms.TextBox txtVolumea;
            private System.Windows.Forms.TextBox txtVolumeb;
            private System.Windows.Forms.TextBox txtVolumec;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <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.label1 = new System.Windows.Forms.Label();
                  this.label2 = new System.Windows.Forms.Label();
                  this.btnPress = new System.Windows.Forms.Button();
                  this.txtVolumea = new System.Windows.Forms.TextBox();
                  this.label3 = new System.Windows.Forms.Label();
                  this.label4 = new System.Windows.Forms.Label();
                  this.button1 = new System.Windows.Forms.Button();
                  this.button2 = new System.Windows.Forms.Button();
                  this.txtVolumeb = new System.Windows.Forms.TextBox();
                  this.txtVolumec = new System.Windows.Forms.TextBox();
                  this.SuspendLayout();
                  //
                  // label1
                  //
                  this.label1.BackColor = System.Drawing.Color.DimGray;
                  this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label1.Font = new System.Drawing.Font("Miriam Fixed", 13.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(177)));
                  this.label1.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label1.Location = new System.Drawing.Point(64, 8);
                  this.label1.Name = "label1";
                  this.label1.Size = new System.Drawing.Size(248, 32);
                  this.label1.TabIndex = 0;
                  this.label1.Text = "Volume of Cone";
                  //
                  // label2
                  //
                  this.label2.BackColor = System.Drawing.Color.DimGray;
                  this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.label2.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label2.Location = new System.Drawing.Point(40, 96);
                  this.label2.Name = "label2";
                  this.label2.Size = new System.Drawing.Size(120, 72);
                  this.label2.TabIndex = 1;
                  this.label2.Text = "The Volume of the cone A is:";
                  //
                  // btnPress
                  //
                  this.btnPress.BackColor = System.Drawing.Color.DimGray;
                  this.btnPress.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.btnPress.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.btnPress.Location = new System.Drawing.Point(160, 208);
                  this.btnPress.Name = "btnPress";
                  this.btnPress.Size = new System.Drawing.Size(75, 32);
                  this.btnPress.TabIndex = 2;
                  this.btnPress.Text = "Press!";
                  this.btnPress.Click += new System.EventHandler(this.btnPress_Click);
                  //
                  // txtVolumea
                  //
                  this.txtVolumea.Location = new System.Drawing.Point(256, 120);
                  this.txtVolumea.Name = "txtVolumea";
                  this.txtVolumea.TabIndex = 3;
                  this.txtVolumea.Text = "";
                  //
                  // label3
                  //
                  this.label3.BackColor = System.Drawing.Color.DimGray;
                  this.label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.label3.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label3.Location = new System.Drawing.Point(32, 296);
                  this.label3.Name = "label3";
                  this.label3.Size = new System.Drawing.Size(128, 72);
                  this.label3.TabIndex = 4;
                  this.label3.Text = "The Volume of the cone B is:";
                  //
                  // label4
                  //
                  this.label4.BackColor = System.Drawing.Color.DimGray;
                  this.label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.label4.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label4.Location = new System.Drawing.Point(40, 456);
                  this.label4.Name = "label4";
                  this.label4.Size = new System.Drawing.Size(120, 72);
                  this.label4.TabIndex = 5;
                  this.label4.Text = "The Volume of the cone C is:";
                  //
                  // button1
                  //
                  this.button1.BackColor = System.Drawing.Color.DimGray;
                  this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.button1.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.button1.Location = new System.Drawing.Point(168, 536);
                  this.button1.Name = "button1";
                  this.button1.Size = new System.Drawing.Size(88, 32);
                  this.button1.TabIndex = 6;
                  this.button1.Text = "Press!!!";
                  this.button1.Click += new System.EventHandler(this.button1_Click);
                  //
                  // button2
                  //
                  this.button2.BackColor = System.Drawing.Color.DimGray;
                  this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.button2.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.button2.Location = new System.Drawing.Point(168, 400);
                  this.button2.Name = "button2";
                  this.button2.Size = new System.Drawing.Size(80, 32);
                  this.button2.TabIndex = 7;
                  this.button2.Text = "Press!!";
                  this.button2.Click += new System.EventHandler(this.button2_Click);
                  //
                  // txtVolumeb
                  //
                  this.txtVolumeb.Location = new System.Drawing.Point(264, 320);
                  this.txtVolumeb.Name = "txtVolumeb";
                  this.txtVolumeb.TabIndex = 8;
                  this.txtVolumeb.Text = "";
                  this.txtVolumeb.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
                  //
                  // txtVolumec
                  //
                  this.txtVolumec.Location = new System.Drawing.Point(264, 480);
                  this.txtVolumec.Name = "txtVolumec";
                  this.txtVolumec.TabIndex = 10;
                  this.txtVolumec.Text = "";
                  this.txtVolumec.TextChanged += new System.EventHandler(this.textBox3_TextChanged);
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
                  this.BackColor = System.Drawing.Color.Gray;
                  this.ClientSize = new System.Drawing.Size(528, 576);
                  this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                                              this.txtVolumec,
                                                                                                              this.txtVolumeb,
                                                                                                              this.button2,
                                                                                                              this.button1,
                                                                                                              this.label4,
                                                                                                              this.label3,
                                                                                                              this.txtVolumea,
                                                                                                              this.btnPress,
                                                                                                              this.label2,
                                                                                                              this.label1});
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void btnPress_Click(object sender, System.EventArgs e)
            {
                  const double PI=3.1415;
                  int height=10, radius=328;
                  string sVolume;

                  
                  
                  sVolume=Convert.ToString(PI*radius*radius*height/3);txtVolumea.Text=Convert.ToInt32(sVolume).ToString();
                  
                  
            }

            private void button1_Click(object sender, System.EventArgs e)
            {
                  const double PI=3.1415;
                  int heightb=30, radius=328;
                  string sVolumeb;

                  sVolumeb=Convert.ToString(PI*radius*radius*heightb/3);txtVolumec.Text=Convert.ToInt32(sVolumeb).ToString();
            }

            private void textBox3_TextChanged(object sender, System.EventArgs e)
            {
            
            }

            private void textBox1_TextChanged(object sender, System.EventArgs e)
            {
            
            }

            private void button2_Click(object sender, System.EventArgs e)
            {
                  const double PI=3.1415;
                  int heighta=20, radius=328;
                  string sVolumea;

                  sVolumea=Convert.ToString(PI*radius*radius*heighta/3);txtVolumeb.Text=Convert.ToInt32(sVolumea).ToString();
                  
                  
            }
      }
}
0
Cocono1
Asked:
Cocono1
1 Solution
 
prashantagarw10Commented:
have u tried debugging the application ? Does the execution pointer go to correct event code when you click on any button ? If yes are the values correct while code is being executed.
If yes ur text must be displayed in the textbox. Also check that textbox does not have forecolor and backcolor properties set to same color!!!!

Cheers!
Prashant
0
 
Cocono1Author Commented:
The textbox for forecolore and backcolor properties is not set to same color.  When it debug the program I get input string was not in correct format.  I can't see what is wrong with it.  When I build the program, I do not get any errors.
0
 
prashantagarw10Commented:
Instead of your two lines
sVolumeb=Convert.ToString(PI*radius*radius*heightb/3);
txtVolumec.Text=Convert.ToInt32(sVolumeb).ToString();


write a simple line
txtVolumec.Text=(PI*radius*radius*heightb)/3;

Now see what happens.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Cocono1Author Commented:
I get the following error message:
Cannot implicitly convert type 'double' to 'string'
0
 
Cocono1Author Commented:
I figured out the problem.  I rewrite the following way and it worked.  Thanks though for trying to help.  I appreciate it.

sVolume=Convert.ToString(PI*radius*radius*height/3);
txtVolumea.Text=sVolume;
0
 
Rajkumar_GCommented:
Now try this code..


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace VolumeConeWindows
{
      /// <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 btnPress;
            private System.Windows.Forms.Label label3;
            private System.Windows.Forms.Label label4;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.Button button2;
            private System.Windows.Forms.TextBox txtVolumea;
            private System.Windows.Forms.TextBox txtVolumeb;
            private System.Windows.Forms.TextBox txtVolumec;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <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.label1 = new System.Windows.Forms.Label();
                  this.label2 = new System.Windows.Forms.Label();
                  this.btnPress = new System.Windows.Forms.Button();
                  this.txtVolumea = new System.Windows.Forms.TextBox();
                  this.label3 = new System.Windows.Forms.Label();
                  this.label4 = new System.Windows.Forms.Label();
                  this.button1 = new System.Windows.Forms.Button();
                  this.button2 = new System.Windows.Forms.Button();
                  this.txtVolumeb = new System.Windows.Forms.TextBox();
                  this.txtVolumec = new System.Windows.Forms.TextBox();
                  this.SuspendLayout();
                  //
                  // label1
                  //
                  this.label1.BackColor = System.Drawing.Color.DimGray;
                  this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label1.Font = new System.Drawing.Font("Miriam Fixed", 13.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(177)));
                  this.label1.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label1.Location = new System.Drawing.Point(64, 8);
                  this.label1.Name = "label1";
                  this.label1.Size = new System.Drawing.Size(248, 32);
                  this.label1.TabIndex = 0;
                  this.label1.Text = "Volume of Cone";
                  //
                  // label2
                  //
                  this.label2.BackColor = System.Drawing.Color.DimGray;
                  this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.label2.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label2.Location = new System.Drawing.Point(40, 96);
                  this.label2.Name = "label2";
                  this.label2.Size = new System.Drawing.Size(120, 72);
                  this.label2.TabIndex = 1;
                  this.label2.Text = "The Volume of the cone A is:";
                  //
                  // btnPress
                  //
                  this.btnPress.BackColor = System.Drawing.Color.DimGray;
                  this.btnPress.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.btnPress.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.btnPress.Location = new System.Drawing.Point(160, 208);
                  this.btnPress.Name = "btnPress";
                  this.btnPress.Size = new System.Drawing.Size(75, 32);
                  this.btnPress.TabIndex = 2;
                  this.btnPress.Text = "Press!";
                  this.btnPress.Click += new System.EventHandler(this.btnPress_Click);
                  //
                  // txtVolumea
                  //
                  this.txtVolumea.Location = new System.Drawing.Point(256, 120);
                  this.txtVolumea.Name = "txtVolumea";
                  this.txtVolumea.TabIndex = 3;
                  this.txtVolumea.Text = "";
                  //
                  // label3
                  //
                  this.label3.BackColor = System.Drawing.Color.DimGray;
                  this.label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.label3.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label3.Location = new System.Drawing.Point(32, 296);
                  this.label3.Name = "label3";
                  this.label3.Size = new System.Drawing.Size(128, 72);
                  this.label3.TabIndex = 4;
                  this.label3.Text = "The Volume of the cone B is:";
                  //
                  // label4
                  //
                  this.label4.BackColor = System.Drawing.Color.DimGray;
                  this.label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.label4.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label4.Location = new System.Drawing.Point(40, 456);
                  this.label4.Name = "label4";
                  this.label4.Size = new System.Drawing.Size(120, 72);
                  this.label4.TabIndex = 5;
                  this.label4.Text = "The Volume of the cone C is:";
                  //
                  // button1
                  //
                  this.button1.BackColor = System.Drawing.Color.DimGray;
                  this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.button1.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.button1.Location = new System.Drawing.Point(168, 536);
                  this.button1.Name = "button1";
                  this.button1.Size = new System.Drawing.Size(88, 32);
                  this.button1.TabIndex = 6;
                  this.button1.Text = "Press!!!";
                  this.button1.Click += new System.EventHandler(this.button1_Click);
                  //
                  // button2
                  //
                  this.button2.BackColor = System.Drawing.Color.DimGray;
                  this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.button2.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.button2.Location = new System.Drawing.Point(168, 400);
                  this.button2.Name = "button2";
                  this.button2.Size = new System.Drawing.Size(80, 32);
                  this.button2.TabIndex = 7;
                  this.button2.Text = "Press!!";
                  this.button2.Click += new System.EventHandler(this.button2_Click);
                  //
                  // txtVolumeb
                  //
                  this.txtVolumeb.Location = new System.Drawing.Point(264, 320);
                  this.txtVolumeb.Name = "txtVolumeb";
                  this.txtVolumeb.TabIndex = 8;
                  this.txtVolumeb.Text = "";
                  this.txtVolumeb.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
                  //
                  // txtVolumec
                  //
                  this.txtVolumec.Location = new System.Drawing.Point(264, 480);
                  this.txtVolumec.Name = "txtVolumec";
                  this.txtVolumec.TabIndex = 10;
                  this.txtVolumec.Text = "";
                  this.txtVolumec.TextChanged += new System.EventHandler(this.textBox3_TextChanged);
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
                  this.BackColor = System.Drawing.Color.Gray;
                  this.ClientSize = new System.Drawing.Size(528, 576);
                  this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                                              this.txtVolumec,
                                                                                                              this.txtVolumeb,
                                                                                                              this.button2,
                                                                                                              this.button1,
                                                                                                              this.label4,
                                                                                                              this.label3,
                                                                                                              this.txtVolumea,
                                                                                                              this.btnPress,
                                                                                                              this.label2,
                                                                                                              this.label1});
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void btnPress_Click(object sender, System.EventArgs e)
            {
                  const double  PI = 3.1415;
                  int height=10, radius=328;
                  string sVolume;
                  sVolume=Convert.ToString(PI*radius*radius*height/3);
                  txtVolumea.Text = decimal.Round(decimal.Parse(sVolume),0).ToString();
         }

            private void button1_Click(object sender, System.EventArgs e)
            {
                  const double PI=3.1415;
                  int heightb=30, radius=328;
                  string sVolumeb;

                  sVolumeb=Convert.ToString(PI*radius*radius*heightb/3);
                  txtVolumec.Text=decimal.Round(decimal.Parse(sVolumeb),0).ToString();
            }

            private void textBox3_TextChanged(object sender, System.EventArgs e)
            {
         
            }

            private void textBox1_TextChanged(object sender, System.EventArgs e)
            {
         
            }

            private void button2_Click(object sender, System.EventArgs e)
            {
                  const double PI=3.1415;
                  int heighta=20, radius=328;
                  string sVolumea;

                  sVolumea=Convert.ToString(PI*radius*radius*heighta/3);
                  txtVolumeb.Text=decimal.Round(decimal.Parse(sVolumea),0).ToString();
            }
      }
}
0
 
frankcvCommented:
The problem in your code is Convert.ToInt32() was provided with a string value that has a decimal point. I have provided you with two alternative solutions to achieve the same result and left the 3rd one untouched.

Convert.ToInt32() can take a numerical value with a decimal point but no decimal point when the input value is a string. Hope this solves your problem.
---------------------------------------------------

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace VolumeConeWindows
{
      /// <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 btnPress;
            private System.Windows.Forms.Label label3;
            private System.Windows.Forms.Label label4;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.Button button2;
            private System.Windows.Forms.TextBox txtVolumea;
            private System.Windows.Forms.TextBox txtVolumeb;
            private System.Windows.Forms.TextBox txtVolumec;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <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.label1 = new System.Windows.Forms.Label();
                  this.label2 = new System.Windows.Forms.Label();
                  this.btnPress = new System.Windows.Forms.Button();
                  this.txtVolumea = new System.Windows.Forms.TextBox();
                  this.label3 = new System.Windows.Forms.Label();
                  this.label4 = new System.Windows.Forms.Label();
                  this.button1 = new System.Windows.Forms.Button();
                  this.button2 = new System.Windows.Forms.Button();
                  this.txtVolumeb = new System.Windows.Forms.TextBox();
                  this.txtVolumec = new System.Windows.Forms.TextBox();
                  this.SuspendLayout();
                  //
                  // label1
                  //
                  this.label1.BackColor = System.Drawing.Color.DimGray;
                  this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 13.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(177)));
                  this.label1.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label1.Location = new System.Drawing.Point(53, 7);
                  this.label1.Name = "label1";
                  this.label1.Size = new System.Drawing.Size(207, 28);
                  this.label1.TabIndex = 0;
                  this.label1.Text = "Volume of Cone";
                  //
                  // label2
                  //
                  this.label2.BackColor = System.Drawing.Color.DimGray;
                  this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.label2.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label2.Location = new System.Drawing.Point(33, 83);
                  this.label2.Name = "label2";
                  this.label2.Size = new System.Drawing.Size(100, 63);
                  this.label2.TabIndex = 1;
                  this.label2.Text = "The Volume of the cone A is:";
                  //
                  // btnPress
                  //
                  this.btnPress.BackColor = System.Drawing.Color.DimGray;
                  this.btnPress.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.btnPress.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.btnPress.Location = new System.Drawing.Point(133, 180);
                  this.btnPress.Name = "btnPress";
                  this.btnPress.Size = new System.Drawing.Size(63, 28);
                  this.btnPress.TabIndex = 2;
                  this.btnPress.Text = "Press!";
                  this.btnPress.Click += new System.EventHandler(this.btnPress_Click);
                  //
                  // txtVolumea
                  //
                  this.txtVolumea.Location = new System.Drawing.Point(213, 104);
                  this.txtVolumea.Name = "txtVolumea";
                  this.txtVolumea.Size = new System.Drawing.Size(84, 20);
                  this.txtVolumea.TabIndex = 3;
                  this.txtVolumea.Text = "";
                  //
                  // label3
                  //
                  this.label3.BackColor = System.Drawing.Color.DimGray;
                  this.label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.label3.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label3.Location = new System.Drawing.Point(27, 257);
                  this.label3.Name = "label3";
                  this.label3.Size = new System.Drawing.Size(106, 62);
                  this.label3.TabIndex = 4;
                  this.label3.Text = "The Volume of the cone B is:";
                  //
                  // label4
                  //
                  this.label4.BackColor = System.Drawing.Color.DimGray;
                  this.label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.label4.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.label4.Location = new System.Drawing.Point(33, 395);
                  this.label4.Name = "label4";
                  this.label4.Size = new System.Drawing.Size(100, 63);
                  this.label4.TabIndex = 5;
                  this.label4.Text = "The Volume of the cone C is:";
                  //
                  // button1
                  //
                  this.button1.BackColor = System.Drawing.Color.DimGray;
                  this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.button1.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.button1.Location = new System.Drawing.Point(144, 336);
                  this.button1.Name = "button1";
                  this.button1.Size = new System.Drawing.Size(73, 27);
                  this.button1.TabIndex = 6;
                  this.button1.Text = "Press!!!";
                  this.button1.Click += new System.EventHandler(this.button1_Click);
                  //
                  // button2
                  //
                  this.button2.BackColor = System.Drawing.Color.DimGray;
                  this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.button2.ForeColor = System.Drawing.SystemColors.ActiveBorder;
                  this.button2.Location = new System.Drawing.Point(144, 464);
                  this.button2.Name = "button2";
                  this.button2.Size = new System.Drawing.Size(67, 27);
                  this.button2.TabIndex = 7;
                  this.button2.Text = "Press!!";
                  this.button2.Click += new System.EventHandler(this.button2_Click);
                  //
                  // txtVolumeb
                  //
                  this.txtVolumeb.Location = new System.Drawing.Point(220, 277);
                  this.txtVolumeb.Name = "txtVolumeb";
                  this.txtVolumeb.Size = new System.Drawing.Size(83, 20);
                  this.txtVolumeb.TabIndex = 8;
                  this.txtVolumeb.Text = "";
                  //
                  // txtVolumec
                  //
                  this.txtVolumec.Location = new System.Drawing.Point(220, 416);
                  this.txtVolumec.Name = "txtVolumec";
                  this.txtVolumec.Size = new System.Drawing.Size(83, 20);
                  this.txtVolumec.TabIndex = 10;
                  this.txtVolumec.Text = "";
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.BackColor = System.Drawing.Color.Gray;
                  this.ClientSize = new System.Drawing.Size(439, 499);
                  this.Controls.Add(this.txtVolumec);
                  this.Controls.Add(this.txtVolumeb);
                  this.Controls.Add(this.button2);
                  this.Controls.Add(this.button1);
                  this.Controls.Add(this.label4);
                  this.Controls.Add(this.label3);
                  this.Controls.Add(this.txtVolumea);
                  this.Controls.Add(this.btnPress);
                  this.Controls.Add(this.label2);
                  this.Controls.Add(this.label1);
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void btnPress_Click(object sender, System.EventArgs e)
            {
                  const double PI=3.1415;
                  int height=10, radius=328;
                  string sVolume;

                  //The following code if fine. You will see a display of an integer.
            sVolume = Convert.ToInt32(PI*radius*radius*height/3).ToString();
                  txtVolumea.Text= sVolume;
            }

            private void button1_Click(object sender, System.EventArgs e)
            {
                  const double PI=3.1415;
                  int heightb=30, radius=328;
                  //string sVolumeb;
                  long lVolumeb;

                  //With the following code you will see a display of an integer as well.
                  lVolumeb = Convert.ToInt32(PI*radius*radius*heightb/3);
                  txtVolumeb.Text = lVolumeb.ToString();
                  //txtVolumec.Text=Convert.ToInt32(sVolumeb).ToString();
            }

                  private void button2_Click(object sender, System.EventArgs e)
            {
                  const double PI=3.1415;
                  int heighta=20, radius=328;
                  string sVolumea;

                        //The following code if not correct because in function
                        //"Convert.ToInt32(string Value)"the Value must be a string consisting of
                        //digits with no decimal point.
                        //
                  sVolumea=Convert.ToString(PI*radius*radius*heighta/3);
                  txtVolumeb.Text=Convert.ToInt32(sVolumea).ToString();
       
               
            }
      }
}

0
 
Computer101Commented:
PAQed, with points refunded (500)

Computer101
E-E Admin
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now