Реализация языка запросов по управлению

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace Phisics2

{

public partial class Form1: Form

{

float w = 6F, h = 7.5F;

string textcode, code;

Pen RedPen = new Pen (Color. Red, 10);

Pen WhitePen = new Pen (Color. White, 10);

public Form1()

{

InitializeComponent();

this. StartPosition = FormStartPosition. CenterScreen;

textBox1.MaxLength = 10;

}

private void Form1_Load(object sender, EventArgs e)

{

textBox1.SelectionStart = 0;

}

private void button1_Click(object sender, EventArgs e)

{

code = null;

// принять значение из текстобкса

textcode = textBox1.Text;

// разделить текст на две части, в первом два симовла, во втором остальные

//for (int i = 0; i < 2; i++)

// portcode += textcode[i];

for (int i = 2; i < textcode.Length; i++)

{

//if ((Convert.ToInt32(textcode[i])!= 48) &&

// (Convert.ToInt32(textcode[i])!= 49))

if ((textcode[i]!= '0') &&

(textcode[i]!= '1') ||

((

(textcode[0]!= 'R') &&

(textcode[0]!= 'r')) ||

((textcode[1]!= 'A') &&

(textcode[1]!= 'B') &&

(textcode[1]!= 'C') &&

(textcode[1]!= 'D') &&

(textcode[1]!= 'E') &&

(textcode[1]!= 'a') &&

(textcode[1]!= 'b') &&

(textcode[1]!= 'c') &&

(textcode[1]!= 'd') &&

(textcode[1]!= 'e'))))

{

MessageBox. Show("Введите название порта и комбинацию из 0 и 1",

"Error",

MessageBoxButtons. OK,

MessageBoxIcon. Error);

return;

}

code += textcode[i];

}

// RA RE RC RD RB

// в зависимости какие первые два симовола идём дальше или выдаём ошибку

// если вторая часть boolean.tryParse(...) булево, то в зависимости

// от кол-ва символов врубаем ножки или выводитм сообщение!

MyFunction(textcode[1], code);

}

public void MyPrint(float x, float y, int count, int from, bool flag)

{

for (; from < count; from++)

{

if (code[from] == '1')

{

pictureBox1.CreateGraphics().FillRectangle(RedPen.Brush, x, y, w, h);

}

Else

{

pictureBox1.CreateGraphics().FillRectangle(WhitePen.Brush, x, y, w, h);

}

if (flag)

y += 13.93F;

Else

y -= 13.93F;

}

}

public void MyFunction(char nameport, string code)

{

if (((nameport == 'A') || (nameport == 'a')) && (code.Length == 7))

{

MyPrint(157.3F,24.03F, 6, 0, true);

MyPrint(157.3F, 191.19F, 7, 6, true);

}

if (((nameport == 'B') || (nameport == 'b')) && (code.Length == 8))

{

MyPrint(283F, 106.87F, 8, 0, false);

}

// нужно подшаманить!

if (((nameport == 'C') || (nameport == 'c')) && (code.Length == 8))

{

MyPrint(157.3F, 204.95F, 4, 0, true);

MyPrint(283F, 246F, 8, 4, false);

}

// тоже подшаманить!

if (((nameport == 'D') || (nameport == 'd')) && (code.Length == 8))

{

MyPrint(157.3F, 260.74F, 2, 0, true);

MyPrint(283F, 273.67F, 4, 2, false);

MyPrint(283F, 190.02F, 8, 4, false);

}

if (((nameport == 'E') || (nameport == 'e')) && (code.Length == 3))

{

MyPrint(157.3F, 107.7F, 3, 0, true);

}

}

private void textBox1_KeyDown(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys. Enter)

button1.PerformClick();

}

}

}


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: