- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 2 个 ownerdrawn 组合框。一个是线条颜色选择器——在图片中它不是组合框。另一个是线型选择器。一旦用户在第一个组合中选择了一种颜色,线型选择器组合(参见第二张图片,最后一个组合(一个没有名称)) 必须有相同颜色的线条。
目前是这样显示的
这是两个组合的代码线条颜色选择器
public partial class ColorPicker : ComboBox
{
// Data for each color in the list
public class ColorInfo
{
public string Text { get; set; }
public Color Color { get; set; }
public ColorInfo(string text, Color color)
{
Text = text;
Color = color;
}
}
public ColorPicker()
{
InitializeComponent();
DropDownStyle = ComboBoxStyle.DropDownList;
DrawMode = DrawMode.OwnerDrawFixed;
DrawItem += OnDrawItem;
}
// Populate control with standard colors
public void AddStandardColors()
{
Items.Clear();
Items.Add(new ColorInfo("Black", Color.Black));
Items.Add(new ColorInfo("Blue", Color.Blue));
Items.Add(new ColorInfo("Lime", Color.Lime));
Items.Add(new ColorInfo("Cyan", Color.Cyan));
Items.Add(new ColorInfo("Red", Color.Red));
Items.Add(new ColorInfo("Fuchsia", Color.Fuchsia));
Items.Add(new ColorInfo("Yellow", Color.Yellow));
Items.Add(new ColorInfo("White", Color.White));
Items.Add(new ColorInfo("Navy", Color.Navy));
Items.Add(new ColorInfo("Green", Color.Green));
Items.Add(new ColorInfo("Teal", Color.Teal));
Items.Add(new ColorInfo("Maroon", Color.Maroon));
Items.Add(new ColorInfo("Purple", Color.Purple));
Items.Add(new ColorInfo("Olive", Color.Olive));
Items.Add(new ColorInfo("Gray", Color.Gray));
}
// Draw list item
protected void OnDrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index >= 0)
{
// Get this color
ColorInfo color = (ColorInfo)Items[e.Index];
// Fill background
e.DrawBackground();
// Draw color box
Rectangle rect = new Rectangle();
rect.X = e.Bounds.X + 2;
rect.Y = e.Bounds.Y + 2;
rect.Width = 18;
rect.Height = e.Bounds.Height - 5;
e.Graphics.FillRectangle(new SolidBrush(color.Color), rect);
e.Graphics.DrawRectangle(SystemPens.WindowText, rect);
// Write color name
Brush brush;
if ((e.State & DrawItemState.Selected) != DrawItemState.None)
brush = SystemBrushes.HighlightText;
else
brush = SystemBrushes.WindowText;
e.Graphics.DrawString(color.Text, Font, brush,
e.Bounds.X + rect.X + rect.Width + 2,
e.Bounds.Y + ((e.Bounds.Height - Font.Height) / 2));
// Draw the focus rectangle if appropriate
if ((e.State & DrawItemState.NoFocusRect) == DrawItemState.None)
e.DrawFocusRectangle();
}
}
/// <summary>
/// Gets or sets the currently selected item.
/// </summary>
public new ColorInfo SelectedItem
{
get
{
return (ColorInfo)base.SelectedItem;
}
set
{
base.SelectedItem = value;
}
}
/// <summary>
/// Gets the text of the selected item, or sets the selection to
/// the item with the specified text.
/// </summary>
public new string SelectedText
{
get
{
if (SelectedIndex >= 0)
return SelectedItem.Text;
return String.Empty;
}
set
{
for (int i = 0; i < Items.Count; i++)
{
if (((ColorInfo)Items[i]).Text == value)
{
SelectedIndex = i;
break;
}
}
}
}
/// <summary>
/// Gets the value of the selected item, or sets the selection to
/// the item with the specified value.
/// </summary>
public new int SelectedValue
{
get
{
if (SelectedIndex >= 0)
return SelectedItem.Color.ToArgb();
return Color.White.ToArgb();
}
set
{
for (int i = 0; i < Items.Count; i++)
{
if (((ColorInfo)Items[i]).Color.ToArgb() == value)
{
SelectedIndex = i;
break;
}
}
}
}
}
}
Code for lineselector combo. This is the last combo(the one with no name) on my second picture. : `
public partial class comboBoxLineStyle : ComboBox
{
public comboBoxLineStyle()
{
InitializeComponent();
this.DrawMode = DrawMode.OwnerDrawFixed;
this.DropDownStyle = ComboBoxStyle.DropDownList;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
if (e.Index < 0) { return; }
e.DrawBackground();
ComboBoxItem item = (ComboBoxItem)this.Items[e.Index];
e.Graphics.DrawImage(item.Picture,new Point(e.Bounds.X, e.Bounds.Y));
}
public new Image SelectedItem
{
get
{
return (Image)base.SelectedItem;
}
set
{
base.SelectedItem = value;
}
}
public new Image SelectedValue
{
get
{
return (Image)base.SelectedValue;
}
set
{
base.SelectedValue = value;
}
}
}
public class ComboBoxItem
{
public string text;
public Image Picture;
public int foreColor;
//public override string ToString()
//{
// return text;
//}
public ComboBoxItem() { }
public ComboBoxItem(string pText, Image pValue)
{
text = pText;
Picture = pValue;
}
public ComboBoxItem(string pText, Image pValue, int pColor)
{
text = pText; Picture = pValue; foreColor = pColor;
}
}
}
我访问这些的形式如下:
private void DlgGraphOptions_Load(object sender, EventArgs e)
{
Color selCol = m_SerOpts.GetColor(idxSeries);
int selcolARGB = selCol.ToArgb();
Color color = Color.FromArgb(selcolARGB);
ComboBoxItem item1Solid = new ComboBoxItem("Solid Line",Properties.Resources.Solidline,selcolARGB);
ComboBoxItem item1dash = new ComboBoxItem("Dashed Line", Properties.Resources.dashedline,selcolARGB);
ComboBoxItem item1dashed = new ComboBoxItem("Dashed Line", Properties.Resources.dashdash,selcolARGB);
comboBoxLineStyle1.Items.Add(item1Solid);
comboBoxLineStyle1.Items.Add(item1dash);
comboBoxLineStyle1.Items.Add(item1dashed);
comboBoxLineStyle1.SelectedIndex = 0;
//I prefer doing something like this
comboBoxLineStyle1.ForeColor.ToArgb() = selcolARGB .
}
m_SerOpts.GetColor(idxSeries) 方法返回一个颜色对象,但返回“00fff00”类型的名称值。如果您需要更多解释,请告诉我
`
谢谢你
最佳答案
我会使用反射来填充来自 Color 类的所有颜色的列表(尽管您可以在代码中复制它):
Dictionary<String, Color> colors = typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.Public).ToDictionary(p => p.Name, p => (Color)p.GetValue(null, null) );
然后使用一种方法在这个字典中搜索与传递的颜色匹配的颜色:
public String GetColorName(Color color)
{
return colors.Where(c => c.Value.A == color.A && c.Value.R == color.R && c.Value.G == color.G && c.Value.B == color.B).FirstOrDefault().Key;
}
如果没有匹配到颜色,则返回null。
关于来自 argb 的 C# 颜色名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10875874/
所以我有一个项目可以通过使用算法更改 argb 值来手动将图像转换为黑白图像。我已经尝试对 RGB 值进行平均,我得到了一个几乎完全灰度的图像,但其中仍然有一些颜色。谁有手动将 aRGB 中的像素转换
我有一个 ARGB 图像数据。我希望将我的窗口图标设置为该数据。经过几个小时的搜索后,我仍然处于起点,手头一无所有。我知道我需要为图像数据创建一个像素图和(可能是)另一个用于掩码的像素图,并使用提示来
我正在学习 C#,我试图解决的以下问题是将一个数字存储为字符串并获取 a、r、g、b 值。 所以我想从 string s = "4280427042"; 到 int a = 255; int r =
对于 ARGB 颜色图,我有四个整数值 (0 - 255)。 现在我想制作这四个整数的唯一浮点数或整数。是否可以像下面那样做? sum = 4 * 255 + A; sum += 3 * 255 +
我正在尝试使用 MakeColor GDIPAPI 单元中的方法,但来自 int 的转换至 byte没有返回给我正确的值。 例子 var argbStr: string; A, R,
this 中的颜色表全部不透明。我猜 A 的值设置为 FF。 透明度代码是什么? 例如这个颜色FFF0F8FF(AliceBlue),改为透明代码,如??F0F8FF ? 最佳答案 以下是 % 到十六
哪种方法允许将 ARGB 转换为字符串作为 'int, int, int' ?例子。 $Main 背景颜色设置为字符串 '0, 100, 200' 。返回 $Main.BackColor 给出 ARG
在as3中,是否有实用程序或函数可以将RGB颜色(例如0xFF0000)和alpha值(例如0.5)转换为A 32位ARGB值? 从 ARGB 到 RGB + alpha? 一些解释:位图数据可以在其
这段代码非常适合我想要做的事情(设置缓冲图像上像素的颜色/alpha),但我不知道它为什么起作用。语法是什么意思?我无法找到有关它的文档。 int rgb = (alpha << 24) | red
假设我有: int x = 140; 我想得到的结果: int y = new Color(x, x, x).getRGB() 来自 Java API 文档: getRGB() Gets the RG
我正在尝试将 ARGB 十六进制 String 解析为 int 但它不起作用。 我的代码: int color = Integer.parseInt("ff686868", 16); 异常(excep
我需要制作透明度,有 2 个像素: pixel1: {A, R, G, B} - foreground pixel pixel2: {A, R, G, B} - background pixel A,
谁能告诉我如何从 ARGB 计算出相应的窗口颜色?我知道有一个 ColorTranslator.ToWin32() 可以进行计算,但它是如何完成的? 另外,OLE 颜色和 Windows (win32
嗯,我正在努力研究我的车牌检测算法,需要一些简单的帮助。 基本上我正在尝试执行以下操作,代码是不言自明的,我只是找不到我正在尝试实现的示例。 提前致谢 if (img.GetPixel(bottomR
我正在开发一个简单的控制台应用程序,您可以在其中输入一个 ARGB 值的十六进制代码,该应用程序会告诉您该值的红色、绿色、蓝色和 Alpha 内容(共 255 个)。 例如: Enter a 32-b
我正在尝试在图像上设置水印(字符串)和具有一定不透明度(css 属性)的 pdf(带有 itext) 所以,不透明度是一个浮点类型,一切都适用于 pdf,因为它有方法 PdfGState gstate
我正在尝试创建一种方法,将两种 ARGB 颜色(第二个在顶部)混合为 alpha 为 0xFF 的颜色,我可能是盲目的,但经过 30 分钟的谷歌搜索后,我似乎找不到一种方法来做到这一点。而且这个方法必
如何将 TYPE_INT_ARGB 的 BufferedImage 保存为 jpg? 程序为我生成了那个图像: 没关系,但是当我以这种方式保存时: ByteArrayOutputStream
我正在尝试创建使用随机颜色的小型应用程序。 Random rnd = new Random(); int color1 = Color.argb(255, rnd.nextInt(25
在我的小程序中,我使用了不同的 BufferedImage 并将它们用作屏幕部件。每个屏幕部分只会在内容需要更改时重新绘制。 这是抽象的 ScreenPart 类: public abstract c
我是一名优秀的程序员,十分优秀!