You are on page 1of 9

using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms;

namespace Abdalla_UT { public partial class Form1 : Form { double Incidence_point = 0.0; int count_half_skips = 0; double projectiondistance = 0.0; double sound_path_length=0.0; double skip_length = 0.0; public Form1() { InitializeComponent(); } private void textBox5_TextChanged(object sender, EventArgs e) { } private void calculate_UT()

{ double Jb = 0.0; double Js = 0.0; double K = 0.0; int count_echo = 0; double echo_pos = 0.0; Jb = double.Parse(textBox1.Text); Js = double.Parse(textBox2.Text); K = Jb / 10.0; count_echo = (int)(Jb / Js); if (count_echo>8) { return; } textBox3.Text = K.ToString(); textBox4.Text = count_echo.ToString(); listBox1.Items.Clear(); for (int i =1 ; i < count_echo+1; i++) { echo_pos = (double)i*Js / K; listBox1.Items.Add(echo_pos.ToString());

pictureBox1.Invalidate(); } private void clear_all() { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; listBox1.Items.Clear(); label20.Text = ""; label24.Text = ""; label25.Text = ""; label22.Text = ""; } private void button1_Click(object sender, EventArgs e) { calculate_UT(); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { //the paintbox shows content Graphics g = e.Graphics; Pen pen = new Pen(Brushes.GreenYellow, 1);

Pen pen1 = new Pen(Brushes.HotPink, 2); Rectangle r = new Rectangle(50, 10, 370,320); g.DrawRectangle(pen, r); Font Font = new Font("Arial", 10); Brush Brush = Brushes.Gold; //Drawing lines in the horizontal direction of equal divisions for (int linecount = 1; linecount < 6; linecount++) { g.DrawLine(pen,50,64*linecount+10,420,64*linecount+10); } //Drawing lines in the vertical direction of equal divisions for (int linecount = 1; linecount < 6; linecount++) { g.DrawLine(pen,74*linecount+50,10,74*linecount+50,330); } //writing numbers from 0 to 10 of step=2 in the vertical direction of equal divisions for (int linecount = 0; linecount < 6; linecount++) { int pos = linecount * 2; g.DrawString(pos.ToString(),Font,Brush,linecount*74+45,335); } //writing numbers from 0 to 100 of step=20 in the vertical direction of equal division for (int linecount = 0; linecount < 6; linecount++) { int pos = 100-linecount * 20; g.DrawString(pos.ToString(),Font,Brush,25,linecount*64); } for (int t = 0; t<listBox1.Items.Count ; t++) { string aline = listBox1.Items[t].ToString(); double dbl_pos = double.Parse(aline); dbl_pos = dbl_pos * 370 / 10; int pos = (int)dbl_pos; double height = 0.0; g.DrawLine(pen1,pos+50, t*35+75, pos+50, 330); } for (int linecount = 1; linecount < 51; linecount++) { g.DrawLine(pen, 48, ((163 * linecount) / 25) + 4, 52, ((163 * linecount) / 25) + 4); } for (int linecount = 1; linecount < 51; linecount++) { g.DrawLine(pen, ((151 * linecount)/20) + 43, 328, ((151 * linecount)/20) + 43, 332); } } private void button2_Click(object sender, EventArgs e) { this.Close();

} private void textBox6_TextChanged(object sender, EventArgs e) {

} private void mytextBox6_Enter() { double read_scale = 0.0; double sound_path_length = 0.0; double K = 0.0; read_scale = double.Parse(textBox5.Text); K = double.Parse(textBox3.Text); sound_path_length = read_scale * K; textBox6.Text = sound_path_length.ToString(); } private void textBox6_Enter(object sender, EventArgs e) { mytextBox6_Enter(); } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { int x_mouse_pos = e.X ; int y_mouse_pos = e.Y; double dbl_x_pos = ((double)x_mouse_pos-50)/37.0; if (dbl_x_pos < 0.0) dbl_x_pos = 0.0; if (dbl_x_pos > 10.0) dbl_x_pos = 10.0; string fstr_x = string.Format("{0:f1}", dbl_x_pos);

double dbl_y_pos = (-(double)y_mouse_pos+330)/3.2; if (dbl_y_pos < 0.0) dbl_y_pos = 0.0; if (dbl_y_pos > 100.0) dbl_y_pos = 100.0; string fstr_y = string.Format("{0:f1}", dbl_y_pos);

label13.Text = fstr_x; label14.Text = fstr_y; } private void pictureBox1_Click(object sender, EventArgs e) { textBox5.Text = label13.Text; mytextBox6_Enter();

} private void pictureBox2_Paint(object sender, PaintEventArgs e) { //picturebox painting for soundpathdrawing //the paintbox shows content Graphics g = e.Graphics; Pen pen = new Pen(Brushes.Black, 1); Pen pen1 = new Pen(Brushes.Black, 2); int height_of_metal = Int32.Parse(textBox8.Text); int int int int x_startlinepos= 0; y_startlinepos = 0; x_endlinepos = 0; y_endlinepos = 0;

Rectangle r = new Rectangle(10, 20, 650, height_of_metal); g.DrawRectangle(pen, r); height_of_metal = Int32.Parse(textBox8.Text); //g.DrawLine(pen, (int)Incidence_point, 20, 222, 222); int linecount = 0; double mod = 0.0; if (count_half_skips == 0) { x_startlinepos = +10 + (int)Incidence_point; y_startlinepos = 20; double radiant = angle2radiant(double.Parse(textBox7.Text));//.Cosin double dbl_x_endlinepos = sound_path_length * Math.Sin(radiant); x_endlinepos=(int)dbl_x_endlinepos+(int)Incidence_point+20; double dbl_y_endlinepos = sound_path_length * Math.Cos(radiant); y_endlinepos = (int)dbl_y_endlinepos+20; label25.Text = dbl_y_endlinepos.ToString(); //x_endlinepos= //y_endlinepos= g.DrawLine(pen, (int)x_startlinepos, y_startlinepos, x_endlinepos, y_endlinepos); } if (count_half_skips > 0) { for (int i = 0; i < count_half_skips; i++) { linecount++; mod = (double)i % 2.0; if (mod == 0.0) y_startlinepos = 0 + 20; if (mod == 1.0) y_startlinepos = height_of_metal + 20;

if (mod == 0.0) y_endlinepos = height_of_metal + 20; if (mod == 1.0) y_endlinepos = 0 + 20; x_startlinepos = i * (int)projectiondistance + (10 + (int)Incidence_point); x_endlinepos = i * (int)projectiondistance + (int)projectiondistance + (10 + (int)Incidence_point); label21.Text = projectiondistance.ToString(); g.DrawLine(pen, (int)x_startlinepos, y_startlinepos, x_endlinepos, y_endlinepos); }

double restpath = sound_path_length - ((skip_length / 2.0) * count_half_skips); double radiant_ = angle2radiant(double.Parse(textBox7.Text));//.Cosin double the_x = Math.Cos(radiant_) * restpath; double the_y = Math.Sin(radiant_) * restpath; x_startlinepos = x_endlinepos; y_startlinepos = y_endlinepos; x_endlinepos = (int)projectiondistance * count_half_skips + (int)the_x + (int)Incidence_point + 10;// ; //y_endlinepos = 222; double restpath_2 = skip_length / 2.0 - restpath; double yheight = restpath_2 * Math.Sin(radiant_); label25.Text = yheight.ToString(); y_endlinepos = (int)yheight + 20; ; g.DrawLine(pen, (int)x_startlinepos, y_startlinepos, x_endlinepos, y_endlinepos); } //if (count_half_skips > 0) } private void textBox8_Leave(object sender, EventArgs e) { pictureBox2.Invalidate(); } private { int int int void pictureBox2_MouseMove(object sender, MouseEventArgs e) x_mouse_pos = e.X; y_mouse_pos = e.Y; height_of_metal = Int32.Parse(textBox8.Text);

double dbl_x_pos = ((double)x_mouse_pos - 10); if (dbl_x_pos < 0.0) dbl_x_pos = 0.0; if (dbl_x_pos > 650.0) dbl_x_pos = 650.0; string fstr_x = string.Format("{0:f1}", dbl_x_pos); label17.Text = fstr_x; double dbl_y_pos = (double)y_mouse_pos -20;

if (dbl_y_pos < 0.0) dbl_y_pos = 0.0; if (dbl_y_pos > height_of_metal) dbl_y_pos = height_of_metal; string fstr_y = string.Format("{0:f1}", dbl_y_pos); label18.Text = fstr_y; } private double angle2radiant(double angle) { //Transformation angle to radiant double radiant = Math.PI * angle / 180.0; return radiant; } private double radiant2angle(double radiant) { //Transformation radian to angle double Pi = Math.PI; double angle = radiant * 180 / Pi; return angle; } private void pictureBox2_Click(object sender, EventArgs e) { double angle = 0.0; int height_of_metal = 0; Incidence_point=double.Parse(label17.Text); label20.Text = Incidence_point.ToString(); label24.Text = skip_length.ToString(); angle = double.Parse(textBox7.Text); height_of_metal = Int32.Parse(textBox8.Text); sound_path_length = double.Parse(textBox6.Text); textBox5.Text = label13.Text; double rad = angle2radiant(angle); skip_length = (2 * height_of_metal)/Math.Cos(rad); double soundpath_half_skip = height_of_metal / Math.Cos(rad); double what = sound_path_length / soundpath_half_skip; projectiondistance = height_of_metal * Math.Tan(rad); count_half_skips=(int)what; //-------------------------------pictureBox2.Invalidate(); } private void button3_Click(object sender, EventArgs e) { // clear_all(); } }

using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms;

namespace Abdalla_Calc {

public partial class Form1 : Form { string myoperator = "+"; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void do_the_calculation() { //Declaration of variables and initiation double value_1 = 0.0; double value_2 = 0.0; double result = 0.0; if (textBox1.Text == "" || textBox2.Text == "") {

return; } value_1 = double.Parse(textBox1.Text); value_2 = double.Parse(textBox2.Text); myoperator = listBox1.Text; if (myoperator == "") myoperator = "+"; if (myoperator == "+") result = value_1 + value_2; if (myoperator == "-") result = value_1 - value_2; if (myoperator == "*") result = value_1 * value_2; if (myoperator == "/") result = value_1 / value_2; textBox3.Text = result.ToString(); } private void button2_Click(object sender, EventArgs e) { do_the_calculation(); } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { do_the_calculation(); } private void textBox1_MouseHover(object sender, EventArgs e) { label5.Text = "input expected"; } private void textBox1_MouseLeave(object sender, EventArgs e) { label5.Text = "-"; } } }

You might also like