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
- {
- TextBox speedBox;
- TextBox lengthBox;
- TextBox amountBox;
- TextBox faultBox;
- Button startButton;
- ComboBox laneBox;
- Graphics g;
- public GUI(Mainentry mainEntry)
- {
- InitializeComponent();
- g = this.CreateGraphics();
- this.Paint += delegate { paintManualUI(); };
- this.Paint += delegate { paintManualTextBoxes((Screen.PrimaryScreen.WorkingArea.Width / 8), (Screen.PrimaryScreen.WorkingArea.Height / 4) * 3); };
- }
- private void paintManualUI()
- {
- int X = (Screen.PrimaryScreen.WorkingArea.Width / 8);
- int Y = (Screen.PrimaryScreen.WorkingArea.Height / 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((Screen.PrimaryScreen.WorkingArea.Width / 3), (Screen.PrimaryScreen.WorkingArea.Height / 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 paintManualTextBoxes(int X, int Y)
- {
- TextBox speedText = new TextBox();
- speedText.BorderStyle = BorderStyle.None;
- speedText.Text = "Speed";
- speedText.ReadOnly = true;
- speedText.Location = new Point(X - 50, Y);
- TextBox lengthText = new TextBox();
- lengthText.BorderStyle = BorderStyle.None;
- lengthText.Text = "Length";
- lengthText.ReadOnly = true;
- lengthText.Location = new Point(X - 50, Y + 50);
- lengthText.Size = new Size(40, 8);
- TextBox faultText = new TextBox();
- faultText.BorderStyle = BorderStyle.None;
- faultText.Text = "Faulty Detection";
- faultText.ReadOnly = true;
- faultText.Location = new Point(X - 93, Y + 100);
- TextBox amountText = new TextBox();
- amountText.BorderStyle = BorderStyle.None;
- amountText.Text = "Amount";
- amountText.ReadOnly = true;
- amountText.Location = new Point(X - 50, Y + 150);
- this.Controls.Add(speedText);
- this.Controls.Add(lengthText);
- this.Controls.Add(faultText);
- this.Controls.Add(amountText);
- }
- private void GUI_Load(object sender, EventArgs e)
- {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement