I have been having an issue for a while. I created a custom control based on a textbox in Visual Studios. I am trying to get the background to change color based on the text in the custom control. I haven't even got that far yet. When I change the background color of the component it seems to be in the foreground and covers the text that is written in the custom control. The current code I have is
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace ctlNumericTextBox
{
public class AToDTextBox : System.Windows.Forms.TextBox
{
public int converterRange;
public float voltageRange;
public int analogToDigitalValue; //Analogue Input Value
public int maximumVoltage; //Max Allowed Voltage
public float dynamicVoltage; //(analogToDigitalValue/converterRange) * maximumVoltage
public Color controlColourGood = Color.Window;
public Color controlColourBad = Color.Red;
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
//var displayValue = ADVAL
}
public AToDTextBox()
{
AToDTextBox customText = new AToDTextBox();
customText.BackColor = controlColourGood;
}
public void SetRanges(int rangeForConversion, float rangeForVoltage)
{
converterRange = rangeForConversion;
voltageRange = rangeForVoltage;
}
public void SetAtoDValue(int value)
{
analogToDigitalValue = value;
dynamicVoltage = (analogToDigitalValue / converterRange) * maximumVoltage;
this.Text = dynamicVoltage.ToString();
}
}
}