【发布时间】:2021-04-22 21:18:31
【问题描述】:
我正在尝试向选项卡控件添加背景图像
$tc_ASSTabControl.BackgroundImage = [System.Drawing.Image]::FromFile('C:\Users\me\test\image1.jpg')
这是定义选项卡控件的代码
# Creating Tab Control
$tc_ASSTabControl = New-Object System.Windows.Forms.TabControl
# Customizing the ASS Tab Control
$tc_ASSTabControl | ForEach-Object {
$_.DataBindings.DefaultDataSourceUpdateMode = 0
$_.Location = New-Object System.Drawing.Point(18, 65)
$_.Name = "tc_ASSTabControl"
$_.Width = 850
$_.Height = 580
$_.BackColor = [System.Drawing.Color]::Transparent
}
添加背景图片后,表单在初始加载时和选项卡(选项卡控件的SelectedIndex)更改时闪烁。
我尝试了以下选项
将 DoubleBuffered 属性设置为 true
#This code doesn't work
$form.DoubleBuffered = $true
这是How to fix the flickering in User Controls.上的相关帖子
每个控件的背景色属性被设置为“透明”
BackColor = [System.Drawing.Color]::Transparent
这是问题的屏幕截图。加载表单时也会发生这种情况。
这是我如何在第一个选项卡顶部定义标签的示例,以帮助理解闪烁的原因。
$lbl_BrowseSearchFolder = New-Object system.Windows.Forms.Label -Property @{
text = "Browse for the folder that is to be searched"
AutoSize = $true
width = 25
height = 10
location = New-Object System.Drawing.Point(29, (25 + $ySpacer))
Font = 'Arial,10'
BackColor = [System.Drawing.Color]::Transparent
}
正如您从图片中看到的,“搜索条件”选项卡上的控件加载有延迟。是否可以设置这些控件的任何属性来防止加载延迟?
有人可以建议一种方法来解决 PowerShell 表单上的闪烁问题
【问题讨论】:
-
如果您不使用 .jpg 文件,而是使用 .bmp 文件(不压缩)会有所帮助
-
@Theo 感谢您的建议。我尝试用 24 位 .bmp 图像替换它。那里没有运气。
-
我认为闪烁与必须重绘的大表面有关,同时在其上方放置了同样大的透明 标签。也许您可以通过不使用标签控件来“作弊”,而是使用面板控件来代替您将背景图像设置为与选项卡控件相同的图像。使面板大小相同并停靠在 tabcontrol 上。
-
感谢您的宝贵时间。我试过了。我创建了一个面板控件并在其上添加了选项卡控件,并在将选项卡控件 BackColor 设置为“透明”后设置了面板控件的背景图像。可悲的是,它没有用
-
不,我的意思是相反。将面板放在选项卡的顶部,而不是标签上。设置它的背景图片而不是透明的。造成问题的是透明度
标签: image winforms powershell tabcontrol flicker