system.drawing.color

How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color

五迷三道 提交于 2020-01-04 06:07:48
问题 I'm developing a vsto addin for Excel, and I'm trying to change the color to the comments in Excel. This is the code that I have: Excel.Range activeCell = _application.ActiveCell; activeCell.AddComment("some text")); activeCell.Comment.Shape.Fill.BackColor = Color.Red; The exception I'm getting is: Cannot implicitly convert type 'System.Drawing.Color' to 'Microsoft.Office.Interop.Excel.ColorFormat' I cannot find how to make a conversion between the two formats. 回答1: One option is to use

Extension method library for actions on System.Drawing.Color

安稳与你 提交于 2020-01-01 11:55:10
问题 Has anyone written a nice extension method 'library' for System.Drawing.Color. Would be nice to say : Color.Red.AdjustBrightness(.5) Color.Red.AdjustAlpha(.5) Color.Red.ToHSV() or something like that. Alpha is easy, but others become time consuming because you have to go off and fine all the right mathematical equations for HSV and HSB and all that fun stuff. Hoping someone else had done the work already :-) Microsoft doesn't seem to want to do it for me. 回答1: CodeProject has some code for an

Extension method library for actions on System.Drawing.Color

空扰寡人 提交于 2020-01-01 11:54:09
问题 Has anyone written a nice extension method 'library' for System.Drawing.Color. Would be nice to say : Color.Red.AdjustBrightness(.5) Color.Red.AdjustAlpha(.5) Color.Red.ToHSV() or something like that. Alpha is easy, but others become time consuming because you have to go off and fine all the right mathematical equations for HSV and HSB and all that fun stuff. Hoping someone else had done the work already :-) Microsoft doesn't seem to want to do it for me. 回答1: CodeProject has some code for an

System.Drawing.Brush from System.Drawing.Color

南楼画角 提交于 2019-12-28 06:19:11
问题 I'm developing a WinForm Printing application for our company. When the document is printed, I need to take the System.Drawing.Color property of each Control on the document and create a System.Drawing.Brush object to draw it. Is there a way to convert the System.Drawing.Color value to a System.Drawing.Brush value? NOTE: I've tried looking into the System.Windows.Media.SolidColorBrush() method, but it does not seem to be helpful. 回答1: Use the SolidBrush class: using (SolidBrush brush = new

System.Drawing.Brush from System.Drawing.Color

☆樱花仙子☆ 提交于 2019-12-28 06:18:26
问题 I'm developing a WinForm Printing application for our company. When the document is printed, I need to take the System.Drawing.Color property of each Control on the document and create a System.Drawing.Brush object to draw it. Is there a way to convert the System.Drawing.Color value to a System.Drawing.Brush value? NOTE: I've tried looking into the System.Windows.Media.SolidColorBrush() method, but it does not seem to be helpful. 回答1: Use the SolidBrush class: using (SolidBrush brush = new

Convert System.Drawing.Color to RGB and Hex Value

人走茶凉 提交于 2019-12-27 11:12:10
问题 Using C# I was trying to develop the following two. The way I am doing it may have some problem and need your kind advice. In addition, I dont know whether there is any existing method to do the same. private static String HexConverter(System.Drawing.Color c) { String rtn = String.Empty; try { rtn = "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2"); } catch (Exception ex) { //doing nothing } return rtn; } private static String RGBConverter(System.Drawing.Color c) { String rtn

Convert System.Drawing.Color to RGB and Hex Value

情到浓时终转凉″ 提交于 2019-12-27 11:12:08
问题 Using C# I was trying to develop the following two. The way I am doing it may have some problem and need your kind advice. In addition, I dont know whether there is any existing method to do the same. private static String HexConverter(System.Drawing.Color c) { String rtn = String.Empty; try { rtn = "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2"); } catch (Exception ex) { //doing nothing } return rtn; } private static String RGBConverter(System.Drawing.Color c) { String rtn

Why does Color.IsNamedColor not work when I create a color using Color.FromArgb()?

ぐ巨炮叔叔 提交于 2019-12-24 05:23:28
问题 In my app I allow the user to build a color, and then show him the name or value of the color later on. If the user picks red (full red, not red-ish), I want to show him "red". If he picks some strange color, then the hex value would be just fine. Here's sample code that demonstrates the problem: static string GetName(int r, int g, int b) { Color c = Color.FromArgb(r, g, b); // Note that specifying a = 255 doesn't make a difference if (c.IsNamedColor) { return c.Name; } else { // return hex

Why does the color after Image.Clear(x) not exactly equal the color x?

China☆狼群 提交于 2019-12-23 03:50:35
问题 The sample code for this issue is largely self-explanatory, so: [Fact] private void Color_in_should_equal_color_out() { var bitmap = new Bitmap(128,128,PixelFormat.Format32bppArgb); var color = Color.FromArgb(30,60,90,120); using (var g = Graphics.FromImage(bitmap)) { g.Clear(color); } var result = bitmap.GetPixel(0,0); Assert.Equal(color, result); } In this instance I would expect the color of the background to be identical to the color I cleared it to. Instead I get this: Assert.Equal()