is there some way to set the color of the name of a tabPage depending on a condition?
my TabControl has several tabPages, where each one is a computer in AD. I'd like to have the following;
if the PC is in AD, set the Tab name forecolor to black and the backcolor to green, if not in AD, set the backcolor red and the forecolor white
can this be done?
thanks!
tab name color
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: tab name color
You can use the "Paint" event to paint custom tabs. It is a bit of a difficult programming task if you have no experience programming to the Windows Net "Graphics" object.
I do not have any examples for tabs. The only samples I have are for the DataGridView. You can search for examples to see if anyone has posted examples. I suggest searching for "TabControl Paint Event"
Every object in WinForms sends a "Paint" event but I am not sure the tab part can be isolated. Give it a try by outputting the object name in the "Paint" event code.
I do not have any examples for tabs. The only samples I have are for the DataGridView. You can search for examples to see if anyone has posted examples. I suggest searching for "TabControl Paint Event"
Every object in WinForms sends a "Paint" event but I am not sure the tab part can be isolated. Give it a try by outputting the object name in the "Paint" event code.
Re: tab name color
Here is one example that will get you started.
https://social.msdn.microsoft.com/Forum ... msdesigner
https://social.msdn.microsoft.com/Forum ... msdesigner
Re: tab name color
OK I believe I got all the required code except that I do not know how to raise the event for that
here's a piece of code to illustrate what I tried. I know the event is not raised because the label1 text property does not get updated
pretty sure I'm missing a small piece somewhere.
here's a piece of code to illustrate what I tried. I know the event is not raised because the label1 text property does not get updated
pretty sure I'm missing a small piece somewhere.
Code: Select all
$tabcontrol1_DrawItem=[System.Windows.Forms.DrawItemEventHandler]{
if ($tabcontrol1.SelectedIndex -eq 0) {
$label1.Text = 'Draw event was raised'
$_.Graphics.FillRectangle('Green', $_.Bounds)
}
}
Re: tab name color
We don't "raise" events. The system raises events based on external influences like mouse clicks or keyboard input. Some events are raised by the system when the GUI needs attention. The "Paint" event delive3red as a "DrawItem event for the form when items need to be drawn is handled by the WinForms system. When you add the DrawItem event it is called before the system draws or paints the item. In the case of the TabControl you get the graphic object for the tab control. This lets you draw on the control window. You then have to calculate what you want to draw and where you want to draw it. This will require some knowledge of mathematics and raster graphics drawing.
I recommend learning how Windows and WinForms work with graphics. As I noted above, you are in the arena with advanced programming and developing.
If I had an example, I would post it. I started a quick example but then realized that it would take me an hour to do a demo that would be understandable. I may do that eventually but can't do it now.
Consider this a good excuse for you to learn Windows graphics. You can also continue to search for other examples. They will not give you the code you seek. They will almost always be in C# and C# cannot be directly turned into PowerShell script. This will give you a chance to learn C# and how to recode C# examples as PowerShell code.
Good luck and have fun. It is something that all Windows GUI programmers have to go through.
I recommend learning how Windows and WinForms work with graphics. As I noted above, you are in the arena with advanced programming and developing.
If I had an example, I would post it. I started a quick example but then realized that it would take me an hour to do a demo that would be understandable. I may do that eventually but can't do it now.
Consider this a good excuse for you to learn Windows graphics. You can also continue to search for other examples. They will not give you the code you seek. They will almost always be in C# and C# cannot be directly turned into PowerShell script. This will give you a chance to learn C# and how to recode C# examples as PowerShell code.
Good luck and have fun. It is something that all Windows GUI programmers have to go through.