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

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

1 year, 1 month ago.

  • Author
  • #97131

    Topics: 3
    Replies: 3
    Points: 0
    Rank: Member

    Hallo, i need help with my code:

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

    $form= New-Object Windows.Forms.Form
    $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 {

    $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"

    $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)) {

    $form.AllowDrop = $true

    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

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort