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


           

Required for Windows Form Designer


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.
Закрыть окно
Содержание  Назад  Вперед