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

         

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


На этой форме подготавливается сообщение к отправке. Значения свойства Name элементов управления приведены на рис. 3.34.


увеличить изображение
Рис. 3.34.  Форма SendMessage

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

Листинг 3.26.

(html, txt)


} #endregion

private void btnViewAttach_Click(object sender, System.EventArgs e) { if(oFDAttach.ShowDialog() != DialogResult.OK) return; txbAttach.Text = oFDAttach.FileName; }

private void btnAddAttach_Click(object sender, System.EventArgs e) { MailAttachment attach = new MailAttachment(oFDAttach.FileName); message.Attachments.Add(attach); txbAttach.Text = ""; oFDAttach.FileName = String.Empty; this.AddAttachmentsToPanel(); }

private void AddAttachmentsToPanel() { pblAttachments.Controls.Clear(); for(int i = message.Attachments.Count -1; i >= 0; i--) { MailAttachment attach = (MailAttachment)message.Attachments[i]; Label lblNumber = new Label(); Label lblAttachName = new Label(); lblNumber.Text = String.Format("#{0}", i + 1); lblAttachName.Text = attach.Filename; lblAttachName.TextAlign = lblNumber.TextAlign = ContentAlignment.MiddleLeft; lblAttachName.Anchor = lblNumber.Anchor = AnchorStyles.Top | AnchorStyles.Left; lblNumber.Location = new Point(15, i*25); lblAttachName.Location = new Point(50, i*25); lblNumber.Size = new Size(20, 20); lblAttachName.Size = new Size(500, 20); lblNumber.ContextMenu = lblAttachName.ContextMenu = contextMenuDeleteAttach; lblNumber.Tag = lblAttachName.Tag = i; pblAttachments.Controls.Add(lblNumber); pblAttachments.Controls.Add(lblAttachName); } }

private void itemDeleteAttach_Click(object sender, System.EventArgs e) { MenuItem item = (MenuItem)sender; ContextMenu menu = (ContextMenu)item.Parent; Label source = (Label)menu.SourceControl; object o = source.Tag; int i = Int32.Parse(o.ToString()); message.Attachments.RemoveAt(i); this.AddAttachmentsToPanel(); }

private void btnSend_Click(object sender, System.EventArgs e) { message.BodyFormat = MailFormat.Text; message.Body = txbBody.Text; message.Cc = txbCopy.Text; message.Bcc = txbBlindCopy.Text; message.Subject = txbSubject.Text; message.To = txbTo.Text; message.From = ((UserIdentity)Thread.CurrentPrincipal.Identity).Mail; Mail.MailSender mailSender = new Mail.MailSender(((UserIdentity)Thread.CurrentPrincipal.Identity).Smtp); mailSender.Send(message, ((UserIdentity)Thread.CurrentPrincipal.Identity).Password); MessageBox.Show("Ваше сообщение отправлено."); this.Close(); } } }

Листинг 3.26.


Содержание раздела