如何从颜色对话框中解析结果,以便我可以将画笔的颜色设置为其值?
这就是我拥有的和我想做的事。
let b = Brushes.Black
btnColor.Click.Add(fun _ ->
ColorDialog.ShowDialog() (* Here I want to set the selected color to my brush b *) |> ignore )
答案 0 :(得分:4)
我猜你在这里谈论System.Windows.Forms
。
open System.Drawing
open System.Windows.Forms
let getColorFromUser initialColor =
use dlg = new ColorDialog(Color = initialColor)
if dlg.ShowDialog() = DialogResult.OK then
dlg.Color
else
initialColor
// example with mutation
let mutable b = new SolidBrush(Color.Black)
b <- new SolidBrush(getColorFromUser(Color.Black))
有关mutable的更多信息,请参阅Values docs。