我对PictureBox
有疑问。
当我将PictureBox
对接到右上方时,它会隐藏位于表单中心的标签的一部分。我怎样才能在PictureBox
上贴上标签?我认为问题在于(Image
和Label
声明)中的停靠声明,这就是它被PictureBox
隐藏的原因。
我该如何正确地做到这一点?
表格声明:
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "Something"
$Form.StartPosition = "CenterScreen"
$Form.Topmost = $True
$Form.BackColor = "White"
$Form.Width = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width
$Form.Height = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height - 50
#$Form.AutoSize = $True
$Form.AutoSizeMode = "GrowAndShrink"
$Form.ControlBox = $false
$Form.MinimumSize = New-Object System.Drawing.Size(1280,1024)
$Form.MaximumSize = New-Object System.Drawing.Size(1920,1080)
图片声明:
$Image = [system.drawing.image]::FromFile("C:\xxx.png")
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Dock = [System.Windows.Forms.DockStyle]::Right
$pictureBox.BackColor = "Transparent"
#$pictureBox.Anchor = [System.Windows.Forms.AnchorStyles]::Right
$pictureBox.AutoSize = $True
$pictureBox.Image=$Image
$Form.Controls.Add($pictureBox)
标签声明:
$redLabel1 = New-Object System.Windows.Forms.Label
$redLabel1.Location = New-Object System.Drawing.Size($Form.Width, $Form.Height)
$redLabel1.AutoSize = $False
$redLabel1.TextAlign = "MiddleCenter"
$redLabel1.Dock = "Fill"
$redLabel1.Text = "Something"
$redLabel1.ForeColor = "Red"
$redLabel1.BackColor = "Transparent"
$Font = New-Object System.Drawing.Font("Arial", 55, [System.Drawing.FontStyle]::Bold)
$redLabel1.Font = $Font
$Form.Controls.Add($redLabel1)
修改
BringToFront()
方法已经过测试并且工作率为50%。文本不在表单中居中,当标签符合PictureBox
时,文本被包装..我希望该标签以某种方式跳过PictureBox
..
截图:
答案 0 :(得分:0)
有一种名为Control.BringToFront
的方法:https://msdn.microsoft.com/fr-fr/library/system.windows.forms.control.bringtofront(v=vs.110).aspx
所以它应该在你的代码中:
$redLabel1.BringToFront()
答案 1 :(得分:0)
我很安静你的标签没有被图片隐藏,但是放在一边这取决于图像的Z顺序 - 以及标签控件(在示例中没有显示丢失控件) ):
fill dock
是第一个控件,而right dock
是第二个控件
控制,第一个控件将填充可用的空间
剩。right dock
是第一个控件而是fill dock
秒
控制。第二个控件将占用第一个控件后面的所有空间
控制我已经快速修改了我的Windows-Form wrapper示例,以显示:
$Form = Form-Control Form @{Text = "Dock test"; StartPosition = "CenterScreen"; Padding = 4}
$Table = $Form | Form TableLayoutPanel @{RowCount = 2; ColumnCount = 3; ColumnStyles = ("Percent", 50), "AutoSize", "AutoSize"; Dock = "Fill"}
$Panel = $Table | Form Panel @{Dock = "Fill"; BorderStyle = "FixedSingle"; BackColor = "Teal"} -Set @{RowSpan = 2}
$Dock = ForEach ($i in 1..2) {
$Button = $Panel | Form Button @{Location = "25, $(75 * $i - 50)"; Size = "50, 50"; BackColor = "Silver"; Enabled = $False; Text = $i}
$Group = $Table | Form GroupBox @{Text = "Dock $i"; AutoSize = $True}
$Flow = $Group | Form FlowLayoutPanel @{AutoSize = $True; FlowDirection = "TopDown"; Dock = "Fill"; Padding = 4}
$Radio = "None", "Top", "Left", "Bottom", "Right", "Fill" | ForEach {
$Flow | Form RadioButton @{Text = $_; AutoSize = $True; Click = ([ScriptBlock]::Create("`$Dock[$($i - 1)].Button.Dock = `$This.Text"))}
}
New-Object PSObject -Property @{Button = $Button; Group = $Group; Flow = $Flow; Radio = $Radio}
}
$Close = $Table | Form Button @{Text = "Close"; Dock = "Bottom"; Click = {$Form.Close()}} -Set @{ColumnSpan = 2}
$Form.ShowDialog()
仅举几例:
可能的解决方案:
right
和标签Bottom
?