4 people like it.

Basic WinForms drag and drop

Quick example of using drag-n-drop with WinForms.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
open System
open System.Windows.Forms

let lbl = new Label(Text = "Label")
lbl.Height <- 200
let img = 
    let temp = new PictureBox(Top=40, Left=8, Width=128, Height= 128, SizeMode=PictureBoxSizeMode.StretchImage, AllowDrop=true)
    temp.DragEnter.Add(fun args ->
        lbl.Text <- "DragEnter: " + String.Join(", ", args.Data.GetFormats())
        args.Effect <- DragDropEffects.All
        )
    temp.DragDrop.Add(fun args ->
        lbl.Text <- "dropped"
        )
    temp

[<STAThreadAttribute>]
do 
    let frm = new Form()
    let panel = new FlowLayoutPanel()
    panel.Dock <- DockStyle.Fill
    frm.Controls.Add panel
    panel.Controls.Add img
    panel.Controls.Add lbl
    Application.Run frm
namespace System
namespace System.Windows
namespace System.Windows.Forms
val lbl : Label

Full name: Script.lbl
Multiple items
type Label =
  inherit Control
  new : unit -> Label
  member AutoEllipsis : bool with get, set
  member AutoSize : bool with get, set
  member BackgroundImage : Image with get, set
  member BackgroundImageLayout : ImageLayout with get, set
  member BorderStyle : BorderStyle with get, set
  member FlatStyle : FlatStyle with get, set
  member GetPreferredSize : proposedSize:Size -> Size
  member Image : Image with get, set
  member ImageAlign : ContentAlignment with get, set
  ...

Full name: System.Windows.Forms.Label

--------------------
Label() : unit
namespace System.Text
property Control.Height: int
val img : PictureBox

Full name: Script.img
val temp : PictureBox
Multiple items
type PictureBox =
  inherit Control
  new : unit -> PictureBox
  member AllowDrop : bool with get, set
  member BorderStyle : BorderStyle with get, set
  member CancelAsync : unit -> unit
  member CausesValidation : bool with get, set
  member ErrorImage : Image with get, set
  member Font : Font with get, set
  member ForeColor : Color with get, set
  member Image : Image with get, set
  member ImageLocation : string with get, set
  ...

Full name: System.Windows.Forms.PictureBox

--------------------
PictureBox() : unit
type PictureBoxSizeMode =
  | Normal = 0
  | StretchImage = 1
  | AutoSize = 2
  | CenterImage = 3
  | Zoom = 4

Full name: System.Windows.Forms.PictureBoxSizeMode
field PictureBoxSizeMode.StretchImage = 1
event Control.DragEnter: IEvent<DragEventHandler,DragEventArgs>
member IObservable.Add : callback:('T -> unit) -> unit
val args : DragEventArgs
property Label.Text: string
Multiple items
type String =
  new : value:char -> string + 7 overloads
  member Chars : int -> char
  member Clone : unit -> obj
  member CompareTo : value:obj -> int + 1 overload
  member Contains : value:string -> bool
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EndsWith : value:string -> bool + 2 overloads
  member Equals : obj:obj -> bool + 2 overloads
  member GetEnumerator : unit -> CharEnumerator
  member GetHashCode : unit -> int
  ...

Full name: System.String

--------------------
String(value: nativeptr<char>) : unit
String(value: nativeptr<sbyte>) : unit
String(value: char []) : unit
String(c: char, count: int) : unit
String(value: nativeptr<char>, startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int) : unit
String(value: char [], startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : unit
String.Join(separator: string, values: Collections.Generic.IEnumerable<string>) : string
String.Join<'T>(separator: string, values: Collections.Generic.IEnumerable<'T>) : string
String.Join(separator: string, [<ParamArray>] values: obj []) : string
String.Join(separator: string, [<ParamArray>] value: string []) : string
String.Join(separator: string, value: string [], startIndex: int, count: int) : string
property DragEventArgs.Data: IDataObject
IDataObject.GetFormats() : string []
IDataObject.GetFormats(autoConvert: bool) : string []
property DragEventArgs.Effect: DragDropEffects
type DragDropEffects =
  | None = 0
  | Copy = 1
  | Move = 2
  | Link = 4
  | Scroll = -2147483648
  | All = -2147483645

Full name: System.Windows.Forms.DragDropEffects
field DragDropEffects.All = -2147483645
event Control.DragDrop: IEvent<DragEventHandler,DragEventArgs>
Multiple items
type STAThreadAttribute =
  inherit Attribute
  new : unit -> STAThreadAttribute

Full name: System.STAThreadAttribute

--------------------
STAThreadAttribute() : unit
val frm : Form
Multiple items
type Form =
  inherit ContainerControl
  new : unit -> Form
  member AcceptButton : IButtonControl with get, set
  member Activate : unit -> unit
  member ActiveMdiChild : Form
  member AddOwnedForm : ownedForm:Form -> unit
  member AllowTransparency : bool with get, set
  member AutoScale : bool with get, set
  member AutoScaleBaseSize : Size with get, set
  member AutoScroll : bool with get, set
  member AutoSize : bool with get, set
  ...
  nested type ControlCollection

Full name: System.Windows.Forms.Form

--------------------
Form() : unit
val panel : FlowLayoutPanel
Multiple items
type FlowLayoutPanel =
  inherit Panel
  new : unit -> FlowLayoutPanel
  member FlowDirection : FlowDirection with get, set
  member GetFlowBreak : control:Control -> bool
  member LayoutEngine : LayoutEngine
  member SetFlowBreak : control:Control * value:bool -> unit
  member WrapContents : bool with get, set

Full name: System.Windows.Forms.FlowLayoutPanel

--------------------
FlowLayoutPanel() : unit
property Control.Dock: DockStyle
type DockStyle =
  | None = 0
  | Top = 1
  | Bottom = 2
  | Left = 3
  | Right = 4
  | Fill = 5

Full name: System.Windows.Forms.DockStyle
field DockStyle.Fill = 5
property Control.Controls: Control.ControlCollection
Control.ControlCollection.Add(value: Control) : unit
type Application =
  static member AddMessageFilter : value:IMessageFilter -> unit
  static member AllowQuit : bool
  static member CommonAppDataPath : string
  static member CommonAppDataRegistry : RegistryKey
  static member CompanyName : string
  static member CurrentCulture : CultureInfo with get, set
  static member CurrentInputLanguage : InputLanguage with get, set
  static member DoEvents : unit -> unit
  static member EnableVisualStyles : unit -> unit
  static member ExecutablePath : string
  ...
  nested type MessageLoopCallback

Full name: System.Windows.Forms.Application
Application.Run() : unit
Application.Run(context: ApplicationContext) : unit
Application.Run(mainForm: Form) : unit
Raw view New version

More information

Link:http://fssnip.net/6X
Posted:8 years ago
Author:MichaelGG
Tags: winforms , events