Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have problem with PictureBox.

When I am docking PictureBox to the top right, it's hidding a part of label which is on the center of form. How I can bring to front label over PictureBox? I am thinking that problem is with docking declaration in both (Image and Label declaration), that's why it's hidden by PictureBox.

How I can do this properly?

Form Declaration:

$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 declaration:

$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)

Label declaration:

$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)

EDIT:

BringToFront() method already tested and working in 50%. Text is not centered in forms, and when label meet PictureBox, text is wrapped.. I would like that label will somehow skip PictureBox..

Screenshot:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
250 views
Welcome To Ask or Share your Answers For Others

1 Answer

I am quiet sure that your label isn't hidden by the picture, but just put aside this depends on the Z-Order of the image - and the label control (which doesn't show from the lose controls in the example):

  • If you fill dock the first control and than right dock the second control, the first control will just fill the available the space that is leftover.
  • If you right dock the first control and than fill dock second control. The second control will take all the space behind the first control

I have quickly modified my Windows-Form wrapper example, to show this:

$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()

Just a few examples:

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

Possible Solutions:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...