Click here to Skip to main content
15,886,631 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
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?
Posted
Updated 24-Oct-11 21:44pm
v2
Comments
Sergey Alexandrovich Kryukov 25-Oct-11 3:43am    
Why irritating the user with different colors for different values? I bet it would drive most of the crazy.
--SA
OriginalGriff 25-Oct-11 3:46am    
No, it's an old standard - negative numbers are often shown in Red, while positive numbers are in Black.
Excel still provides this as a standard option in the number formatting properties.
Sergey Alexandrovich Kryukov 25-Oct-11 3:50am    
Aha, this is because so many people still leave in the world when negative numbers were not yet introduced. Who did it? Indians, Arabs. Hm, "standard". You also mention accountant's "()" format for negatives. What a lame!
--SA

Try:

VB
Public Property NegativeColor() As Color
	Get
		Return m_NegativeColor
	End Get
	Set
		m_NegativeColor = Value
	End Set
End Property
Private m_NegativeColor As Color
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Oct-11 3:54am    
No Griff, such setter will leave BackColor unchanged, if the user assigns negative color when numeric is negative or positive color when it is not. You need to check if the color is changed and also call the method which assigns BackColor (and this property itself calls Invalidate), this way it will work correctly. (I did not vote this time.)
--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
 
Share this answer
 
v2
Comments
fadi77_net 25-Oct-11 4:17am    
thank you SAKryukov
but I want to give the developer the ability to set the color if he want, but if he dont want to do that, it is up to him.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900