Advertisement
FoxyShadoww

DarkTextBoxWithScroll

Sep 10th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. public class DarkTextBoxScroll : Control
  2.     {
  3.         private static TextBox textBox = new TextBox();
  4.  
  5.         public DarkTextBoxScroll()
  6.         {
  7.             Paint += UserControl1_Paint;
  8.             Resize += UserControl1_Resize;
  9.             textBox.Multiline = true;
  10.             textBox.BorderStyle = BorderStyle.None;
  11.             Controls.Add(textBox);
  12.             textBox.BackColor = Color.FromArgb(22, 22, 22);
  13.             textBox.ForeColor = Color.White;
  14.         }
  15.  
  16.         [DllImport("user32.dll", CharSet = CharSet.Auto)]
  17.         private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
  18.  
  19.         private const int WM_VSCROLL = 0x115;
  20.         private const int SB_BOTTOM = 7;
  21.  
  22.         /// <summary>
  23.         /// Scrolls the vertical scroll bar of a multi-line text box to the bottom.
  24.         /// </summary>
  25.         /// <param name="tb">The text box to scroll</param>
  26.         public static void ScrollToBottom(TextBox tb)
  27.         {
  28.             SendMessage(tb.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero);
  29.         }
  30.  
  31.         /// <summary>
  32.         /// Use this method to scroll the textbox down to the bottom.
  33.         /// </summary>
  34.         public static void Scroll()
  35.         {
  36.             ScrollToBottom(textBox);
  37.         }
  38.  
  39.         /// <summary>
  40.         /// The text property.
  41.         /// </summary>
  42.         public override string Text
  43.         {
  44.             get { return textBox.Text; }
  45.             set { textBox.Text = value; }
  46.         }
  47.  
  48.         /// <summary>
  49.         /// The TextChanged event.
  50.         /// </summary>
  51.         [Browsable(true)]
  52.         public new event EventHandler TextChanged
  53.         {
  54.             add
  55.             {
  56.                 textBox.TextChanged += value;
  57.             }
  58.             remove
  59.             {
  60.                 textBox.TextChanged -= value;
  61.             }
  62.         }
  63.  
  64.         /// <summary>
  65.         /// When you resize the control.
  66.         /// </summary>
  67.         /// <param name="sender"></param>
  68.         /// <param name="e"></param>
  69.         private void UserControl1_Resize(object sender, EventArgs e)
  70.         {
  71.             textBox.Size = new Size(Width - 3, Height - 2);
  72.             textBox.Location = new Point(2, 1);
  73.         }
  74.  
  75.         /// <summary>
  76.         /// Paint the user control.
  77.         /// </summary>
  78.         /// <param name="sender"></param>
  79.         /// <param name="e"></param>
  80.         private void UserControl1_Paint(object sender, PaintEventArgs e)
  81.         {
  82.             // Let's draw a rectangle around the control.
  83.             ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.FromArgb(255, 44, 44, 44), ButtonBorderStyle.Solid);
  84.         }
  85.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement