Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. //using System.Windows.Forms;
  2.  
  3. DialogResult ShowMessage(string text, string caption = "")
  4. {
  5.     var result = DialogResult.None;
  6.     using (Form frm = new Form())
  7.     {
  8.         frm.Text = caption;
  9.         frm.MinimumSize = new Size(350, 250);
  10.         frm.SizeGripStyle = SizeGripStyle.Hide;
  11.         Button btn = new Button();
  12.         frm.Controls.Add(btn);
  13.         btn.Left = frm.ClientSize.Width - btn.Width - btn.Margin.Right;
  14.         btn.Top = frm.ClientSize.Height - btn.Height - btn.Margin.Bottom;
  15.         btn.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
  16.         btn.Text = "OK";
  17.         btn.DialogResult = DialogResult.OK;
  18.         btn.Click += (s, e) => { ((Control)s).FindForm().Close(); };
  19.         TextBox tb = new TextBox();
  20.         frm.Controls.Add(tb);
  21.         tb.Multiline = true;
  22.         tb.ReadOnly = true;
  23.         tb.BackColor = SystemColors.Window;
  24.         tb.SetBounds(0, 0, frm.ClientSize.Width, btn.Top - btn.Margin.Top);
  25.         tb.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
  26.         tb.ScrollBars = ScrollBars.Both;
  27.         tb.Text = text;              
  28.         result = frm.ShowDialog();
  29.     }
  30.     return result;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement