Tooltips not showing when First tab from the tabcontrol is removed.

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
This topic is 1 year and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
ddemaeseneer
Posts: 8
Last visit: Fri Jan 26, 2024 2:53 pm
Has voted: 2 times

Tooltips not showing when First tab from the tabcontrol is removed.

Post by ddemaeseneer »

Product: PowerShell Studio 2022 (64 Bit)
Build: v5.8.201
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.18363.0
PowerShell version(s): 5.1.18362.2212

Behavior: Tooltips not showing when First tab from the tabcontrol is removed.
I am writing a GUI where tabs are removed when a certain condition is met.
Situation: At Form Load - When a x user with y rights > remove tabs from the tabcontrol <

Team A: All Tooltips are showing when all tabs are present.
Team B: Need Tab 1 and 3 only to be showed. Tab 2, 4, (5 and 6 empty tabs) are removed. Tooltips are showing.
Team C: Need Tab 2 and 4 only to be showed. Tab 1, 3, 5 and 6 are removed. < Tooltips are not showing except for the ToolStrip with Buttons and the MenuStrip.

Thus I conclude that when the first tab from the tabcontrol is removed > is the cause of this unwanted behavior.
ddemaeseneer
Posts: 8
Last visit: Fri Jan 26, 2024 2:53 pm
Has voted: 2 times

Re: Tooltips not showing when First tab from the tabcontrol is removed.

Post by ddemaeseneer »

I have found a solution to the problem I have encountered.

Replaced this: $TabControl.TabPages.Remove($TabPageX)
To this: $TabControl.TabPages['TabPageX'].Dispose()
ddemaeseneer
Posts: 8
Last visit: Fri Jan 26, 2024 2:53 pm
Has voted: 2 times

Re: Tooltips not showing when First tab from the tabcontrol is removed.

Post by ddemaeseneer »

Correction .. bug seems to be somewhere else .. :?
User avatar
brittneyr
Site Admin
Posts: 1654
Last visit: Wed Mar 27, 2024 1:54 pm
Answers: 39
Been upvoted: 30 times

Re: Tooltips not showing when First tab from the tabcontrol is removed.

Post by brittneyr »

[Topic moved by moderator to PowerShell GUIs forum]
Brittney
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tooltips not showing when First tab from the tabcontrol is removed.

Post by jvierra »

There is really not enough information to understand what you are seeing. Can you post the simplest PSF that demonstrates the issue.
ddemaeseneer
Posts: 8
Last visit: Fri Jan 26, 2024 2:53 pm
Has voted: 2 times

Re: Tooltips not showing when First tab from the tabcontrol is removed.

Post by ddemaeseneer »

Thank you but I have found a solution to the problem I have encountered.
It seems that resetting Tooltips on a ListView over and over was buggy with my code..
I wrote this piece of code that, depending on the Profile, the ToolTip is updated.

Code: Select all

	$UserProfiles = $Reporters.Profile | Group-Object -NoElement
	$IsManagerOfToolTip = ($UserProfiles | ForEach-Object { '{0} {1}' -f $_.Count, $_.Name }) -join "`n"
	$GroupBoxUserMgmtManageOrReportTo.Text = 'Is Manager Of'
	$TooltipMustTotalToolkit.SetToolTip($ListViewUserMgmtOutputManageOrReportTo, $IsManagerOfToolTip)

So, instead of resetting the ToolTip on the Listview, which was the cause of the problem, I reset the Tooltip on the groupbox.

Code: Select all

	$TooltipMustTotalToolkit.SetToolTip($GroupBoxUserMgmtManageOrReportTo, $IsManagerOfToolTip)
Problem solved.
Attachments
Gui.JPG
Gui.JPG (70.56 KiB) Viewed 1178 times
ddemaeseneer
Posts: 8
Last visit: Fri Jan 26, 2024 2:53 pm
Has voted: 2 times

Re: Tooltips not showing when First tab from the tabcontrol is removed.

Post by ddemaeseneer »

The code that works:

Code: Select all

$ButtonUserMgmtSearch_Click = {
	$Global:ADUserInfo = Get-MUSTTotalToolkitADUserInformation -UserName $UserName
	if (-not $ADUserInfo -or $ADUserInfo.count -gt 1)
	{
		$Message = 'Unable to find user {0} !' -f $ComboboxUserMgmt.Text
		$MessageBox = Get-MessageBox -Message $Message -Caption 'User Not Found !' -Icon Error -Button OK
		if ($MessageBox -eq 'OK')
		{
			Clear-UserMgmtData
		}
	}
	else
	{
		$GroupboxUserMgmtInformation.Visible = $true
		$DateTimeFormat = @{ Format = 'dd/MM/yyyy HH:mm:ss' }
		$Script:DN = $ADUserInfo.distinguishedname
		#region User Account Status
		#region User Account Enabled/Disabled
		if ($ADUserInfo.Enabled)
		{
			$AccountStatus = 'Enabled'
			$LabelUserMgmtOutputAccoutStatus.ForeColor = 'Green'
		}
		else
		{
			$AccountStatus = 'Disabled'
			$LabelUserMgmtOutputAccoutStatus.ForeColor = 'Red'
		}
		$LabelUserMgmtOutputAccoutStatus.Text = $AccountStatus
		#endregion User Account Enabled/Disabled
		#region User Account Locked Out
		if ($ADUserInfo.LockedOut)
		{
			$LabelUserMgmtOutputLockedOut.ForeColor = 'Red'
			$ButtonUserMgmtUnlockAccount.Enabled = $true
			$ButtonUserMgmtUnlockAccount.PerformClick()
		}
		else
		{
			$LabelUserMgmtOutputLockedOut.ForeColor = 'Green'
			$TextUnlockAccount = 'User Account is not Locked Out'
			$TooltipMustTotalToolkit.SetToolTip($ButtonUserMgmtUnlockAccount, $TextUnlockAccount)
		}
		$LabelUserMgmtOutputLockedOut.Text = $ADUserInfo.LockedOut
		#endregion User Account Locked Out
		#endregion User Account Status
		#region User Profile
		if ($ADUserInfo.IsManager)
		{
			$GroupBoxUserMgmtManageOrReportTo.Enabled = $true
			$GroupBoxUserMgmtManageOrReportTo.Visible = $true
			
			$Reporters = $ADUserInfo.Reporters | Get-MUSTTotalToolkitADUserInformation
			
			$UserProfiles = $Reporters.Profile | Group-Object -NoElement
			$IsManagerOfToolTip = ($UserProfiles | ForEach-Object { '{0} {1}' -f $_.Count, $_.Name }) -join "`n"
			$GroupBoxUserMgmtManageOrReportTo.Text = 'Is Manager Of'
			$TooltipMustTotalToolkit.SetToolTip($GroupBoxUserMgmtManageOrReportTo, $IsManagerOfToolTip)
			
			$ListViewUserMgmtOutputManageOrReportTo.Items.Clear()
			$ListViewUserMgmtOutputManageOrReportTo.Refresh()
			$ListViewUserMgmtOutputManageOrReportTo.Update()
			
			$Reporters | Sort-Object Profile | ForEach-Object {
				Add-ListViewItem -ListviewComputerLogsInfo $ListViewUserMgmtOutputManageOrReportTo -Items $_.Name -SubItems $_.Profile
			}
		}
		if ($ADUserInfo.IsReporter)
		{
			$GroupBoxUserMgmtManageOrReportTo.Enabled = $true
			$GroupBoxUserMgmtManageOrReportTo.Visible = $true
			$GroupBoxUserMgmtManageOrReportTo.Text = 'Is Reporter Of'
			
			$Managers = $ADUserInfo.Manager | Get-MUSTTotalToolkitADUserInformation

			$TooltipMustTotalToolkit.SetToolTip($GroupBoxUserMgmtManageOrReportTo, '')
			
			$ListViewUserMgmtOutputManageOrReportTo.Items.Clear()
			$ListViewUserMgmtOutputManageOrReportTo.Refresh()
			$ListViewUserMgmtOutputManageOrReportTo.Update()
			
			$Managers | Sort-Object -Unique | ForEach-Object {
				Add-ListViewItem -ListviewComputerLogsInfo $ListViewUserMgmtOutputManageOrReportTo -Items $_.Name -SubItems $_.Profile
			}
		}
		if ($ADUserInfo.Profile -match 'STAFF')
		{
			$GroupBoxUserMgmtManageOrReportTo.Enabled = $false
			$GroupBoxUserMgmtManageOrReportTo.Visible = $false
			$GroupBoxUserMgmtManageOrReportTo.Text = ''
			
			$ListViewUserMgmtOutputManageOrReportTo.Items.Clear()
			$ListViewUserMgmtOutputManageOrReportTo.Refresh()
			$ListViewUserMgmtOutputManageOrReportTo.Update()
		}
		
		$LabelUserMgmtOutputLSU.Text = $ADUserInfo.LSU
		$LabelUserMgmtOutputLSU.ForeColor = $ADUserInfo.SetScopeColor
		$LabelUserMgmtOutputUserProfile.Text = $ADUserInfo.Profile
		$LabelUserMgmtOutputUserProfile.ForeColor = $ADUserInfo.SetScopeColor
		$LabelUserMgmtOutputOU.Text = $ADUserInfo.OU
		$LabelUserMgmtOutputOU.ForeColor = $ADUserInfo.SetScopeColor
		
		#endregion User Profile
		#region User Account Description
		if ($ADUserInfo.Description.length -gt 31)
		{
			$Text = '{0} ...' -f $ADUserInfo.Description.Substring(0, 26)
			$LabelUserMgmtOutputDescription.Text = $Text
			$TooltipMustTotalToolkit.SetToolTip($LabelUserMgmtOutputDescription, $ADUserInfo.Description)
		}
		else
		{
			$LabelUserMgmtOutputDescription.Text = $ADUserInfo.Description
			$TooltipMustTotalToolkit.SetToolTip($LabelUserMgmtOutputDescription, '')
		}
		#endregion User Account Description
		#region User Account Password Information

		$LastBadPasswordAttempt = Get-Date $ADUserInfo.LastBadPasswordAttempt @DateTimeFormat
		$AccountExpirationDate = Get-Date $ADUserInfo.AccountExpirationDate @DateTimeFormat
		
		$PasswordInfo = Get-ADUserPasswordInformation $UserName
		$Global:PasswordExpirationDate = Get-Date $PasswordInfo.Expiration @DateTimeFormat
		$PasswordLastChanged = Get-Date $PasswordInfo.LastChanged @DateTimeFormat
		$DaysLeft = $PasswordInfo.DaysLeft
		
		if ($PasswordLastChanged -match '1601')
		{
			$PasswordLastChanged = 'Never'
			$PasswordExpirationDate = 'Never'
			$DaysLeft = ''
		}
		
		$LabelUserMgmtOutputPWExpiresOn.Text = $PasswordExpirationDate
		$LabelUserMgmtOutputPWLastSet.Text = $PasswordLastChanged
		$LabelUserMgmtOutputPWBadPWTime.Text = $LastBadPasswordAttempt
		$LabelUserMgmtOutputPWBadLogonCount.Text = $ADUserInfo.BadLogonCount
		$LabelUserMgmtOutputPWBadPWCount.Text = $ADUserInfo.BadPwdCount
		$LabelUserMgmtOutputPWDaysB4Expiration.Text = $DaysLeft
		#endregion User Account Password Information
		
		$Offices = $ADUserInfo.Office -join "`n"
		$LabelUserMgmtOutputOffice.Text = $Offices
		
		$Created = Get-Date $ADUserInfo.Created @DateTimeFormat
		$LabelUserMgmtOutputCreated.Text = $Created
		
		$MailboxCreatedOn = Get-Date $ADUserInfo.MailboxCreatedOn @DateTimeFormat
		$LabelUserMgmtOutputMbxCreation.Text = $MailboxCreatedOn
		
		$LabelUserMgmtOutputMBXDB.Text = $ADUserInfo.MailboxDatabaseLink
		$LabelUserMgmtOutputDisplayName.Text = $ADUserInfo.DisplayName
		$LabelUserMgmtOutputEmployeeNumber.Text = $ADUserInfo.EmployeeNumber
		$LabelUserMgmtOutputExpirationDate.Text = $AccountExpirationDate
		$LabelUserMgmtOutputUserName.Text = $ADUserInfo.SamAccountName
		
		$LinkLabelUserMgmtOutputEmail.Text = $ADUserInfo.EmailAddress
		$LinkLabelUserMgmtOutputPhone.Text = $ADUserInfo.OfficePhone
		
		$ButtonUserMgmtLastLogon.Enabled = $true
		$ButtonUserMgmtExtendPassword.Enabled = $true
		$ButtonUserMgmtMSTSC.Enabled = $true
		$this.Cursor = 'Default'
	}
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tooltips not showing when First tab from the tabcontrol is removed.

Post by jvierra »

See. The question you posted could never be answered. It is always best to use multiple tooltip controls and to not get fancy with your code. You can use one simple function for all tooltips by detecting the source control.

Watch out for the built-in default tooltip. Use one or the other method but not both.

Again, without the PSF the code is not very useful for us. You should not ask for frum assistance for complex issues without code that can be run. Just a piece of code is not helpful.

Also, just re-looking at your code likely helped you to see the issue. I know that happens to me quite often. Reducing the code to the smallest example often uncovers the problem.

Glad you found a solution.
This topic is 1 year and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked