如何为您的UserControl创建ForeColor属性 [英] How to create a ForeColor property to your UserControl

查看:83
本文介绍了如何为您的UserControl创建ForeColor属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我正在创建一个数字文本框,我想创建2个属性,分别为NegativeColorPositiveColor,以允许用户选择要为字体设置的颜色,该值是负数还是正数.

您能帮我吗?

Dear all,

I am creating a numeric text box, and I want to create 2 properties, NegativeColor and PositiveColor, to let the user chose color to be set for the font when the value is negative or positive.

Can you help me please?

推荐答案

尝试:

Try:

Public Property NegativeColor() As Color
	Get
		Return m_NegativeColor
	End Get
	Set
		m_NegativeColor = Value
	End Set
End Property
Private m_NegativeColor As Color


只需创建这些两个属性.这里的关键是属性设置器方法:它应该为新值分配一个实现字段,而且还应基于当前数值立即分配属性BackColor,以便可以在渲染时将公开属性的更改考虑在内立即上色.

再一次,我强烈建议您放弃这个想法:这种变化的颜色会激怒用户,甚至不会使他们感到困惑.

—SA
Just create these two properties. The key here is the property setter method: it should assign an implementing field to a new value, but also assign the property BackColor immediately, based on current numeric value, so the change in your exposed property could be taken into account in rendered color immediately.

Once again, I would strongly advise you to give up the idea: such changing color will irritate the users, if not confuse them.

—SA


这篇关于如何为您的UserControl创建ForeColor属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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