No Labels or Text Boxes Appear in GroupBox on PowerShell

Asked 1 years ago, Updated 1 years ago, 372 views

I'd like to have some groups in the subform and create text, labels, etc. in those boxes.This is an image that creates an input form.

Below is the code for the part that is in question

#Subforms
$optionform=New-Object System.Windows.Forms.Form
$optionform.StartPosition="CenterScreen"
$optionform.Size=New-Object System.Drawing.Size(500,500)
$optionform.MaximizeBox=$False
$optionform.MinimizeBox=$false
$optionform.text="options"
$optionform.Owner=$form#$form is the main form

# Abbreviated: Closing events, click events, etc.

# Group 1
$Group1 = New-Object System.Windows.Forms.GroupBox
$Group1.Location=New-Object System.Drawing.Point(10,10)
$Group1.size = New-Object System.Drawing.Size (220,115)
$Group1.text="Group1"
$optionform.Controls.Add ($Group1)

## Group 1: Label 1
$Label1 = New-Object System.Windows.Forms.Label
$Label1.Location=New-Object System.Drawing.Point (15,20)
$Label1.Size=New-Object System.Drawing.Size(55,20)
$Label1.Text="Label 1"
$Group1.Controls.Add ($Label1)

## Abbreviated: There are other text and combo boxes.

# Group 2
$Group2 = New-Object System.Windows.Forms.GroupBox
$Group2.Location=New-Object System.Drawing.Point(235,10)
$Group2.size = New-Object System.Drawing.Size (220,115)
$Group2.text="Group2"
$optionform.Controls.Add ($Group2)

## Group 2: Text Box 1
$textBox1 = New-Object System.Windows.Forms.TextBox
$textBox1.Location=New-Object System.Drawing.Point(240,20)
$textBox1.Size=New-Object System.Drawing.Size(55,20)
$Group2.Controls.Add ($textBox1)

## Abbreviated: There are other text and combo boxes.

This will display the labels and Group 2 placed in Group 1 and Group 1.However, the text that is placed in Group 2 is not displayed.

I've tried two things.
The first was to increase the size of Group 1 by rewriting the text to be placed within Group 2 to be placed in Group 1.In this case, it was displayed without any problems.
Second, we erased Group 2 itself and placed it directly in the subform $optionform.This case was also displayed without any problems.

From the above, I think there may be a problem with the placement of Group 2 and how to write the code, but I can't find the problem and I'm at a loss.
What is the problem with this?
Thank you for your cooperation.

powershell

2022-11-21 06:56

1 Answers

New-Object System.Drawing.Point() seems to have been misunderstood.
I thought the standard (Point(0,0) was always in the upper left corner of any GroupBox, but it seems that the standard for label and text placement is in the upper left corner of the GroupBox.
In fact, System.Drawing.Point(), such as labels and text, was shown to be smaller.


2022-11-21 10:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.