Студопедия

Главная страница Случайная страница

Разделы сайта

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Листинг П1-3. Файл ch05\SimpleNotepad\RegisterForm.cs






using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace SimpleNotepad
{
/// < summary>
/// Summary description for RegisterForm.
/// < /summary>
public class RegisterForm: System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBoxName;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBoxEmail;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox comboBoxLevel;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton3;
private System.Windows.Forms.RadioButton radioButton4;
private System.Windows.Forms.RadioButton radioButton5;
private System.Windows.Forms.TextBox textBoxFavoriteOS;
private System.Windows.Forms.MonthCalendar monthCalendar1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.CheckBox checkBoxSendNews;
private System.Windows.Forms.CheckBox checkBoxSendLetter;
private System.Windows.Forms.TextBox textBoxComment;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.GroupBox groupBoxGender;
private System.Windows.Forms.GroupBox groupBoxOS;
private System.Windows.Forms.ErrorProvider errorProvider1;
/// < summary>
/// Required designer variable.
/// < /summary>
private System.ComponentModel.Container components = null;

public RegisterForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}

/// < summary>
/// Clean up any resources being used.
/// < /summary>
protected override void Dispose(bool disposing)
{
if(disposing)
{
if(components! = null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code
/// < summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// < /summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBoxName = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBoxEmail = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.comboBoxLevel = new System.Windows.Forms.ComboBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.groupBoxGender = new System.Windows.Forms.GroupBox();
this.groupBoxOS = new System.Windows.Forms.GroupBox();
this.textBoxFavoriteOS = new System.Windows.Forms.TextBox();
this.radioButton5 = new System.Windows.Forms.RadioButton();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.monthCalendar1 = new
System.Windows.Forms.MonthCalendar();
this.label4 = new System.Windows.Forms.Label();
this.checkBoxSendNews = new System.Windows.Forms.CheckBox();
this.checkBoxSendLetter = new System.Windows.Forms.CheckBox();
this.textBoxComment = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.errorProvider1 = new
System.Windows.Forms.ErrorProvider();
this.groupBoxGender.SuspendLayout();
this.groupBoxOS.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.Control;
this.button1.DialogResult =
System.Windows.Forms.DialogResult.Yes;
this.button1.Location = new System.Drawing.Point(117, 480);
this.button1.Name = " button1";
this.button1.Size = new System.Drawing.Size(112, 23);
this.button1.TabIndex = 0;
this.button1.Text = " Зарегистрировать";
//
// button2
//
this.button2.BackColor = System.Drawing.SystemColors.Control;
this.button2.DialogResult =
System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(253, 480);
this.button2.Name = " button2";
this.button2.Size = new System.Drawing.Size(112, 23);
this.button2.TabIndex = 1;
this.button2.Text = " Отменить";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(108, 56);
this.textBoxName.Name = " textBoxName";
this.textBoxName.Size = new System.Drawing.Size(121, 20);
this.textBoxName.TabIndex = 2;
this.textBoxName.Text = " ";
this.textBoxName.Validating +=
new System.ComponentModel.CancelEventHandler(
this.textBoxName_Validating);
//
// label1
//
this.label1.Font = new System.Drawing.Font(" Arial", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
this.label1.Location = new System.Drawing.Point(29, 8);
this.label1.Name = " label1";
this.label1.Size = new System.Drawing.Size(424, 32);
this.label1.TabIndex = 3;
this.label1.Text = " Зарегистрируйте свою копию программы";
//
// label2
//
this.label2.Location = new System.Drawing.Point(48, 56);
this.label2.Name = " label2";
this.label2.Size = new System.Drawing.Size(48, 23);
this.label2.TabIndex = 4;
this.label2.Text = " Ф. И. О.";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 88);
this.label3.Name = " label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 5;
this.label3.Text = " Адрес E-Mail: ";
this.label3.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// textBoxEmail
//
this.textBoxEmail.Location =
new System.Drawing.Point(108, 88);
this.textBoxEmail.Name = " textBoxEmail";
this.textBoxEmail.Size = new System.Drawing.Size(121, 20);
this.textBoxEmail.TabIndex = 6;
this.textBoxEmail.Text = " ";
this.textBoxEmail.Validating +=
new System.ComponentModel.CancelEventHandler(
this.textBoxEmail_Validating);
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 120);
this.label5.Name = " label5";
this.label5.Size = new System.Drawing.Size(88, 16);
this.label5.TabIndex = 9;
this.label5.Text = " Квалификация: ";
this.label5.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// comboBoxLevel
//
this.comboBoxLevel.Items.AddRange(new object[] {
" Начальная",
" Средняя",
" Высокая",
" Специалист",
" Эксперт" });
this.comboBoxLevel.Location =
new System.Drawing.Point(108, 120);
this.comboBoxLevel.Name = " comboBoxLevel";
this.comboBoxLevel.Size = new System.Drawing.Size(121, 21);
this.comboBoxLevel.TabIndex = 10;
this.comboBoxLevel.Text = " Начальная";
//
// radioButton1
//
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(16, 16);
this.radioButton1.Name = " radioButton1";
this.radioButton1.Size = new System.Drawing.Size(48, 24);
this.radioButton1.TabIndex = 12;
this.radioButton1.TabStop = true;
this.radioButton1.Text = " Муж.";
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(64, 16);
this.radioButton2.Name = " radioButton2";
this.radioButton2.Size = new System.Drawing.Size(48, 24);
this.radioButton2.TabIndex = 13;
this.radioButton2.Text = " Жен.";
//
// groupBoxGender
//
this.groupBoxGender.Controls.AddRange(new System.Windows.Forms.Control[] {
this.radioButton2,
this.radioButton1});
this.groupBoxGender.Location =
new System.Drawing.Point(253, 56);
this.groupBoxGender.Name = " groupBoxGender";
this.groupBoxGender.Size = new System.Drawing.Size(176, 48);
this.groupBoxGender.TabIndex = 14;
this.groupBoxGender.TabStop = false;
this.groupBoxGender.Text = " Пол";
//
// groupBoxOS
//
this.groupBoxOS.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBoxFavoriteOS,
this.radioButton5,
this.radioButton4,
this.radioButton3});
this.groupBoxOS.Location = new System.Drawing.Point(253, 112);
this.groupBoxOS.Name = " groupBoxOS";
this.groupBoxOS.Size = new System.Drawing.Size(176, 144);
this.groupBoxOS.TabIndex = 15;
this.groupBoxOS.TabStop = false;
this.groupBoxOS.Text = " Любимая ОС";
//
// textBoxFavoriteOS
//
this.textBoxFavoriteOS.Enabled = false;
this.textBoxFavoriteOS.Location =
new System.Drawing.Point(40, 104);
this.textBoxFavoriteOS.Name = " textBoxFavoriteOS";
this.textBoxFavoriteOS.TabIndex = 3;
this.textBoxFavoriteOS.Text = " ";
//
// radioButton5
//
this.radioButton5.Location = new System.Drawing.Point(16, 72);
this.radioButton5.Name = " radioButton5";
this.radioButton5.Size = new System.Drawing.Size(152, 24);
this.radioButton5.TabIndex = 2;
this.radioButton5.Text = " Другая (укажите, какая)";
this.radioButton5.CheckedChanged +=
new System.EventHandler(this.radioButton5_CheckedChanged);
//
// radioButton4
//
this.radioButton4.Location = new System.Drawing.Point(16, 48);
this.radioButton4.Name = " radioButton4";
this.radioButton4.Size = new System.Drawing.Size(64, 24);
this.radioButton4.TabIndex = 1;
this.radioButton4.Text = " Linux";
//
// radioButton3
//
this.radioButton3.Checked = true;
this.radioButton3.Location = new System.Drawing.Point(16, 24);
this.radioButton3.Name = " radioButton3";
this.radioButton3.Size = new System.Drawing.Size(88, 24);
this.radioButton3.TabIndex = 0;
this.radioButton3.TabStop = true;
this.radioButton3.Text = " MS Windows";
//
// monthCalendar1
//
this.monthCalendar1.Location =
new System.Drawing.Point(37, 184);
this.monthCalendar1.MaxSelectionCount = 1;
this.monthCalendar1.Name = " monthCalendar1";
this.monthCalendar1.TabIndex = 16;
//
// label4
//
this.label4.Location = new System.Drawing.Point(37, 160);
this.label4.Name = " label4";
this.label4.Size = new System.Drawing.Size(152, 16);
this.label4.TabIndex = 17;
this.label4.Text = " День Вашего рождения: ";
//
// checkBoxSendNews
//
this.checkBoxSendNews.Checked = true;
this.checkBoxSendNews.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxSendNews.Location =
new System.Drawing.Point(253, 288);
this.checkBoxSendNews.Name = " checkBoxSendNews";
this.checkBoxSendNews.Size = new System.Drawing.Size(152, 16);
this.checkBoxSendNews.TabIndex = 18;
this.checkBoxSendNews.Text = " Подписка на новости";
//
// checkBoxSendLetter
//
this.checkBoxSendLetter.Checked = true;
this.checkBoxSendLetter.CheckState =
System.Windows.Forms.CheckState.Checked;
this.checkBoxSendLetter.Location = new
System.Drawing.Point(253, 304);
this.checkBoxSendLetter.Name = " checkBoxSendLetter";
this.checkBoxSendLetter.Size =
new System.Drawing.Size(168, 32);
this.checkBoxSendLetter.TabIndex = 19;
this.checkBoxSendLetter.Text = " Подписка на электронную газету";
//
// textBoxComment
//
this.textBoxComment.Location =
new System.Drawing.Point(77, 384);
this.textBoxComment.Multiline = true;
this.textBoxComment.Name = " textBoxComment";
this.textBoxComment.Size = new System.Drawing.Size(328, 72);
this.textBoxComment.TabIndex = 20;
this.textBoxComment.Text = " ";
//
// label6
//
this.label6.Location = new System.Drawing.Point(77, 360);
this.label6.Name = " label6";
this.label6.Size = new System.Drawing.Size(208, 23);
this.label6.TabIndex = 21;
this.label6.Text = " Оставьте Ваш комментарий: ";
//
// errorProvider1
//
this.errorProvider1.DataMember = null;
//
// RegisterForm
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.button2;
this.ClientSize = new System.Drawing.Size(482, 519);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label6,
this.textBoxComment,
this.checkBoxSendLetter,
this.checkBoxSendNews,
this.label4,
this.monthCalendar1,
this.groupBoxOS,
this.comboBoxLevel,
this.label5,
this.textBoxEmail,
this.label3,
this.label2,
this.label1,
this.textBoxName,
this.button2,
this.button1,
this.groupBoxGender});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = " RegisterForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = " Регистрация программы";
this.groupBoxGender.ResumeLayout(false);
this.groupBoxOS.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

private void radioButton5_CheckedChanged(object sender, System.EventArgs e)
{
RadioButton rb = (RadioButton)sender;
if(rb.Checked)
textBoxFavoriteOS.Enabled = true;
else
textBoxFavoriteOS.Enabled = false;
}

private void textBoxName_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if(textBoxName.Text.Length == 0)
{
errorProvider1.SetError(textBoxName, " Не указано имя");
}
else
errorProvider1.SetError(textBoxName, " ");
}

private void textBoxEmail_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
string email = textBoxEmail.Text;

if(email.IndexOf('@') == -1 || email.IndexOf('.') == -1)
{
errorProvider1.SetError(textBoxEmail,
" Неправильный адрес E-Mail");
}
else
errorProvider1.SetError(textBoxEmail, " ");
}

public string UserName
{
get
{
return textBoxName.Text;
}
}

public string UserEmail
{
get
{
return textBoxEmail.Text;
}
}

public string UserLevel
{
get
{
return comboBoxLevel.Text;
}
}

public string UserComment
{
get
{
return textBoxComment.Text;
}
}

public string UserGender
{
get
{
for(int i=0; i < groupBoxGender.Controls.Count; i++)
{
RadioButton rb = (RadioButton)groupBoxGender.Controls[i];
if(rb.Checked)
return rb.Text;
}
return " ";
}
}

public string FavoriteOS
{
get
{
for(int i=0; i < groupBoxOS.Controls.Count; i++)
{
if(groupBoxOS.Controls[i] is RadioButton)
{
RadioButton rb = (RadioButton)groupBoxOS.Controls[i];

if(rb.Checked)
{
if(rb.Name! = radioButton5.Name)
return rb.Text;
else
return textBoxFavoriteOS.Text;
}
}
}
return " ";
}
}

public string SendNews
{
get
{
if(checkBoxSendNews.Checked)
return " Yes";
else
return " No";
}
}

public string SendLetter
{
get
{
if(checkBoxSendLetter.Checked)
return " Yes";
else
return " No";
}
}

public string UserBirthDay
{
get
{
DateTime dt = monthCalendar1.SelectionStart;
return dt.Day + "." + dt.Month + "." + dt.Year;
}
}

}
}






© 2023 :: MyLektsii.ru :: Мои Лекции
Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав.
Копирование текстов разрешено только с указанием индексируемой ссылки на источник.