Skip to content

Instantly share code, notes, and snippets.

@Pitasi Pitasi/bottone.fsx
Created Oct 7, 2016

Embed
What would you like to do?
open System.Windows.Forms
open System.Drawing
type Bottone() =
inherit UserControl()
let mutable FColor = Color.Red
let mutable SColor = Color.FromArgb(175, 0, 0, 0)
let mutable STickness = 3
let mutable LText = ""
member this.ForegroundColor
with get() = FColor
and set(v) = FColor <- v
member this.ShadowTickness
with get() = STickness
and set(v) = STickness <- v
member this.LabelText
with get() = LText
and set(v) = LText <- v
override this.OnPaint e =
let g = e.Graphics
g.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
let w, h = this.Width, this.Height
let r = new Rectangle(Point(0, 0), this.Size)
use MainBrush = new SolidBrush(FColor)
use ShadowBrush = new SolidBrush(SColor)
// rettangolo
g.FillRectangle(MainBrush, r)
// effetto ombra in basso a destra
use p = new Pen(ShadowBrush, Width=single(STickness))
g.DrawLine(p, w-(STickness/2), 0, w-(STickness/2), h)
g.DrawLine(p, 0, h-(STickness/2), w-(STickness/2), h-(STickness/2))
// effetto luce in alto a sinistra
use p = new Pen(Brushes.White, Width=2.f)
g.DrawLine(p, 0, 0, w, 0)
g.DrawLine(p, 0, 0, 0, h)
// testo
let margin = 10
let l = new Label(
Location=Point(margin/2, margin/2), // margine
Size=Size(this.Size.Width - 10, this.Size.Height - 10), // per il testo
BackColor=Color.FromArgb(0, 0, 0, 0),
TextAlign=ContentAlignment.MiddleCenter,
Text=LText)
this.Controls.Add(l)
let f = new Form(Text="Bottoni", TopMost=true)
f.Show()
let b = new Bottone(
Location=Point(10, 10),
Size=Size(200,100),
ForegroundColor=Color.Gold,
ShadowTickness=2,
LabelText="Io sono un bottone"
)
f.Controls.Add(b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.