Guest User

Untitled

a guest
Oct 28th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 3.25 KB | None | 0 0
  1. open System
  2. open System.Drawing
  3. open System.Windows.Forms
  4. open System.Windows.Forms.DataVisualization.Charting
  5. open System.IO
  6.  
  7. type FileMetaData = {Name: string; Size: int64;}
  8.  
  9. module FileData =
  10.     let GetFileList (path:string)  =
  11.         DirectoryInfo(path).EnumerateFiles("*",SearchOption.AllDirectories)
  12.         |> Seq.map(fun x -> {Name = x.FullName; Size = x.Length})
  13.  
  14.     let getFileMetadata paths = paths |> Seq.collect GetFileList |> List.ofSeq
  15.  
  16. type public MainForm() as form =
  17.     inherit Form()
  18.  
  19.     // TODO define your controls
  20.     let button1 = new Button()
  21.     let button2 = new Button()
  22.     let button3 = new Button()
  23.     let listbox = new ListBox()
  24.     let textbox = new TextBox()
  25.     let picture = new PictureBox()
  26.  
  27.     // TODO initialize your controls
  28.     let initControls() =
  29.         //listbox.FormattingEnabled <- true
  30.         listbox.Location <- Point(12, 91)
  31.         listbox.Size <- Size(183, 368)
  32.  
  33.         button1.Location <- Point(13, 13)
  34.         button1.Size <- Drawing.Size(75, 23)
  35.         button1.Text <- "Выбрать папку"
  36.  
  37.         button2.Location <- Point(121, 12)
  38.         button2.Size <- Size(75, 23)
  39.         button2.Text <- "Очистить"
  40.  
  41.         button3.Location <- Point(215, 12)
  42.         button3.Size <- Size(75, 23)
  43.         button3.Text <- "Построить"
  44.  
  45.         textbox.Location <- Point(13, 53)
  46.         textbox.Size <- Size(559, 20)
  47.  
  48.         picture.Size <- Size(357, 368)
  49.         picture.Location <- Point(215, 91)
  50.  
  51.         button1.Click.AddHandler(new EventHandler
  52.             (fun sender e -> form.SelectFolder(sender, e)))  
  53.              
  54.         button2.Click.AddHandler(new EventHandler
  55.             (fun sender e -> form.ClearFolder(sender, e)))  
  56.  
  57.         button3.Click.AddHandler(new EventHandler
  58.             (fun sender e -> form.Plot(sender, e)))  
  59.     do
  60.         form.SuspendLayout();
  61.         initControls()
  62.  
  63.         // TODO add controls to the form
  64.         form.Controls.Add(button1)
  65.         form.Controls.Add(button2)
  66.         form.Controls.Add(button3)
  67.         form.Controls.Add(textbox)
  68.         form.Controls.Add(listbox)
  69.         form.Controls.Add(picture)
  70.         // TODO define form properties
  71.         form.AutoScaleDimensions <- SizeF(6.0f, 13.0f)
  72.         form.AutoScaleMode <- AutoScaleMode.Font
  73.         form.ClientSize <- new Size(584, 471)
  74.         form.Text <- "Main Form"
  75.  
  76.         // render the form
  77.         form.ResumeLayout(false)
  78.         form.PerformLayout()
  79.  
  80.     // TODO define your event handlers
  81.     member form.SelectFolder(sender:obj, e:EventArgs) =
  82.         use dialog = new FolderBrowserDialog(RootFolder = Environment.SpecialFolder.MyComputer)
  83.         if dialog.ShowDialog() = DialogResult.OK then
  84.             listbox.Items.Add(dialog.SelectedPath) |> ignore
  85.         ()
  86.  
  87.     member form.ClearFolder(sender:obj, e:EventArgs) =
  88.         listbox.Items.Clear()
  89.         ()
  90.  
  91.     member form.Plot(sender:obj, e:EventArgs) =
  92.         let filelist =
  93.             [ for x in listbox.Items -> x ]
  94.             |> List.map(string)
  95.             |> FileData.getFileMetadata
  96.             |> List.map(fun y -> y.Name, y.Size)
  97.        
  98.         let chart1 = FSharp.Charting.Chart.Column filelist
  99.  
  100.         picture.Image <- chart1.CopyAsBitmap()
  101.         ()
Advertisement
Add Comment
Please, Sign In to add comment