Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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 Winforms MoveUp/MoveDown_Winforms_Powershell - Fatal编程技术网

PowerShell Winforms MoveUp/MoveDown

PowerShell Winforms MoveUp/MoveDown,winforms,powershell,Winforms,Powershell,我最近才开始进入PowerShell表单,一旦我撞到墙上,它就会成为支持的雷区。对于c#来说,有太多东西了,但我常常很难将其转换为PowerShell 下面的代码是一个更大的Skype脚本的片段(请原谅糟糕的延迟,没有必要添加不敬的代码)。当我的CheckedListBox被填充时,我正在努力创建上移/下移按钮。 CheckedListBox很重要,因为列表中的每个人都将被添加到Skype响应组中,并且选中的每个人都将被指定为该组的管理员。选择此类型的布线时,上移/下移按钮将用于优先级目的 #F

我最近才开始进入PowerShell表单,一旦我撞到墙上,它就会成为支持的雷区。对于c#来说,有太多东西了,但我常常很难将其转换为PowerShell

下面的代码是一个更大的Skype脚本的片段(请原谅糟糕的延迟,没有必要添加不敬的代码)。当我的CheckedListBox被填充时,我正在努力创建上移/下移按钮。
CheckedListBox很重要,因为列表中的每个人都将被添加到Skype响应组中,并且选中的每个人都将被指定为该组的管理员。选择此类型的布线时,上移/下移按钮将用于优先级目的

#Function for creating an "open file" button
Function OpenFileDialog
    { [System.Reflection.Assembly]::LoadWithPartialName( "System.Windows.Forms" ) | Out-Null
      $OBJFORM        = New-Object System.Windows.Forms.OpenFileDialog
      $OBJFORM.Filter = "Text files (*.txt)|*.txt"
      $TXTIMPORT      = $OBJFORM.ShowDialog()

      IF ( $TXTIMPORT -eq "OK" )
         { Return $OBJFORM.FileName } }



# ///////////////

#Function for importing users
Function ImportUsers
    { $USERS    = gc $TAB2IMPORT
      $SIPUSERS = @()

      foreach ( $USER in $USERS )
              { $USERSIP = ( "sip:" + $_ )

                $SIPUSERS += $USERSIP

                IF ( $USERSIP -ne $NULL )
                   { [void]$TAB2LISTBOX.Items.Add( $USERSIP ) }

                IF ( $SIPUSERS.Count -ge 2 )
                   { $TAB2LISTL.Visible = $TRUE } } }



# ///////////////

# Adds .NET assemby's and turns on visual themes in standard PowerShell.
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()



# ///////////////

# Creates the parent form and controls
$SDC                  = New-Object System.Windows.Forms.Form
$SDC.Location         = '270,175'
$SDC.Size             = '900,600'
$SDC.StartPosition    = "CenterScreen"
$SDC.BackColor        = "Lavender"
$SDC.Font             = "Calibri, 8.5"
$SDC.FormBorderStyle  = "Fixed3D"

$TABC                 = New-Object System.Windows.Forms.TabControl
$TABC.Location        = '140,20'
$TABC.Size            = '720,520'
$TABC.SizeMode        = "Fixed"
$SDC.Controls.Add( $TABC )



# ///////////////

#Tab controls
$TAB2                 = New-Object System.Windows.Forms.TabPage
$TAB2.Location        = '20,40'
$TAB2.Size            = '100,100'
$TAB2.Text            = "Response Group"
$TAB2.Padding         = New-Object System.Windows.Forms.Padding ( 3,3,3,3 )
$TAB2.AutoScroll      = $TRUE
$TABC.Controls.Add( $TAB2 )



# ///////////////

#Tab 2 ( Migrate users to Skype )
$TAB2HEADER           = New-Object System.Windows.Forms.Label
$TAB2HEADER.Font      = New-Object System.Drawing.Font( "Calibri",11,[System.Drawing.FontStyle]::Bold ) 
$TAB2HEADER.Location  = '50,30'
$TAB2HEADER.Size      = '620,30'
$TAB2HEADER.Text      = "This tab will create a response group."
$TAB2.Controls.Add( $TAB2HEADER )




# ///////////////

#Tab 2 Add Users to Hunt Group
$TABAGENTSL           = New-Object System.Windows.Forms.Label
$TABAGENTSL.Font      = New-Object System.Drawing.Font( "Calibri",8,[System.Drawing.FontStyle]::Bold )
$TABAGENTSL.Location  = '50,420'
$TABAGENTSL.Size      = '200,20'
$TABAGENTSL.Text      = "Who do you want adding to the group?"
$TAB2.Controls.Add( $TABAGENTSL )

#Tab 2 Open File Button
$TAB2IMPORT           = New-Object System.Windows.Forms.Button
$TAB2IMPORT.Location  = '50,450'
$TAB2IMPORT.Size      = '80,20'
$TAB2IMPORT.Text      = "File Import"
$TAB2.Controls.Add( $TAB2IMPORT )
$TAB2IMPORT.Add_Click( { $TAB2IMPORT = OpenFileDialog ; ImportUsers } )



# ///////////////

#Tab 2 ListBox for Users
$TAB2LISTBOX          = New-Object System.Windows.Forms.CheckedListBox
$TAB2LISTBOX.Location = '320,120'
$TAB2LISTBOX.Size     = '200,200'
$TAB2.Controls.Add( $TAB2LISTBOX )

#Tab 2 Listbox Help
$TAB2LISTL            = New-Object System.Windows.Forms.Label
$TAB2LISTL.Font       = New-Object System.Drawing.Font( "Calibri",8,[System.Drawing.FontStyle]::Italic ) 
$TAB2LISTL.Location   = '550,120'
$TAB2LISTL.Size       = '150,80'
$TAB2LISTL.Text       = "All names within the list will be added to the response group. `nThose checked will be designated response group admins"
$TAB2LISTL.Visible    = $FALSE
$TAB2.Controls.Add( $TAB2LISTL )

$TAB2LISTMU           = New-Object System.Windows.Forms.Button
$TAB2LISTMU.Location  = '530,260'
$TAB2LISTMU.Text      = "&Move Up"
$TAB2.Controls.Add( $TAB2LISTMU )


$SDC.Add_Shown( { $SDC.Activate() } )


$SDC.ShowDialog()
我为VisualStudio购买了PowerShell Pro Tools,但遇到了同样的障碍,如果我不知道首先需要使用什么工具,我无法从屏幕上可用的选项中找到答案。因此,我一直住在伊塞,直到我死


任何帮助都将不胜感激。谢谢

我找到了一个关于如何做的链接

*编辑

我“清理”了代码以供自己使用,如下所示:

#Function for Move Down
Function MoveDown {
  IF ( ( $TAB2LISTBOX.SelectedIndex -ne -1 ) -and ( $TAB2LISTBOX.SelectedIndex -lt $TAB2LISTBOX.Items.Count - 1 ) )
     { $TAB2LISTBOX.BeginUpdate()
       $SELECTITEM = $TAB2LISTBOX.SelectedIndex 
       $TAB2LISTBOX.Items.Insert( $SELECTITEM, $TAB2LISTBOX.Items.Item( $SELECTITEM +1 ) )
       $TAB2LISTBOX.Items.RemoveAt( $SELECTITEM +2 )
       $TAB2LISTBOX.SelectedIndex = ( $SELECTITEM +1 )
       $TAB2LISTBOX.EndUpdate() } }


#Function for Move Up
Function MoveUp {
  IF ( $TAB2LISTBOX.SelectedIndex -gt 0 )
     { $TAB2LISTBOX.BeginUpdate()
       $SELECTITEM = $TAB2LISTBOX.selectedIndex
       $TAB2LISTBOX.Items.Insert( $SELECTITEM -1, $TAB2LISTBOX.Items.Item( $SELECTITEM ) )
       $TAB2LISTBOX.SelectedIndex = ( $SELECTITEM -1 )
       $TAB2LISTBOX.Items.RemoveAt( $SELECTITEM +1 )
       $TAB2LISTBOX.EndUpdate() } }

下面是一个C#示例,它看起来只是在更改项目索引:如果您在button对象上访问相同的方法,则通过Powershell似乎是可行的。有趣的是,您应该链接到该威胁,因为这正是我几天来一直试图破译的威胁。我知道这是可以做到的,只是从C中找出PowerShell命令#