Use
textbox.Fill.ForeColor.RGB = ColorTranslator.ToWin32(colour);
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I'm trying to create a textbox and fill it with a specific colour.
So far, I managed to do it but the result seems not to match with the colour that I specify.
This is an example:
Color colour = Color.Red; // -> define my colour
Excel.Shape textbox = worksheet.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, (float)x3, (float)y3, 100, 100);
var infoToDisplay = "#####";
textbox.TextFrame.Characters(System.Type.Missing, System.Type.Missing).Text = infoToDisplay;
textbox.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = Color.White.ToArgb(); //-> text in white
textbox.Fill.ForeColor.RGB = colour.ToArgb(); // -> fill colour using a known Color
The result is a Blue fill not Red as I am specifying.
This is the same for different types of shapes e.g. line.
What is happening?
This may be a simple correction but I'm not sure why it happens.
Can anyone support, please?
Thank you.
Regards,
Pedro
Use
textbox.Fill.ForeColor.RGB = ColorTranslator.ToWin32(colour);