[英]Getting the color object from ColorDialog.color.name
In my winforms application I have a ColorDialog control and when the user select a color, I save the Name of the color object. 在我的winforms应用程序中,我有一个ColorDialog控件,当用户选择一种颜色时,我将保存颜色对象的名称。 For a custom color value starts with FF ex: fffdfcc8 (This is a light yellow / cream color)
对于自定义颜色值,以FF开头:fffdfcc8(这是浅黄色/乳白色)
Some where later I want to get to the color object from the color name string, fffdfcc8 to a system.drawing.color object. 稍后,我想从颜色名称字符串fffdfcc8到system.drawing.color对象访问颜色对象。 How can I do this???
我怎样才能做到这一点???
Dim dlgColor As New ColorDialog()
dlgColor.AllowFullOpen = True
dlgColor.AnyColor = True
If dlgColor.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
DgView.CurrentCell.Text = dlgColor.Color.Name
End If
How to create color object based on the name value in DgView.CurrentCell.Text 如何基于DgView.CurrentCell.Text中的名称值创建颜色对象
UPDATE2: Adding # in front of the custom name value and using the System.Drawing.ColorTranslator.FromHtml("#" & color)
does get the job done. UPDATE2:在自定义名称值之前添加#并使用
System.Drawing.ColorTranslator.FromHtml("#" & color)
确实可以完成工作。 Not sure what to do next since to me it was not that obvious...leave it up to the moderator to decide 不知道下一步该怎么做,因为对我来说还不那么明显...让主持人决定
UPDATE: This is not a duplicate since the name value is not a hex value. 更新:这不是重复的,因为名称值不是十六进制值。
Prefix # to the custom name and use it like this should work. 给自定义名称添加前缀#,然后像这样使用它就可以了。 As indicated in the comments and updates.
如评论和更新所示。 Thanks to Phiter Fernandes for the help.
感谢Phiter Fernandes的帮助。
Dim strColor = DgView.CurrentCell.Text
System.Drawing.ColorTranslator.FromHtml("#" & strColor)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.