Change the borderColor of the TextBox
try this
bool focus = false;
private void Form1_Paint(object sender, PaintEventArgs e)
{
if (focus)
{
textBox1.BorderStyle = BorderStyle.None;
Pen p = new Pen(Color.Red);
Graphics g = e.Graphics;
int variance = 3;
g.DrawRectangle(p, new Rectangle(textBox1.Location.X - variance, textBox1.Location.Y - variance, textBox1.Width + variance, textBox1.Height +variance ));
}
else
{
textBox1.BorderStyle = BorderStyle.FixedSingle;
}
}
private void textBox1_Enter(object sender, EventArgs e)
{
focus = true;
this.Refresh();
}
private void textBox1_Leave(object sender, EventArgs e)
{
focus = false;
this.Refresh();
}
Change the border color of textbox in c# winforms - Newbie
Try creating your own textBox using the UserControl. Here is a sample that will get you started:
public partial class UserControl1 : UserControl
{
private string text;
public string Text
{
get { return textBox.Text; }
set { textBox.Text = value; }
}
TextBox textBox = new TextBox();
public UserControl1()
{
InitializeComponent();
this.Paint += new PaintEventHandler(UserControl1_Paint);
this.Resize += new EventHandler(UserControl1_Resize);
textBox.Multiline = true;
textBox.BorderStyle = BorderStyle.None;
this.Controls.Add(textBox);
}
private void UserControl1_Resize(object sender, EventArgs e)
{
textBox.Size = new Size(this.Width - 3, this.Height - 2);
textBox.Location = new Point(2, 1);
}
private void UserControl1_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);
}
}
Change border color in TextBox C#
You have to draw text manually as well.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Pen penBorder = new Pen(Color.Gray, 1);
Rectangle rectBorder = new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1);
e.Graphics.DrawRectangle(penBorder, rectBorder);
Rectangle textRec = new Rectangle(e.ClipRectangle.X + 1, e.ClipRectangle.Y + 1, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1);
TextRenderer.DrawText(e.Graphics, Text, this.Font, textRec, this.ForeColor, this.BackColor, TextFormatFlags.Default);
}
Alternatively you can try to use e.Graphics.DrawString()
method if TextRenderer
is not giving you desired results (I always have better results with this approach thou).
How to change border color of textarea on :focus
.input:focus {
outline: none !important;
border:1px solid red;
box-shadow: 0 0 10px #719ECE;
}
How to change TextBox border color and Style while typing?
First of all, whenever you ask something in SO, you have to put some effort and show what you´ve tried so that people will be willing to help you. Take that as a note for future questions.
Having said that, you have to add a handler to the TextChanged event of your TextBox control. Then you have to change the properties as you desire:
private void textBox1_TextChanged(object sender, EventArgs e)
{
//PUT THE BUSINESS LOGIC IN HERE
if(textBox1.Text = "")
{
textBox1.BorderStyle = BorderStyle.None;
Pen p = new Pen(Color.Red);
Graphics g = e.Graphics;
int variance = 3;
g.DrawRectangle(p, new Rectangle(textBox1.Location.X - variance, textBox1.Location.Y - variance, textBox1.Width + variance, textBox1.Height +variance ));
}
else
{
textBox1.BorderStyle = BorderStyle.FixedSingle;
}
}
How to change textbox border color and width in winforms?
You could do the following:
- Place the
TextBox
inside aPanel
- Give the panel 1 pixel padding
- Set the text dock to
Fill
- Make the text box to have no border
Then, handle mouse events on the text box, switch the background color of the panel between your two colors, when the mouse enters/leaves.
This isn't the most elegant approach in terms of using resources/handles but it should work without any custom drawing.
Change dynamic textbox border color in Angular
Well, if you want to change the color when you click a button you can use a variable (if only one of them can be change the color) or and array
Only one
indexAttention:number=-1;
checkValue(variable:string)
{
//better than use a "typical for just use findIndex
this.indexAttention=this.values.findIndex(x=>x==variable)
}
//and
<input [style.border-color]="i==indexAttention?'red':null ...>
If you has more you can create an array with the index of the elements. For this we can use map
indexesAttention:number[]=[]
checkValue(variable:string)
{
//map convert an array in another with the same elements and the values calculates
//in this case, if the value is equal to the variable
//return the index, else return -1
this.indexesAttention=this.values.map((x,index)=>x==variable?index:-1)
}
Then we write
<input [style.border-color]="indexesAttention.indexOf(i)>=0?'red':null ...>
NOTE: Is good know the differents methods to iterate in an array: find, findIndex,forEach,map... (Take a look to the mozilla page)
Update if we want to check severals words in a list it's better that our function return an array -not change the variable-
checkValue(variable:string):number[]
{
return this.values
.map((x,index)=>x==variable?index:-1)
.filter(x=>x!=-1) //only want the index>>-1
}
So we can in click function
click()
{
this.indexesAttention=[] //clean the array
this.lists.forEach(x=>{ //iterate using forEach
//concat two arrays
this.indexesAttention=[...this.indexesAttention,
...this.checkValue(x)]
})
}
Now, we are using the spread operator to concat two arrays
NOTE: I know that there're many concepts but really, about arrays, there are no more
NOTE2: you can use also
<input
[style.border-color]="lists.indexOf(values[i])>=0?'red':null"
...>
And you forget the functions
Not able to change TextField Border Color
That is not changing due to the default theme set to the screen.
So just change them for the widget you are drawing by wrapping your TextField with new ThemeData()
child: new Theme(
data: new ThemeData(
primaryColor: Colors.redAccent,
primaryColorDark: Colors.red,
),
child: new TextField(
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderSide: new BorderSide(color: Colors.teal)),
hintText: 'Tell us about yourself',
helperText: 'Keep it short, this is just a demo.',
labelText: 'Life story',
prefixIcon: const Icon(
Icons.person,
color: Colors.green,
),
prefixText: ' ',
suffixText: 'USD',
suffixStyle: const TextStyle(color: Colors.green)),
),
));
Related Topics
Gridview with Fixed Header and Full Page Width Grid
How to Conditionally Control The Visibility of a Control in Asp.Net
Compile for Windows on Linux Using Monodevelop
How to Determine The Screen Width/Height Using C#
Webbrowser Component Not Showing CSS 3
Creating a Data.Frame Using R.Net
Xamarin Visual Studio iOS Development Without a Mac
Androidapp and MySQL connection Didn't Work Connection.Open
Exception from Hresult: 0X80040013: When Integrating R with C#:
Google Play Games Service: Error_Not_Authorized, When Rollout for Beta
Swift: Convert Nsdate to C# Ticks
How to Bind an Objective-C Static Library to Xamarin.iOS
How to Call R Functions from C# and Retrieve The Result in C#
Feasibility of C# Development with Mono
Converting a Byte to a Binary String in C#
System.Data.Sqlclient.Sqlexception: Invalid Column Name 'Phone_Types_Phone_Type_Id'