TextBox text color
-
Does anyone know if it is possible to change the colour of the text in a text box? I have tried textBox1.forecolor = System.drawing.color.red; and also changing the color in the textbox properties but it doesn't seem to work! Am I missing something? Thanks Paddy
-
Does anyone know if it is possible to change the colour of the text in a text box? I have tried textBox1.forecolor = System.drawing.color.red; and also changing the color in the textbox properties but it doesn't seem to work! Am I missing something? Thanks Paddy
Hmmm... Your question caught me as setting the ForeColor property in the designer should work, in fact it works on my box :confused:. However if you would like to change the color programtically you can do:
this.textBox1.ForeColor = Color.Aqua;
You should see call kinds of different colors in the intellisence once you type
Color.
You may also need to prependthis.
in front of yourtextBox1
HTH Nick Parker -
Hmmm... Your question caught me as setting the ForeColor property in the designer should work, in fact it works on my box :confused:. However if you would like to change the color programtically you can do:
this.textBox1.ForeColor = Color.Aqua;
You should see call kinds of different colors in the intellisence once you type
Color.
You may also need to prependthis.
in front of yourtextBox1
HTH Nick Parker -
Thanks for the quick reply Nick. I don't know why it wont work for me! Do you need to add Using Systems.color or anything like that at the start of your code? Paddy
Try pasting this code in exactly, I just made this up really quickly.
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace ChangeColor { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBox1 // this.textBox1.ForeColor = System.Drawing.Color.Aqua; this.textBox1.Location = new System.Drawing.Point(72, 80); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(104, 20); this.textBox1.TabIndex = 0; this.textBox1.Text = "textBox1"; // // button1 // this.button1.Location = new System.Drawing.Point(16, 128); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(104, 24); this.button1.TabIndex = 1; this.button1.Text = "Change To Red"; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(128, 128); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(104, 24); this.button2.TabIndex = 2; this.button2.Text = "Change To Green"; this.button2.Click += new System.EventHandler(this.button2_Click);
-
Try pasting this code in exactly, I just made this up really quickly.
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace ChangeColor { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBox1 // this.textBox1.ForeColor = System.Drawing.Color.Aqua; this.textBox1.Location = new System.Drawing.Point(72, 80); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(104, 20); this.textBox1.TabIndex = 0; this.textBox1.Text = "textBox1"; // // button1 // this.button1.Location = new System.Drawing.Point(16, 128); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(104, 24); this.button1.TabIndex = 1; this.button1.Text = "Change To Red"; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(128, 128); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(104, 24); this.button2.TabIndex = 2; this.button2.Text = "Change To Green"; this.button2.Click += new System.EventHandler(this.button2_Click);
Thanks for the help. I'm in poxy work at the moment with no visual studio so I wont get a chance to try adding it to my code till lunch time! Do you know if the textBox.ForeColor changes all the text in the texbox or can I make different words different colors by changing the forecolor before I append text to the texbox? Thanks, Paddy.
-
Thanks for the help. I'm in poxy work at the moment with no visual studio so I wont get a chance to try adding it to my code till lunch time! Do you know if the textBox.ForeColor changes all the text in the texbox or can I make different words different colors by changing the forecolor before I append text to the texbox? Thanks, Paddy.
Paddy wrote: Do you know if the textBox.ForeColor changes all the text in the texbox or can I make different words different colors by changing the forecolor before I append text to the texbox? If you wish to use different colors for different words you would have to use a control such as the RichTextBox control which supports formatting. The text field is only a single color unless you make your own text control and draw it yourself. Rocky Moore
-
Paddy wrote: Do you know if the textBox.ForeColor changes all the text in the texbox or can I make different words different colors by changing the forecolor before I append text to the texbox? If you wish to use different colors for different words you would have to use a control such as the RichTextBox control which supports formatting. The text field is only a single color unless you make your own text control and draw it yourself. Rocky Moore
-
You just declare a RichTextBox object or you could find it in the Toolbox. To change the color/font or something you just use SelectionFont/SelectionColor property to change the color/font of selected text. Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!
-
You just declare a RichTextBox object or you could find it in the Toolbox. To change the color/font or something you just use SelectionFont/SelectionColor property to change the color/font of selected text. Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!
-
Paddy wrote: doesn't sound to difficult. Believe me! It's too easy! :) Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!
-
Paddy wrote: doesn't sound to difficult. Believe me! It's too easy! :) Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!