Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Frame color of a textbox?

Frame color of a textbox?

Scheduled Pinned Locked Moved C#
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Martin 0
    wrote on last edited by
    #1

    How can I change the Frame color of a textbox?

    C M 2 Replies Last reply
    0
    • M Martin 0

      How can I change the Frame color of a textbox?

      C Offline
      C Offline
      CWinThread
      wrote on last edited by
      #2

      I was wondering the same thing myself, and ended up just changing the BorderStyle to None, and drawing a simple border myself in the parent form/user control with a function like:

      private void DrawTextBoxBorder(Graphics g)
      {
          Rectangle rectClient = myTextBox.ClientRectangle;
          Rectangle rect = myTextBox.RectangleToScreen(rectClient);
          rect.Offset(-1,-1);
          rect.Width += 1;
          rect.Height += 1;
      
          Point ptClient = new Point(0,0);
          Point ptScreen = PointToScreen(ptClient);
          rect.Offset(-ptScreen.X, -ptScreen.Y);
      
          g.DrawRectangle(Pens.SlateGray, rect);
      }
      
      1 Reply Last reply
      0
      • M Martin 0

        How can I change the Frame color of a textbox?

        M Offline
        M Offline
        Mohamad Al Husseiny
        wrote on last edited by
        #3

        Inherit your class from TextBox Overrid OnPaint and set ControlStyle to UserPaint use The Following Class as start

        public class TextBoxEx :TextBox
        {
        private Color borderColor;
        public TextBoxEx()
        {
        	this.SetStyle(ControlStyles.UserPaint,true);
        	this.BorderStyle=BorderStyle.FixedSingle;
        	borderColor=Color.Red;
        
        }
        public Color BorderColor
        {
        	get
        	{
        		return borderColor;
        	}
        	set
        	{
        		borderColor=value;
        	}
        }
        protected override void OnBorderStyleChanged(EventArgs e)
        {
        	this.BorderStyle=BorderStyle.FixedSingle;
        	base.OnBorderStyleChanged (e);
        }
        
        protected override void OnPaint(PaintEventArgs e)
        {
        	base.OnPaint (e);
        	ControlPaint.DrawBorder
        		(e.Graphics,e.ClipRectangle,borderColor,ButtonBorderStyle.Solid);
        	
        }
        

        MCAD

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups