Drag-n-drop

Welcome Forums General PowerShell Q&A Drag-n-drop

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
6 months, 3 weeks ago.

  • Author
    Posts
  • #97131

    Participant

    Hallo, i need help with my code:

    [void] [reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")

    $form= New-Object Windows.Forms.Form
    $Form.FormBorderStyle=[System.Windows.Forms.FormBorderStyle]::FixedDialog
    $Image = [system.drawing.image]::FromFile("C:\Users\wn00099713\Desktop\VPNcopy\vpn3.png")

    $Form.BackgroundImage = $Image
    $Form.Width = $Image.Width
    $Form.Height = $Image.Height
    $Form.MinimizeBox = $False
    $Form.MaximizeBox = $False
    $Form.SizeGripStyle = "Hide"
    $Form.WindowState = "Normal"
    $form.text = "VPN"
    $Form.KeyPreview = $True
    #$Form.Add_KeyDown({if ($_.KeyCode -eq "Enter"){copyfile}})
    $Form.Add_KeyDown({if ($_.KeyCode -eq "Escape"){$Form.Close()}})

    $form2= New-Object Windows.Forms.Form
    $Form2.AutoSize = $True
    $Form2.AutoSizeMode = "GrowAndShrink"
    $Form2.MinimizeBox = $False
    $Form2.MaximizeBox = $False
    $Form2.SizeGripStyle = "Hide"
    $Form2.StartPosition = "WindowsDefaultLocation"
    $Form2.WindowState = "Normal"
    $Form2.BackColor = "navy"
    $Form2.ForeColor = "white"
    $form2.text = "Informace"
    $Form2.KeyPreview = $True
    $Form2.Add_KeyDown({if ($_.KeyCode -eq "Escape"){$Form2.Close()}})

    Add-Type -AssemblyName System.DirectoryServices.AccountManagement;
    $DisplayName = [System.DirectoryServices.AccountManagement.UserPrincipal]::Current.DisplayName;

    function script:kopirovani {
    Copy-Item "$filename" -Destination "C:\Program Files\OpenVPN\config"
    }

    function script:dadclr {
    $listBox.Items.Clear()
    }

    $Instalace = New-Object System.Windows.Forms.Button
    $Instalace.Location = New-Object System.Drawing.Size(0,75)
    $Instalace.Size = New-Object System.Drawing.Size(472,30)
    $Instalace.ForeColor = "White"
    $Instalace.BackColor = "Navy"
    $Instalace.Font = New-Object System.Drawing.Font("Verdana",13,[System.Drawing.FontStyle]::bold)
    $Instalace.Text = "Kompletní instalace pro $DisplayName"
    $Instalace.Add_Click({copyfile})

    $listBox = New-Object Windows.Forms.ListBox
    $listBox.Font = New-Object System.Drawing.Font("Verdana",12,[System.Drawing.FontStyle]::regular)
    $listBox.Location = New-Object System.Drawing.Size(0,105)
    $listBox.Size = New-Object System.Drawing.Size(472,100)
    $listBox.Dock = [System.Windows.Forms.DockStyle]::None
    $handler = {
    if ($_.Data.GetDataPresent([Windows.Forms.DataFormats]::FileDrop)) {
    foreach ($filename in $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)) {
    $listBox.Items.Add($filename)
    }
    }
    }

    $form.AllowDrop = $true
    $form.Add_DragEnter($handler)

    Function script:copyfile {
    foreach ($filename in $_.Data.GetData) {
    Copy-Item -Path "$filename" -Destination "C:\Program Files\OpenVPN\config"
    }
    }

    I need that when i click on Button "Kompletní instalace pro $DisplayName" (Its $Instalace), that i will copy from D and Drop listbox to any path in PC.

    Here is the problem. Doesnt work!

  • #97215

    Keymaster

    Unfortunately, because you didn't format your code as asked in the bullets above the posting text box, I'm not able to follow it and help.

    It'd also help if you could just narrow down the code you post to the code in question – it makes it a lot easier to see where the problem might be.

The topic ‘Drag-n-drop’ is closed to new replies.