Here are the screenshots:
-->
Initial Program |
Result after entering data |
Here are the free code: I have written the code myself. So it will be hard for you to understand but you can email or contact me to ask any questions:
Use this code to put in any .cs file:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Gravitational_Force
{
public partial class Form1 : Form
{
//Global Variable
decimal M1;
decimal M2;
decimal r;
decimal Force;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
M1 = Convert.ToDecimal(txtM1.Text);
M2 = Convert.ToDecimal(txtM2.Text);
r = Convert.ToDecimal(txtR.Text);
double G = 6.6726 * Math.Pow(10, -11);
decimal Gc = (decimal)G; //Converting double to decimla
Force = (Gc* M1 * M2)/ r * r;
label10.Text = "Force = " +Math.Round( Force,10) + "N";
label5.Text = "F = G * M1 * M2 * / r* r ";
label6.Text = " F = 6.6726* 10 ^-11 * " + M1 + "*" + M2;
label8.Text = r + " * " + r;
label9.Text = "------------------";
label7.Text = " F = " +Math.Round(Force, 10) + " N";
}
}
}
---Now its time for designers:
Place these codes in you designer.cs file:
namespace Gravitational_Force
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.txtM1 = new System.Windows.Forms.TextBox();
this.txtM2 = new System.Windows.Forms.TextBox();
this.txtR = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label10 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// txtM1
//
this.txtM1.Location = new System.Drawing.Point(214, 31);
this.txtM1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.txtM1.Name = "txtM1";
this.txtM1.Size = new System.Drawing.Size(214, 24);
this.txtM1.TabIndex = 0;
//
// txtM2
//
this.txtM2.Location = new System.Drawing.Point(214, 80);
this.txtM2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.txtM2.Name = "txtM2";
this.txtM2.Size = new System.Drawing.Size(214, 24);
this.txtM2.TabIndex = 1;
//
// txtR
//
this.txtR.Location = new System.Drawing.Point(214, 129);
this.txtR.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.txtR.Name = "txtR";
this.txtR.Size = new System.Drawing.Size(214, 24);
this.txtR.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(31, 31);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(151, 18);
this.label1.TabIndex = 3;
this.label1.Text = "1st Object Mass (M1)";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(31, 80);
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(155, 18);
this.label2.TabIndex = 4;
this.label2.Text = "2nd Object Mass (M2)";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(107, 132);
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(73, 18);
this.label3.TabIndex = 5;
this.label3.Text = "Radius (r)";
//
// groupBox1
//
this.groupBox1.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.groupBox1.Controls.Add(this.label10);
this.groupBox1.Controls.Add(this.label9);
this.groupBox1.Controls.Add(this.label8);
this.groupBox1.Controls.Add(this.label7);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Location = new System.Drawing.Point(3, 205);
this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.groupBox1.Size = new System.Drawing.Size(425, 286);
this.groupBox1.TabIndex = 6;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Result";
//
// button1
//
this.button1.Location = new System.Drawing.Point(256, 161);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(113, 37);
this.button1.TabIndex = 7;
this.button1.Text = "Calculate";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(45, 35);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(0, 18);
this.label4.TabIndex = 0;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(45, 93);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(12, 18);
this.label5.TabIndex = 1;
this.label5.Text = ".";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(45, 139);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(12, 18);
this.label6.TabIndex = 2;
this.label6.Text = ".";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(45, 223);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(12, 18);
this.label7.TabIndex = 3;
this.label7.Text = ".";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(104, 175);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(12, 18);
this.label8.TabIndex = 4;
this.label8.Text = ".";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(97, 157);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(12, 18);
this.label9.TabIndex = 5;
this.label9.Text = ".";
//
// pictureBox1
//
this.pictureBox1.ErrorImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.ErrorImage")));
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(446, 22);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(415, 469);
this.pictureBox1.TabIndex = 8;
this.pictureBox1.TabStop = false;
//
// label10
//
this.label10.AutoSize = true;
this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label10.ForeColor = System.Drawing.Color.Red;
this.label10.Location = new System.Drawing.Point(24, 35);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(15, 24);
this.label10.TabIndex = 6;
this.label10.Text = ".";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(855, 496);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtR);
this.Controls.Add(this.txtM2);
this.Controls.Add(this.txtM1);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.Name = "Form1";
this.Text = "Gravity Equation";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtM1;
private System.Windows.Forms.TextBox txtM2;
private System.Windows.Forms.TextBox txtR;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label10;
}
}
ENJOY the code Thank You!
No comments:
Post a Comment