即使关闭颜色对话框,如何存储自定义颜色 [英] How to store custom color even if the color dialog box was closed

查看:79
本文介绍了即使关闭颜色对话框,如何存储自定义颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以为特定实例存储自定义颜色的颜色。

一旦颜色对话框关闭,如果它再次打开,所选颜色就会被删除。



如何摆脱这个

I can store a color in custom color for particular instance.
As soon as the color dialog box closes and if it was opened again the selected color gets deleted.

How to get rid of this

推荐答案

通过使用自定义颜色对话框作为静态属性(例如在主体中)只在第一次调用时创建,然后重复使用。

By using the custom color dialog as a static property (in the main from for example) that is created only at its first invocation, then reused.
public Form MainForm
{
protected static ColorDialog _colorDialog = null;


protected void UsageOfColorSelection(...)
{

if(_colorDialog == null)
{
_colorDialog = new ColorDialog();
}

 if (_colorDialog.ShowDialog() == DialogResult.OK)
        textBox1.ForeColor =  colorDialog.Color;
//...


}
}


实际上,它不正确说我在这个答案中向你展示的自定义颜色定义:[ ^ ] ...不要保留。只要您的应用程序正在运行,它们就会持续存在。



当您退出应用程序时,它们当然会被清除。



所以,关于如何保存它们的问题,以及下次运行应用程序时它们是否可用,是你想要保存任何时候必须回答的问题/ i>应用程序设置。



CustomColors可用作ColorDialog对象的属性:[ ^ ]。它是一个由16个整数组成的数组,其中每个整数代表一个Color。每个插槽的默认值...未定义...是#16777215,这是白色。



有多种方法可以保存应用程序设置,并恢复它们。这些包括应用程序设置,序列化和其他方法。



我建议你从这里开始学习Application.Settings:[ ^ ]。一旦开始,并知道如何创建应用程序设置,设置并恢复它,在这里询问具体问题。



请记住,目标,对于许多人在这里,我们回答问题的方法是帮助人们成为更好的程序员,教学,启用。
Actually, it is incorrect to say that Custom Colors defined in the way I showed you in this answer: [^] ... do not persist. They do persist, as long as your Application is running.

They are, of course, cleared when you quit your Application.

So, the question of how to save them, so they'll be available the next time you run your Application, is the same question you have to answer any time you want to save any Application Setting.

The CustomColors are available as a Property of the ColorDialog object: [^]. It's an array of 16 integers where each integer represents a Color. The default for each "slot" ... undefined ... is #16777215, which is White.

There are a variety of ways to approach saving Application settings, and restoring them. These include Application Settings, Serialization, and other methods.

I suggest you start here, and study Application.Settings: [^]. Once you get started, and know how to create an Application Setting, set it, and restore it, ask specific questions here.

Please remember that the goal, for many of us answering questions, here, is to help people become better programmers, to teach, to enable.


这篇关于即使关闭颜色对话框,如何存储自定义颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆