Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace DSemulator
- {
- public partial class GUI : Form
- {
- Integer screenWidth;
- Integer screenHeight;
- TextBox speedBox;
- TextBox lengthBox;
- TextBox amountBox;
- TextBox faultBox;
- Button startButton;
- ComboBox laneBox;
- Graphics g;
- public GUI(Mainentry mainEntry)
- {
- InitializeComponent();
- //Creating a constant integer for screen width/height prevents repeated calls to
- // Screen.PrimaryScreen.WorkingArea - optimizing the number of calculations done
- screenWidth = Screen.PrimaryScreen.WorkingArea.Width ;
- screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
- g = this.CreateGraphics();
- int X = (screenWidth / 8);
- int Y = (screenHeight / 4) * 3;
- speedBox = new TextBox();
- speedBox.Name = "speedBox";
- speedBox.MaxLength = 5;
- speedBox.Location = new Point(X, Y);
- speedBox.KeyPress += input_KeyPress;
- lengthBox = new TextBox();
- lengthBox.Name = "lengthBox";
- lengthBox.MaxLength = 5;
- lengthBox.Location = new Point(X, Y + 50);
- lengthBox.KeyPress += input_KeyPress;
- amountBox = new TextBox();
- amountBox.Name = "amountBox";
- amountBox.MaxLength = 2;
- amountBox.Location = new Point(X, Y + 100);
- amountBox.KeyPress += amountBox_KeyPress;
- faultBox = new TextBox();
- faultBox.Name = "faultBox";
- faultBox.MaxLength = 2;
- faultBox.Location = new Point(X, Y + 150);
- faultBox.KeyPress += amountBox_KeyPress;
- laneBox = new ComboBox();
- laneBox.Name = "laneBox";
- for (int i = 1; i <= 3; i++)
- laneBox.Items.Add("Drivelane " + i);
- laneBox.SelectedIndex = 0;
- laneBox.Location = new Point(X, Y - 50);
- startButton = new Button();
- startButton.Name = "startButton";
- startButton.Text = "Start";
- startButton.BackColor = Color.Green;
- startButton.Size = new Size(100, 50);
- startButton.Font = new Font("Times New Roman", 20);
- startButton.Location = new Point((screenWidth / 3), (screenHeight / 4) * 3);
- this.Controls.Add(speedBox);
- this.Controls.Add(lengthBox);
- this.Controls.Add(amountBox);
- this.Controls.Add(faultBox);
- this.Controls.Add(laneBox);
- this.Controls.Add(startButton);
- startButton.Click += startButton_Click;
- }
- void startButton_Click(object sender, EventArgs e)
- {
- Control[] temp = this.Controls.Find("speedBox", false);
- float speed = float.Parse(((TextBox)temp[0]).Text);
- ((TextBox)temp[0]).Text = String.Empty;
- temp = this.Controls.Find("lengthBox", false);
- float length = float.Parse(((TextBox)temp[0]).Text);
- ((TextBox)temp[0]).Text = String.Empty;
- temp = this.Controls.Find("amountBox", false);
- int amount = int.Parse(((TextBox)temp[0]).Text);
- ((TextBox)temp[0]).Text = String.Empty;
- temp = this.Controls.Find("faultBox", false);
- int fault = int.Parse(((TextBox)temp[0]).Text);
- ((TextBox)temp[0]).Text = String.Empty;
- temp = this.Controls.Find("laneBox", false);
- int lane = ((ComboBox)temp[0]).SelectedIndex + 1;
- //call some method in another object
- }
- void amountBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- Byte backspace = 0x8;
- if (e.KeyChar >= '0' && e.KeyChar <= '9' || e.KeyChar == Convert.ToChar(backspace))
- e.Handled = false;
- else
- e.Handled = true;
- }
- void input_KeyPress(object sender, KeyPressEventArgs e)
- {
- Byte backspace = 0x8;
- if (e.KeyChar >= '0' && e.KeyChar <= '9' || e.KeyChar == Convert.ToChar(backspace) || e.KeyChar == ',')
- e.Handled = false; //accept character
- else
- e.Handled = true; //decline character
- }
- private void GUI_Load(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement