Свойства - C# (204636)
Формулировка задачи:
Помогите люди добрые, мне в код нужно добавить свойства, а я понятия не имею как это сделать!
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.Name = "Address Form";
this.street_box.Location = new System.Drawing.Point(0, 50);
this.street_box.Width += 50;
this.house_box.Location = new System.Drawing.Point(0, 100);
this.index_box.Location = new System.Drawing.Point(0, 150);
this.error_label.ForeColor = System.Drawing.Color.Red;
this.error_label.Location = new System.Drawing.Point(Width / 2, Height / 2);
Button check_button = new Button();
check_button.Text = "Check";
check_button.Click += OnCheckButton_click;
check_button.Location = new System.Drawing.Point(150, 0);
this.Controls.AddRange (new Control[]
{city_box, street_box, house_box, index_box, error_label, check_button});
this.Show ();
}
private void OnCheckButton_click(object sender, EventArgs e)
{
string error_location = string.Empty;
bool error = false;
if (Regex.IsMatch (city_box.Text, @"^(\w|\d|-|\s)+$") == false)
{
error_location = "City";
error = true;
}
if (error == false && Regex.IsMatch (street_box.Text, @"^(\w|\d|-|\s)+$") == false)
{
error_location = "Street";
error = true;
}
if (error == false && (house_box.Text == string.Empty ||
house_box.Text.Any((x) => Char.IsDigit(x) == false)))
{
error_location = "House";
error = true;
}
if (error == false && (index_box.Text == string.Empty ||
index_box.Text.Any ((x) => Char.IsDigit (x) == false)))
{
error_location = "Index";
error = true;
}
if (error == true)
{
error_label.Text = "Error in " + error_location;
error_label.Show ();
}
else
{
error_label.Hide ();
}
}
private TextBox city_box = new TextBox();
private TextBox street_box = new TextBox();
private TextBox house_box = new TextBox();
private TextBox index_box = new TextBox();
private Label error_label = new Label();
}
class Program
{
static void Main()
{
Application.Run (new Form1());
}
}
}
Решение задачи: «Свойства»
textual
Листинг программы
public double heightPole;// это поле public double height{// это свойство get{return height;}//получаем значение поля , если надо можно вызвать функцию перевода из одной системы измерения в другую set{heightPole=value; redraw();}// записываем значение , и перерисовываем окно }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д