Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

RUS_-_Karejev_-_Razrabotka_Windows-prilozhenij

.pdf
Скачиваний:
30
Добавлен:
02.02.2015
Размер:
8.19 Mб
Скачать

///the contents of this method with the code editor.

///</summary>

private void InitializeComponent()

{

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CUWStep1)); this.lblEmail = new System.Windows.Forms.Label();

this.txbEmail = new System.Windows.Forms.TextBox(); this.lblMailSample = new System.Windows.Forms.Label(); this.lblAliasSample = new System.Windows.Forms.Label(); this.txbAlias = new System.Windows.Forms.TextBox(); this.lblAlias = new System.Windows.Forms.Label(); this.btnNext = new System.Windows.Forms.Button(); this.SuspendLayout();

//

// lblEmail

//

this.lblEmail.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.lblEmail.Location = new System.Drawing.Point(24, 16); this.lblEmail.Name = "lblEmail";

this.lblEmail.Size = new System.Drawing.Size(240, 23); this.lblEmail.TabIndex = 0;

this.lblEmail.Text = "Введите адрес электронной почты"; this.lblEmail.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

//

// txbEmail

//

this.txbEmail.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.txbEmail.Location = new System.Drawing.Point(24, 48); this.txbEmail.Name = "txbEmail";

this.txbEmail.Size = new System.Drawing.Size(240, 20); this.txbEmail.TabIndex = 1;

this.txbEmail.Text = "";

//

// lblMailSample

//

this.lblMailSample.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.lblMailSample.ForeColor = System.Drawing.SystemColors.AppWorkspace; this.lblMailSample.Location = new System.Drawing.Point(24, 72); this.lblMailSample.Name = "lblMailSample";

this.lblMailSample.Size = new System.Drawing.Size(240, 23); this.lblMailSample.TabIndex = 2;

this.lblMailSample.Text = "Например, address@mail.com"; this.lblMailSample.TextAlign = System.Drawing.ContentAlignment.TopRight;

//

// lblAliasSample

//

this.lblAliasSample.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.lblAliasSample.ForeColor = System.Drawing.SystemColors.AppWorkspace; this.lblAliasSample.Location = new System.Drawing.Point(26, 160); this.lblAliasSample.Name = "lblAliasSample";

this.lblAliasSample.Size = new System.Drawing.Size(240, 23); this.lblAliasSample.TabIndex = 5;

this.lblAliasSample.Text = "Например, Иван Васильевич"; this.lblAliasSample.TextAlign = System.Drawing.ContentAlignment.TopRight;

//

// txbAlias

//

this.txbAlias.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.txbAlias.Location = new System.Drawing.Point(26, 136); this.txbAlias.Name = "txbAlias";

this.txbAlias.Size = new System.Drawing.Size(240, 20); this.txbAlias.TabIndex = 2;

this.txbAlias.Text = "";

//

// lblAlias

//

this.lblAlias.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.lblAlias.Location = new System.Drawing.Point(26, 104); this.lblAlias.Name = "lblAlias";

this.lblAlias.Size = new System.Drawing.Size(240, 23); this.lblAlias.TabIndex = 3;

this.lblAlias.Text = "Введите ваше имя ";

this.lblAlias.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

//

// btnNext

//

this.btnNext.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));

this.btnNext.Location = new System.Drawing.Point(192, 192); this.btnNext.Name = "btnNext";

this.btnNext.TabIndex = 3; this.btnNext.Text = "Далее";

this.btnNext.Click += new System.EventHandler(this.btnNext_Click);

//

// CUWStep1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 238); this.ControlBox = false; this.Controls.Add(this.btnNext); this.Controls.Add(this.lblAliasSample); this.Controls.Add(this.txbAlias); this.Controls.Add(this.txbEmail); this.Controls.Add(this.lblAlias); this.Controls.Add(this.lblMailSample); this.Controls.Add(this.lblEmail);

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "CUWStep1";

this.Text = "Шаг 1 из 3";

this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.ResumeLayout(false);

}

#endregion

private void btnNext_Click(object sender, System.EventArgs e)

{

if(txbEmail.Text == "")

{

MessageBox.Show("Введите адрес электронной почты."); return;

}

else

{

identity.Alias = txbAlias.Text; identity.Mail = txbEmail.Text;

CUWStep2 step2 = new CUWStep2(this.identity); step2.MdiParent = this.MdiParent; this.Close();

step2.Show();

}

}

}

}

Листинг 3.19.

Второй шагМастера. ФормаCUWStep2.cs

Значения свойства Name элементов управления этой формы приведены на рис. 3.28.

Рис. 3.28. Форма CUWStep2

Полный листинг формы:

using System;

using System.Drawing; using System.Collections;

using System.ComponentModel; using System.Windows.Forms;

namespace MailApplication

{

///<summary>

///Summary description for CUWStep2.

/// </summary>

public class CUWStep2 : System.Windows.Forms.Form

{

private UserIdentity identity;

private System.Windows.Forms.Label lblPop3Sample; private System.Windows.Forms.TextBox txbPop3; private System.Windows.Forms.Label lblPop3;

private System.Windows.Forms.Label lblPop3PortSample; private System.Windows.Forms.TextBox txbPop3Port; private System.Windows.Forms.Label lblPop3Port; private System.Windows.Forms.Button btnNext;

///<summary>

///Required designer variable.

///</summary>

private System.ComponentModel.Container components = null;

public CUWStep2(UserIdentity identity)

{

InitializeComponent();

this.identity = identity;

}

///<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()

{

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CUWStep2)); this.lblPop3Sample = new System.Windows.Forms.Label();

this.txbPop3 = new System.Windows.Forms.TextBox(); this.lblPop3 = new System.Windows.Forms.Label(); this.lblPop3PortSample = new System.Windows.Forms.Label(); this.txbPop3Port = new System.Windows.Forms.TextBox(); this.lblPop3Port = new System.Windows.Forms.Label(); this.btnNext = new System.Windows.Forms.Button(); this.SuspendLayout();

//

// lblPop3Sample

//

this.lblPop3Sample.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.lblPop3Sample.ForeColor = System.Drawing.SystemColors.AppWorkspace; this.lblPop3Sample.Location = new System.Drawing.Point(26, 64); this.lblPop3Sample.Name = "lblPop3Sample";

this.lblPop3Sample.Size = new System.Drawing.Size(240, 23); this.lblPop3Sample.TabIndex = 5;

this.lblPop3Sample.Text = "Например, pop3.mail.com"; this.lblPop3Sample.TextAlign = System.Drawing.ContentAlignment.TopRight;

//

// txbPop3

//

this.txbPop3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.txbPop3.Location = new System.Drawing.Point(26, 40); this.txbPop3.Name = "txbPop3";

this.txbPop3.Size = new System.Drawing.Size(240, 20); this.txbPop3.TabIndex = 4;

this.txbPop3.Text = "";

//

// lblPop3

//

this.lblPop3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.lblPop3.Location = new System.Drawing.Point(26, 8); this.lblPop3.Name = "lblPop3";

this.lblPop3.Size = new System.Drawing.Size(240, 23); this.lblPop3.TabIndex = 3;

this.lblPop3.Text = "Введите адрес сервера POP3:"; this.lblPop3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

//

// lblPop3PortSample

//

this.lblPop3PortSample.Anchor = ((System.Windows.Forms.AnchorStyles)(( (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.lblPop3PortSample.ForeColor = System.Drawing.SystemColors.AppWorkspace; this.lblPop3PortSample.Location = new System.Drawing.Point(26, 160); this.lblPop3PortSample.Name = "lblPop3PortSample"; this.lblPop3PortSample.Size = new System.Drawing.Size(240, 23); this.lblPop3PortSample.TabIndex = 8;

this.lblPop3PortSample.Text = "Например, 110"; this.lblPop3PortSample.TextAlign = System.Drawing.ContentAlignment.TopRight;

//

// txbPop3Port

//

this.txbPop3Port.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.txbPop3Port.Location = new System.Drawing.Point(26, 136); this.txbPop3Port.Name = "txbPop3Port";

this.txbPop3Port.Size = new System.Drawing.Size(240, 20); this.txbPop3Port.TabIndex = 7;

this.txbPop3Port.Text = "110";

//

// lblPop3Port

//

this.lblPop3Port.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.lblPop3Port.Location = new System.Drawing.Point(26, 104); this.lblPop3Port.Name = "lblPop3Port";

this.lblPop3Port.Size = new System.Drawing.Size(240, 23); this.lblPop3Port.TabIndex = 6;

this.lblPop3Port.Text = "Укажите почтовый порт:"; this.lblPop3Port.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

//

// btnNext

//

this.btnNext.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));

this.btnNext.Location = new System.Drawing.Point(192, 200); this.btnNext.Name = "btnNext";

this.btnNext.TabIndex = 9; this.btnNext.Text = "Далее";

this.btnNext.Click += new System.EventHandler(this.btnNext_Click);

//

// CUWStep2

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 238); this.Controls.Add(this.btnNext); this.Controls.Add(this.lblPop3PortSample); this.Controls.Add(this.txbPop3Port); this.Controls.Add(this.lblPop3Port); this.Controls.Add(this.lblPop3Sample); this.Controls.Add(this.txbPop3); this.Controls.Add(this.lblPop3);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "CUWStep2";

this.Text = "Шаг 2 из 3";

this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.ResumeLayout(false);

}

#endregion

private void btnNext_Click(object sender, System.EventArgs e)

{

if(txbPop3.Text == "")

{

MessageBox.Show("Введите адрес сервера POP3");

}

else

{

this.identity.Pop3 = txbPop3.Text; try

{

//Преобразовываем введенное значение в тип Int32 this.identity.Pop3Port = Int32.Parse(txbPop3Port.Text); CUWStep3 step3 = new CUWStep3(this.identity); step3.MdiParent = this.MdiParent;

this.Close();

step3.Show();

}

catch(Exception)

{

MessageBox.Show("Значение порта должно быть числом");

}

}

}

}

}

Листинг 3.20.

Третий шагМастера. ФормаCUWStep3.cs

Значения свойства Name элементов управления этой формы приведены на рис. 3.29.

Рис. 3.29. Форма CUWStep3

Полный листинг формы:

using System;

using System.Drawing; using System.Collections;

using System.ComponentModel; using System.Windows.Forms; using System.Threading;

using System.Security.Principal;

namespace MailApplication

{

///<summary>

///Summary description for CUWStep3.

///</summary>

public class CUWStep3 : System.Windows.Forms.Form

{

private UserIdentity identity;

private System.Windows.Forms.Label lblSmtpSample; private System.Windows.Forms.TextBox txbSmtp; private System.Windows.Forms.Label lblSmtp; private System.Windows.Forms.Button btnFinish;

///<summary>

///Required designer variable.

///</summary>

private System.ComponentModel.Container components = null;

public CUWStep3(UserIdentity identity)

{

InitializeComponent(); this.identity = identity;

}

///<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()

{

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CUWStep3)); this.lblSmtpSample = new System.Windows.Forms.Label();

this.txbSmtp = new System.Windows.Forms.TextBox(); this.lblSmtp = new System.Windows.Forms.Label(); this.btnFinish = new System.Windows.Forms.Button(); this.SuspendLayout();

//

// lblSmtpSample

//

this.lblSmtpSample.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.lblSmtpSample.ForeColor = System.Drawing.SystemColors.AppWorkspace; this.lblSmtpSample.Location = new System.Drawing.Point(26, 72); this.lblSmtpSample.Name = "lblSmtpSample";

this.lblSmtpSample.Size = new System.Drawing.Size(240, 23); this.lblSmtpSample.TabIndex = 8;

this.lblSmtpSample.Text = "Например, smtp.mail.com"; this.lblSmtpSample.TextAlign = System.Drawing.ContentAlignment.TopRight;

//

// txbSmtp

//

this.txbSmtp.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.txbSmtp.Location = new System.Drawing.Point(26, 48); this.txbSmtp.Name = "txbSmtp";

this.txbSmtp.Size = new System.Drawing.Size(240, 20); this.txbSmtp.TabIndex = 7;

this.txbSmtp.Text = "";

//

// lblSmtp

//

this.lblSmtp.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right))); this.lblSmtp.Location = new System.Drawing.Point(26, 16); this.lblSmtp.Name = "lblSmtp";

this.lblSmtp.Size = new System.Drawing.Size(240, 23); this.lblSmtp.TabIndex = 6;

this.lblSmtp.Text = "Введите адрес SMTP-сервера:"; this.lblSmtp.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

//

// btnFinish

//

this.btnFinish.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));

this.btnFinish.Location = new System.Drawing.Point(200, 208); this.btnFinish.Name = "btnFinish";

this.btnFinish.TabIndex = 9; this.btnFinish.Text = "Готово";

this.btnFinish.Click += new System.EventHandler(this.btnFinish_Click);

//

// CUWStep3

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.btnFinish); this.Controls.Add(this.lblSmtpSample); this.Controls.Add(this.txbSmtp); this.Controls.Add(this.lblSmtp);

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "CUWStep3";

this.Text = "Шаг 3 из 3";

this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.ResumeLayout(false);

}

#endregion

private void btnFinish_Click(object sender, System.EventArgs e)

{

if(txbSmtp.Text != "")

{

this.identity.Smtp = txbSmtp.Text; //Закрываем текущую форму this.Close();

Thread.CurrentPrincipal = new GenericPrincipal(this.identity, new string[]{"user"}); this.identity.Dispose();

//Закрываем родительскую форму CreateUserWizard Form.ActiveForm.Close();

}

else

{

MessageBox.Show("Введите адрес сервера SMTP");

}

}

}

}

Листинг 3.21.

Главная формаmainForm.cs

Главная форма программы представляет собой контейнер для других форм и поэтому содержит сравнительно мало элементов управления. Значения свойства Name элементов управления приведены на рис. 3.30.

Рис. 3.30. Форма mainForm

Полный листинг формы:

using System;

using System.Drawing; using System.Collections;

using System.ComponentModel; using System.Windows.Forms; using System.Data;

using System.Threading;

using System.Security.Principal;

namespace MailApplication

{

///<summary>

///Summary description for Form1.

///</summary>

public class mainForm : System.Windows.Forms.Form

{

private System.Windows.Forms.MainMenu mainMenu; private System.Windows.Forms.MenuItem itemFile; private System.Windows.Forms.MenuItem itemUsers; private System.Windows.Forms.MenuItem itemNewUser; private System.Windows.Forms.MenuItem itemExit; private System.Windows.Forms.MenuItem itemEvent; private System.Windows.Forms.MenuItem itemGet; private System.Windows.Forms.MenuItem itemSend; private System.Windows.Forms.MenuItem itemSetting;

///<summary>

///Required designer variable.

///</summary>

private System.ComponentModel.Container components = null;

public mainForm()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

///<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()

{

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(mainForm)); this.mainMenu = new System.Windows.Forms.MainMenu();

this.itemFile = new System.Windows.Forms.MenuItem(); this.itemNewUser = new System.Windows.Forms.MenuItem(); this.itemUsers = new System.Windows.Forms.MenuItem(); this.itemExit = new System.Windows.Forms.MenuItem(); this.itemEvent = new System.Windows.Forms.MenuItem(); this.itemGet = new System.Windows.Forms.MenuItem(); this.itemSend = new System.Windows.Forms.MenuItem(); this.itemSetting = new System.Windows.Forms.MenuItem();

//

// mainMenu

//

this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.itemFile, this.itemEvent});

//

// itemFile

//

this.itemFile.Index = 0;

this.itemFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.itemNewUser, this.itemUsers, this.itemExit});

this.itemFile.Text = "Файл";

//

//itemNewUser

this.itemNewUser.Index = 0;

this.itemNewUser.Shortcut = System.Windows.Forms.Shortcut.CtrlN; this.itemNewUser.Text = "Новый пользователь";

this.itemNewUser.Click += new System.EventHandler(this.itemNewUser_Click);

//itemUsers

//

this.itemUsers.Index = 1;

this.itemUsers.Shortcut = System.Windows.Forms.Shortcut.CtrlL; this.itemUsers.Text = "Смена пользователя";

this.itemUsers.Click += new System.EventHandler(this.itemUsers_Click);

//

//itemExit

this.itemExit.Index = 2;

this.itemExit.Shortcut = System.Windows.Forms.Shortcut.AltF4; this.itemExit.Text = "Выход";

this.itemExit.Click += new System.EventHandler(this.itemExit_Click);

//itemEvent

//

this.itemEvent.Enabled = false; this.itemEvent.Index = 1;

this.itemEvent.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.itemGet, this.itemSend, this.itemSetting});

this.itemEvent.Text = "Действия";

//

//itemGet

this.itemGet.Index = 0;

this.itemGet.Shortcut = System.Windows.Forms.Shortcut.CtrlG; this.itemGet.Text = "Получить почту";

this.itemGet.Click += new System.EventHandler(this.itemGet_Click);

//itemSend

//

this.itemSend.Index = 1;

this.itemSend.Shortcut = System.Windows.Forms.Shortcut.CtrlS; this.itemSend.Text = "Отправить письмо";

this.itemSend.Click += new System.EventHandler(this.itemSend_Click);

//

// itemSetting

//

this.itemSetting.Index = 2;

this.itemSetting.Shortcut = System.Windows.Forms.Shortcut.CtrlO; this.itemSetting.Text = "Настройки";

this.itemSetting.Visible = false;

//

// mainForm

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(792, 545); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.IsMdiContainer = true;

this.Menu = this.mainMenu; this.Name = "mainForm"; this.Text = "Ballet";

this.Closing += new System.ComponentModel.CancelEventHandler(this.mainForm_Closing); this.Load += new System.EventHandler(this.itemUsers_Click);

}

#endregion

///<summary>

///The main entry point for the application.

///</summary>

[STAThread]

static void Main()

{

Application.Run(new mainForm());

}

private void itemExit_Click(object sender, System.EventArgs e)

{

this.Close();

}

private void itemUsers_Click(object sender, System.EventArgs e)

{

selectUser select = new selectUser(); if(select.ShowDialog() != DialogResult.OK)

//Запускаем главную форму. return;

if(Thread.CurrentPrincipal.Identity is UserIdentity) ((UserIdentity)Thread.CurrentPrincipal.Identity).Dispose();

string userName = select.lstViewUsers.SelectedItems[0].Text; UserIdentity identity = new UserIdentity(userName);

Thread.CurrentPrincipal = new GenericPrincipal(identity, new string[]{"user"}); //Вызываем метод ActivateEventItem

this.ActivateEventItem();

}

private void ActivateEventItem()

{

//Включаем доступность пункта меню "Действия". this.itemEvent.Enabled = true;

}

private void itemNewUser_Click(object sender, System.EventArgs e)

{

//Создаем экземпляр wizard формы CreateUserWizard CreateUserWizard wizard = new CreateUserWizard(); //Показываем форму:

wizard.ShowDialog(); if(Thread.CurrentPrincipal != null)

this.ActivateEventItem();

}

private void mainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)

{

if(Thread.CurrentPrincipal.Identity is UserIdentity) ((UserIdentity)Thread.CurrentPrincipal.Identity).Dispose();

}

private void itemSend_Click(object sender, System.EventArgs e)

{

PasswordPromt pass = new PasswordPromt(); if(pass.ShowDialog() != DialogResult.OK)

return;

SendMessage send = new SendMessage(); send.MdiParent = this;

send.Show();

}

private void itemGet_Click(object sender, System.EventArgs e)

{

PasswordPromt pass = new PasswordPromt(); if(pass.ShowDialog() != DialogResult.OK)

return;

MessageList list = new MessageList(); list.MdiParent = this;

list.Show();

}

}

}

Листинг 3.22.

Формасписка сообщенийMessageList.cs

Значения свойства Name элементов управления этой формы приведены на рис. 3.31.

увеличить изображение

Рис. 3.31. Форма MessageList

Полный листинг формы:

using System;

using System.Drawing; using System.Collections;

using System.ComponentModel; using System.Windows.Forms;

namespace MailApplication

{

///<summary>

///Summary description for MessageList.

///</summary>

public class MessageList : System.Windows.Forms.Form

{

private Mail.Providers.Pop3 mail; private UserIdentity identity;

private System.Windows.Forms.ListView lstViewMessages; private System.Windows.Forms.ColumnHeader colFrom; private System.Windows.Forms.ColumnHeader colSubject; private System.Windows.Forms.ColumnHeader colDate; private System.Windows.Forms.ImageList imageListIcons; private System.Windows.Forms.ColumnHeader colIcon; private System.Windows.Forms.Label lblMessagesCount; private System.Windows.Forms.Panel pnlPages;

private System.ComponentModel.IContainer components;

public MessageList()

{

InitializeComponent();

identity = (UserIdentity)System.Threading.Thread.CurrentPrincipal.Identity; // Создание объекта POP3.

if(identity.Pop3Port == -1)

mail = new Mail.Providers.Pop3(identity.Pop3); else

mail = new Mail.Providers.Pop3(identity.Pop3, identity.Pop3Port);

}

///<summary>

///Clean up any resources being used.

///</summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]