PowerShell GUI观察器有几个套接字连接

时间:2014-06-22 12:02:21

标签: sockets powershell user-interface

我发现很多例子都很长 - 但我认为可以用很短的方式完成。

我需要一个GUI来显示并启用我需要的几个套接字连接选项。

一开始我觉得我有:

    # Load external assemblies
    [void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void][Reflection.Assembly]::LoadWithPartialName("System.Drawing")
            $OnLoadForm_StateCorrection = {
                $form1.WindowState = $InitialFormWindowState
            }

    $myGUI   = New-Object System.Windows.Forms.Form
    $myGUI.Text = "Socket-Traffic"
    $myGUI.Name = "myGUI"
    $myGUI.DataBindings.DefaultDataSourceUpdateMode = 0
    $myGUI.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,255) 
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Width = 332
    $System_Drawing_Size.Height = 264
    $myGUI.ClientSize = $System_Drawing_Size

现在我有一个Hashes列表,其中包含变量和连接的所有相关信息。 groupe必须能够访问他们的哈希:

  $Sockets = $HASH1,$HASH2,$HASH3,$HASH4 # all hasches have a [string] ID: $HASH1.ID = $port
  $n = 0 # do I need that?
  foreach ($h in $Sockets) { 
     makeTab $myGUI $h $n
     $n++
  }

我想到的功能应该像这样开始:

  function makeTab {
     param (
        [parameter(Mandatory=$true)]
          [PSObject] $gui,
        [parameter(Mandatory=$true)]
          [PSObject] $hashTable, # with all info to connect and vars. 
        [parameter(Mandatory=$true)]
          [int] $noTab 
     )
     ... ??
  }

每个Socket-Tab都必须有这些内部组合:

按钮后面的所有函数调用如下:
$ x_OnClick = {Write-host"点击按钮,执行..." }

  1) Send-a-Line Groupe 
     a) Line to enter test meant to sent.
     b) Button to send  # no 'cancle'
  2) Login-Groupe: 
     a) status: Login=Green.ico, Connected=Orange.ico, nothing=red.ico
     b) Button: Login (connect & login)
     c) Button: Logout (Logout & disconnect)
  3) Logging-Groupe:
     a) last 2 Lines been sent
     b) last 2 line received
  4) Status Groupe
     a) text lines with var. info. about the connection
     b) text lines with var. info. about the connection
     ...
  Global - Finally
     a) Button to Exit the script with logout & disconnect all socket connections...

5月s.o.可以起草一个例子吗?之后,我可以确定组中各种按钮和按钮的大小和位置 非常感谢您提前! Gooly

1 个答案:

答案 0 :(得分:0)

如果您能够使用PowerSHell 3.0或更高版本,则可以使用WPF,其中表单只是类似XML的文本。您可以在可视化设计器中创建XML表单,如Visual Studio Express。 像这样:TreeView Example