简体   繁体   English

将颜色对话框结果解析为画笔

[英]Parse color dialog results into brush

How do I parse the result from a color dialog so that I can set the color of a brush to its value? 如何解析颜色对话框中的结果,以便可以将画笔的颜色设置为其值?

This is what I have and what I want to do. 这就是我所拥有的,我想做的。

 let b = Brushes.Black
 btnColor.Click.Add(fun _ ->
 ColorDialog.ShowDialog() (* Here I want to set the selected color to my brush b *) |> ignore )

I'll take a guess that you're talking about System.Windows.Forms here. 我猜您在这里谈论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))

See the Values docs for more info on mutable. 有关可变的更多信息,请参见值文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM