Mattersphere Developers Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
avatar
Admin
Admin
Posts : 122
Join date : 2018-12-17
https://mattersphere-devs.forumotion.com

Altering the ForeColor of a Control Empty Altering the ForeColor of a Control

Thu 23 Jan 2020 - 15:04
How do I change the fore colour of a control in C#. Essentially, I want it to change to red based on one criteria, and black on another.
________________________________________________________________________________________________________________________________
Hi
This should do it for our textbox.
Code:

FWBS.Common.UI.Windows.eTextBox2 ctrl = EnquiryForm.GetControl("TextBox1") as FWBS.Common.UI.Windows.eTextBox2;
TextBox innerctrl = ctrl.Control as TextBox;
innerctrl.ForeColor = System.Drawing.Color.Red;

If you could tell me the control you are using. I can tailor a better example
Regards
Danny
________________________________________________________________________________________________________________________________
Thanks, Danny. The control is called OCcost1 and it's a textbox.
________________________________________________________________________________________________________________________________
Hi
Great yes my sample should be correct. Simply change the name I use to OCcost1
Code:

FWBS.Common.UI.Windows.eTextBox2 ctrl = EnquiryForm.GetControl("OCcost1") as FWBS.Common.UI.Windows.eTextBox2;

Regards
Danny
________________________________________________________________________________________________________________________________
Danny,

I get this error when trying to apply the code:
Code:

at OMS.Scriptlets.UDSCRINVFPEX.ocoverride_Changed(Object sender, EventArgs e) in
    c:\Users\cliffp\AppData\Local\Temp\yrm10ggj.0.cs:line 59 at System.EventHandler.Invoke(Object sender, EventArgs e) at
    FWBS.Common.UI.Windows.eCheckBox2.OnChanged()
    at FWBS.Common.UI.Windows.eCheckBox2.RaiseChangedEvent(Object sender, EventArgs e)
    at System.Windows.Forms.Control.OnLeave(EventArgs e)
    at System.Windows.Forms.Control.NotifyLeave()
    at System.Windows.Forms.ContainerControl.UpdateFocusedControl()
________________________________________________________________________________________________________________________________
Danny, Just seen it's not a text box but an eCurrency?
________________________________________________________________________________________________________________________________
Hi
This should do it.
Code:

FWBS.OMS.UI.Windows.eCurrency ctrl = EnquiryForm.GetControl("OCcost1") as FWBS.OMS.UI.Windows.eCurrency;
TextBox innerctrl = ctrl.Control as TextBox;
innerctrl.ForeColor = System.Drawing.Color.Red;
Regards
Danny
________________________________________________________________________________________________________________________________
Hi, Danny. I get this error when compiling: Performing main compilation... error:
Code:

The type or namespace name 'eCurrency' does not exist in the namespace 'FWBS.Common.UI.Windows' (are you missing an assembly reference?) Line 58 error: The type or namespace name 'eCurrency' does not exist in the namespace 'FWBS.Common.UI.Windows' (are you missing an assembly reference?) Line 58 Build complete -- 2 errors.
________________________________________________________________________________________________________________________________
Hi
I think you have put in the wrong name space see in bold
[code]
FWBS.OMS.UI.Windows.eCurrency ctrl = EnquiryForm.GetControl("OCcost1") as
[\code]
________________________________________________________________________________________________________________________________
Perfect.
Thanks, Danny.
Back to top
Permissions in this forum:
You cannot reply to topics in this forum