I'm using VS2012 with VB.NET on a winforms application. I set the BackColor property of some textboxes programmatically during my code depending on form validation. This works fine, the problem is that I'd like to "reset" the BackColor property of the textbox, so that the textbox performs as if it were in the same state before I set the BackColor. So it would do the following:
Return to the default color of white immediately after "reset"
Change to that "light gray" color when the textbox.enabled = false
The reason why I cannot simply set the BackColor to Color.White, is that this affects the textbox when textbox.enabled = false. The textbox does not return that "light gray" color after setting the backcolor and disabling the textbox. I need it to return to that color, and I'd rather not have to set the textbox's color everytime I enable or disable the textbox. Thanks!
Simply:
TextBox1.BackColor = SystemColors.Window
You reset the color by re-assigning the original value of BackColor. Or by assigning the default value, it isn't white:
textBox1.BackColor = Color.FromKnownColor(KnownColor.Window);
textBox1.BackColor = SystemColors.Control;
This is an old post, but when I used SystemColors.Window it set it to white, not the default grey.
Related
How to add a hint text to a TextBox in a UserForm that will disappear once a user type anything in?
Add a Label element.
Type a hint text.
Set BackColor, Height, Left, Top, and Width properties to match that of the TextBox that will be added later.
Note: Setting BackColor to Window Background (from the drop-down list) will match the common background color of a text box.
Set ForeColor property (a different from TextBox text color allows to distinguish the hint text from the entered one).
Add a TextBox element.
Set BackColor, Height, Left, Top, and Width properties.
Set BackStyle property to fmBackStyleTransparent.
Add the following code to Sub TextBox_Change:
If TextBox.Value = "" Then
TextBox.BackStyle = fmBackStyleTransparent
Else
TextBox.BackStyle = fmBackStyleOpaque
End If
Here is the result:
can you help me to solve my problem on vb.net
i want to change background color of one or more datagridview using check all component on form using controls..
For Each ctrl In ctrlParent.Controls
If ctrl.GetType Is GetType(DataGridView) Then
....
End If
Next
if i use ctrl.BackColor = Color.Black, that no make any change. but if i use ctrl.Backgroundcolor = Color.Black shows error : 'Backgroundcolor' is not a member of 'System.Windows.Forms.Control'
any idea?
can i access control preperty to change 'Backgroundcolor' property of datagridview?
or any else?
note : ctrl.ForeColor = Color.Black -> successfully change font color on datagridview
You can filter the type of controls directly to DataGridView in your loop.
Then set BackgroundColor accordingly:
For Each ctrl In ctrlParent.Controls.OfType(Of DataGridView)
ctrl.BackgroundColor = Color.Black
Next
I want to have a little square that will display the color currently selected by a color dialog.
It should look like this: Picture of what I want
And the green box, should update to another color when they choose one.
How would I go about doing this?
Using colorDialog As New ColorDialog
'If the user actually selected a color Then
If colorDialog.ShowDialog() = DialogResult.OK Then
'Set the background color of the picture box = color selected from the color dialog
PictureBox1.BackColor = colorDialog.Color
End If
End Using
Place this code in your Button_Click event handler.
Now the datagridView Header Background color is showing in Gray. I want to change to differenct
color.
I Changed the background color in ColumnHeaderDefaultCellStyle, but nothing changed.
How to do this.
Set the property EnableHeadersVisualStyles to False, then change the ColumnHeaderDefaultCellStyle background color to the color that you desire. You will be able to see the changes in the designer itself.
Also, if you are trying to set the color (back or fore)color or other properties of the individual column's header (not all at once) use
datagridview.Columns(e.ColumnIndex).HeaderCell.Style.BackColor = color.cyan
datagridview.Columns(e.ColumnIndex).HeaderCell.Style.(ForeColor or Font or Alignment etc) = whatever
where e.ColumnIndex was taken from the EventArgs of your Event, but you can alter accordingly.
In datagridView you can change the Header color by using DataGridViewCellStyle, see the following code
' Set the selection background color for all the cells.
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black
' Set RowHeadersDefaultCellStyle.SelectionBackColor so that its default
' value won't override DataGridView.DefaultCellStyle.SelectionBackColor.
dataGridView1.RowHeadersDefaultCellStyle.SelectionBackColor = Color.Empty
' Set the background color for all rows and for alternating rows.
' The value for alternating rows overrides the value for all rows.
dataGridView1.RowsDefaultCellStyle.BackColor = Color.LightGray
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.DarkGray
' Set the row and column header styles.
dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Black
dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Black
EDIT:
Using the DataGridViewCellStyle, your header color will changes but a seperator for columns in the header section will not appear. So, heres a overrided event of OnPaint Event Handler have a look at this
how do i set the background color of my form to what the user picks from colordialog?
Simply assign the BackColor property of the form with the value of the Color property of the ColorDialog:
Dim cd As New ColorDialog()
If cd.ShowDialog() = DialogResult.OK Then
Me.BackColor = cd.Color
End If