Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 在自定义按钮类上使用父事件_Powershell_Oop_Events - Fatal编程技术网

Powershell 在自定义按钮类上使用父事件

Powershell 在自定义按钮类上使用父事件,powershell,oop,events,Powershell,Oop,Events,我想创建一个带有可点击按钮的GUI。我已经在程序中开始了,但我想在object中继续。所以我重新开始了我的项目。 现在,我有点被事件缠住了,尤其是添加点击 这是我的自定义按钮类 class ConfigButton : Windows.Forms.Button { # Constructor ConfigButton ([String]$Label, [int] $PosX, [int] $PosY) { # Set properties

我想创建一个带有可点击按钮的GUI。我已经在程序中开始了,但我想在object中继续。所以我重新开始了我的项目。 现在,我有点被事件缠住了,尤其是添加点击

这是我的自定义按钮类

class ConfigButton : Windows.Forms.Button {

    # Constructor

    ConfigButton ([String]$Label, [int] $PosX, [int] $PosY) {       
        # Set properties
        $this.Text = $Label
        $this.Location = New-Object System.Drawing.Point($PosX,$PosY)
        $this.Autosize = $True
    }

    # Functions

    [void] AddToWindow([ConfigWindow]$Window) {
        $Window.Controls.Add($this)
    }

    [String] ToString() {
        return $this.Text
    }

    #Events
}
我的问题是:如何在我的自定义类中添加添加单击事件? 我天真地尝试了
$this.Add\u单击
,但没有

这是我的“Main”,我在这里创建我的对象并将其添加到我的主窗口(原始值在这里用于测试)


谢谢。

你不需要添加它-它已经在那里了,从
按钮继承而来。
:)只需执行
$ButtonClose。添加({})
这就是我最后做的。这不是我想做的,但似乎我别无选择。
$Main = New-Object ConfigWindow("Main Window", 1000, 800)

$ButtonClose = New-Object ConfigButton("Fermer",200, 200)

$ButtonClose.AddToWindow($Main)

Write-Host $ButtonClose.ToString()

$Main.DisplayWindow()