2016-09-01 1 views
0

내 GroupBox가 표시되지 않는 이유를 모르겠습니다. 여러 개의 레이블이있는 groupbox를 표시하고 싶지만 작동하지 않습니다. 라디오 버튼을 코드로 레이블로 대체하려고 시도했습니다.>>https://sysadminemporium.wordpress.com/2012/12/07/powershell-gui-for-your-scripts-episode-3/ 저는 GUI 초보자이며 다른 예제를 보았습니다.하지만이 코드는 사용할 수 없습니다.내 Powershell GUI에 그룹 상자를 표시 할 수 없습니다.

#---------------------------------------------- 
# Generated Form Function 
#---------------------------------------------- 
function Call-test_psf { 

    #---------------------------------------------- 
    #region Import the Assemblies 
    #---------------------------------------------- 
    [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') 
    [void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') 
    [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') 
    #endregion Import Assemblies 

    #---------------------------------------------- 
    #region Generated Form Objects 
    #---------------------------------------------- 
    [System.Windows.Forms.Application]::EnableVisualStyles() 
    $form1 = New-Object 'System.Windows.Forms.Form' 

    $form1.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog 
    $form1.MaximizeBox = $False 
    $form1.MinimizeBox = $False 
    # Choix du titre 
    $form1.Text = "Title" 

    $label4 = New-Object 'System.Windows.Forms.Label' 
    $label5 = New-Object 'System.Windows.Forms.Label' 



    #endregion Generated Form Objects 

    #---------------------------------------------- 
    # User Generated Script 
    #---------------------------------------------- 


    $form1_Load={ 
     #TODO: Initialize Form Controls here 

    } 

    # --End User Generated Script-- 
    #---------------------------------------------- 
    #region Generated Events 
    #---------------------------------------------- 

    $Form_StateCorrection_Load= 
    { 
     #Correct the initial state of the form to prevent the .Net maximized form issue 
     $form1.WindowState = $InitialFormWindowState 
    } 

    $Form_Cleanup_FormClosed= 
    { 
     #Remove all event handlers from the controls 
     try 
     { 
      $buttonSuivant.remove_Click($buttonSuivant_Click) 
      $buttonRetour.remove_Click($buttonRetour_Click) 
      $form1.remove_Load($form1_Load) 
      $form1.remove_Load($Form_StateCorrection_Load) 
      $form1.remove_FormClosed($Form_Cleanup_FormClosed) 
     } 
     catch [Exception] 
     { } 
    } 
    #endregion Generated Events 

    #---------------------------------------------- 
    #region Generated Form Code 
    #---------------------------------------------- 
    $form1.SuspendLayout() 
    # 
    # form1 
    # 
    $form1.Controls.Add($groupBox1) 
    $form1.ClientSize = '700, 300' 

    #endregion 
    $form1.Name = 'form1' 
    $form1.Text = 'Title' 
    $form1.add_Load($form1_Load) 
    # 
    # GroupBox1 
    # 
    $groupBox1 = New-Object System.Windows.Forms.GroupBox 
    $groupBox1.Location = '150,300' 
    $groupBox1.size = '400,150' 
    $groupBox1.text = "Title groupBox1" 
    $groupBox1.Visible = $true 
    # 
    # progressBar1 
    # 
    $progressBar1 = New-Object System.Windows.Forms.ProgressBar 
    $progressBar1.Name = 'progressBar1' 
    $progressBar1.Value = 0 
    $progressBar1.Style="Continuous" 
    $System_Drawing_Size = New-Object System.Drawing.Size 
    $System_Drawing_Size.Width = $width - 40 
    $System_Drawing_Size.Height = 20 
    $progressBar1.Size = $System_Drawing_Size 
    $progressBar1.Left = 5 
    $progressBar1.Top = 40 
    # 
    # label4 
    # 
    $label4.Font = 'Microsoft Sans Serif, 8pt' 
    $label4.Location = '50, 50' 
    $label4.Name = 'label2' 
    $label4.Size = '20, 20' 
    $label4.TabIndex = 8 
    $label4.TextAlign = 'TopLeft' 
    $label4.Visible = $false 
    $label4.Text = "test" 
    # 
    # label5 
    # 
    $label5.Font = 'Microsoft Sans Serif, 8pt' 
    $label5.Location = '50, 70' 
    $label5.Name = 'label2' 
    $label5.Size = '20, 20' 
    $label5.TabIndex = 10 
    $label5.TextAlign = 'TopLeft' 
    $label5.Visible = $false 
    $label5.Text = "test" 

    $groupBox1.Controls.AddRange(@($Label4,$Label5)) 
    # 
    $form1.ResumeLayout() 
    #endregion Generated Form Code 

    #---------------------------------------------- 

    #Save the initial state of the form 
    $InitialFormWindowState = $form1.WindowState 
    #Init the OnLoad event to correct the initial state of the form 
    $form1.add_Load($Form_StateCorrection_Load) 
    #Clean up the control events 
    $form1.add_FormClosed($Form_Cleanup_FormClosed) 
    #Show the Form 
    return $form1.ShowDialog() 

} #End Function 

#Call the form 
Call-test_psf | Out-Null 

당신이 날 도와 줄 수 : 여기 내 코드? 미리 감사드립니다.

답변

2

변경 2 라인 :

$groupBox1.Location = '150,300'

Y 위치는 단지 높은 300 픽셀의 같은 양식의 맨 아래 떨어져있는 300입니다.

$form1.Controls.Add($groupBox1) 

그룹 상자를 만든 후에이 줄을 이동하십시오. 그래서 어디 예를 들어 $groupBox1 = New-Object System.Windows.Forms.GroupBox

후 :

$groupBox1 = New-Object System.Windows.Forms.GroupBox 
$groupBox1.Location = '10,10' 
$groupBox1.size = '400,150' 
$groupBox1.text = "Title groupBox1" 
$groupBox1.Visible = $true 
$form1.Controls.Add($groupBox1)   # line moved here. 
+0

이 감사는 완벽! – Jey10

관련 문제