Создание Windows-приложений на основе Visual C#


           

Третий шаг Мастера. Форма 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.



Содержание  Назад  Вперед