Advertisement
Guest User

Untitled

a guest
Nov 7th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.00 KB | None | 0 0
  1. // Funzione per trovare il font della dimensione adatta
  2. let FindFont (g : Graphics) (str : string) (box : SizeF) (preferredfont : Font) =
  3.   let stringsize = g.MeasureString(str, preferredfont)
  4.   let scaleRatio = min (box.Height / stringsize.Height) (box.Width / stringsize.Width)
  5.   let scalefontsize = scaleRatio * preferredfont.Size
  6.   new Font(preferredfont.FontFamily, float32 scalefontsize)
  7.  
  8. type PIGlyph() =
  9.   inherit LWControl()
  10.   let mutable letter = 'A'
  11.   let mutable letterSize = 12.0f
  12.  
  13.   member this.Lettera
  14.     with get() = letter
  15.     and set(v) = letter <- v
  16.    
  17.   member this.LetterSize
  18.     with get() = letterSize
  19.     and set(v) = letterSize <- v
  20.  
  21.  
  22.   override this.OnPaint e =
  23.     let parent = this.Parent
  24.     let g = e.Graphics
  25.     let r = RectangleF(this.Position, this.Size) |> RectF2Rect
  26.     g.DrawRectangle(Pens.Red, r)
  27.  
  28.     let fittingfont = FindFont g (string letter) this.Size FontArray.[curFontIndex]
  29.     g.DrawString(string letter, fittingfont, Brushes.Black, this.Position)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement