Search code examples
.netwinformspowershellpowershell-5.0

Windows forms ToolTip property "ShowAlways" not working when parent object is disabled


According to the Microsoft developer documentation there's a ToolTip property called ShowAlways which according to the documentation;

With the ShowAlways property, you can display a ToolTip window even when the container of the ToolTip is not active. You can use this feature in a modeless window application to enable ToolTip windows to be displayed regardless of which modeless window is active.

With the below example code I can't make this work.

$Form                            = New-Object system.Windows.Forms.Form
$Form.ClientSize                 = '200,100'
$Form.text                       = "test"
$Form.TopMost                    = $false
$Form.FormBorderStyle            = 'FixedDialog'
$Form.MaximizeBox                = $false
$Form.StartPosition              = 'CenterScreen'

$checkbox1                       = New-Object system.Windows.Forms.CheckBox
$checkbox1.text                  = "Test"
$checkbox1.AutoSize              = $true
$checkbox1.width                 = 100
$checkbox1.height                = 20
$checkbox1.location              = New-Object System.Drawing.Point(10,50)
$checkbox1.Font                  = 'Verdana,7'

#Disable checkbox enabled state
$checkbox1.Enabled               = $false

$tooltip1                        = New-Object System.Windows.Forms.ToolTip
#Showalways property to true
$tooltip1.ShowAlways             = $true
$tooltip1.SetToolTip($checkbox1,"This is a tooltip.")
$Form.controls.AddRange($checkbox1)

$Form.ShowDialog()

Am I missing something?


Solution

  • I ended up removing the text from the checkbox and replaced it with a label instead so that I can use the ToolTip on that, and added an OnClick action to the label for QoL if the checkbox state is enabled.

    Maybe it isn't the best and most beautiful solution, but it's one that works and gets the job done until (or if) disabled checkboxes support ToolTips in the future.