- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个简单的属性网格,以允许用户修改图表的颜色。默认情况下,图表具有“Palette”属性,该属性的枚举类型为“ChartColorPalette”。如果作为我的属性网格基础的对象也具有相同类型的“Palette”属性,则将获得可能值的下拉列表。但是,我没有得到的是值名称左侧的小条纹图像。
现在,我可以编写一个UITypeEditor派生的类,并让“PaintValue”绘制一些我使用“Paint”或类似方法从屏幕上剔除的资源位图,但这似乎很乏味。
有谁知道“ChartColorPalette”枚举是否已有类型编辑器,可以用来获取小位图?
最佳答案
碰巧的是,编写UITypeEditor并不是那么棘手,也没有那么多代码。
首先,我创建了一个类型编辑器,如下所示:
private class ChartColorPaletteEditor : UITypeEditor
{
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
public override void PaintValue(PaintValueEventArgs e)
{
String paletteName = e.Value.ToString();
String baseName = this.GetType().Namespace + ".MyChart";
ResourceManager mgr = new ResourceManager(baseName, this.GetType().Assembly);
Bitmap bmp = mgr.GetObject(paletteName) as Bitmap;
if (bmp != null)
{
e.Graphics.DrawImage(bmp, e.Bounds);
bmp.Dispose();
}
}
}
[DefaultValue(typeof(ChartColorPalette), "BrightPastel")]
[Editor(typeof(ChartColorPaletteEditor), typeof(System.Drawing.Design.UITypeEditor))]
[Category("Appearance")]
[Description("The named palette to use when choosing the colour scheme for the chart series lines.")]
public ChartColorPalette Palette { get; set; }
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Windows.Forms.DataVisualization.Charting;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
Enum.GetValues(typeof(ChartColorPalette)).OfType<ChartColorPalette>().ToList().ForEach(GeneratePNG);
}
static void GeneratePNG(ChartColorPalette palette)
{
if (palette == ChartColorPalette.None) return;
Color[] colours = palette.GetColors();
if (colours.Length >= 12)
{
colours = new Color[] { colours[0], colours[2], colours[4], colours[6], colours[8], colours[10] };
}
else
{
colours = new Color[] { colours[0], colours[1], colours[2], colours[3], colours[4], colours[5] };
}
using (Bitmap bmp = new Bitmap(20, 14))
{
using (Graphics gr = Graphics.FromImage(bmp))
{
using (SolidBrush b1 = new SolidBrush(colours[0]),
b2 = new SolidBrush(colours[1]),
b3 = new SolidBrush(colours[2]),
b4 = new SolidBrush(colours[3]),
b5 = new SolidBrush(colours[4]),
b6 = new SolidBrush(colours[5]))
{
int height = bmp.Height - 2;
gr.DrawRectangle(Pens.Black, 0, 0, bmp.Width - 1, bmp.Height - 1);
gr.FillRectangle(b1, new Rectangle(1, 1, 3, height));
gr.FillRectangle(b2, new Rectangle(4, 1, 3, height));
gr.FillRectangle(b3, new Rectangle(7, 1, 3, height));
gr.FillRectangle(b4, new Rectangle(10, 1, 3, height));
gr.FillRectangle(b5, new Rectangle(13, 1, 3, height));
gr.FillRectangle(b6, new Rectangle(16, 1, 3, height));
}
}
String path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
path = Path.Combine(path, @"Visual Studio 2010\Projects\DataVisualization.Charting\Palette Bitmaps");
String filename = palette.ToString() + ".png";
bmp.Save(Path.Combine(path, filename), ImageFormat.Png);
}
}
}
public static class Extensions
{
public static Color[] GetColors(this ChartColorPalette value)
{
switch (value)
{
case ChartColorPalette.Berry:
return GetColors(0x8a2be2, 0xba55d3, 0x4169e1, 0xc71585, 0x0000ff, 0x8a2be2, 0xda70d6, 0x7b68ee, 0xc000c0, 0x0000cd, 0x800080);
case ChartColorPalette.Bright:
return GetColors(0x008000, 0x0000ff, 0x800080, 0x00ff00, 0xff00ff, 0x008080, 0xffff00, 0x808080, 0x00ffff, 0x000080, 0x800000, 0xff0000, 0x808000, 0xc0c0c0, 0xff6347, 0xffe4b5);
case ChartColorPalette.BrightPastel:
return GetColors(0x418cf0, 0xfcb441, 0xe0400a, 0x056492, 0xbfbfbf, 0x1a3b69, 0xffe382, 0x129cdd, 0xca6b4b, 0x005cdb, 0xf3d288, 0x506381, 0xf1b9a8, 0xe0830a, 0x7893be);
case ChartColorPalette.Chocolate:
return GetColors(0xa0522d, 0xd2691e, 0x8b0000, 0xcd853f, 0xa52a2a, 0xf4a460, 0x8b4513, 0xc04000, 0xb22222, 0xb65c3a);
case ChartColorPalette.EarthTones:
return GetColors(0xff8000, 0xb8860b, 0xc04000, 0x6b8e23, 0xcd853f, 0xc0c000, 0x228b22, 0xd2691e, 0x808000, 0x20b2aa, 0xf4a460, 0x00c000, 0x8fbc8b, 0xb22222, 0x8b4513, 0xc00000);
case ChartColorPalette.Excel:
return GetColors(0x9999ff, 0x993366, 0xffffcc, 0xccffff, 0x660066, 0xff8080, 0x0066cc, 0xccccff, 0x000080, 0xff00ff, 0xffff00, 0x00ffff, 0x800080, 0x800000, 0x008080, 0x0000ff);
case ChartColorPalette.Fire:
return GetColors(0xffd700, 0xff0000, 0xff1493, 0xdc143c, 0xff8c00, 0xff00ff, 0xffff00, 0xff4500, 0xc71585, 0xdde221);
case ChartColorPalette.Grayscale:
return GetColors(0xc8c8c8, 0xbdbdbd, 0xb2b2b2, 0xa7a7a7, 0x9c9c9c, 0x919191, 0x868686, 0x7b7b7b, 0x707070, 0x656565, 0x5a5a5a, 0x4f4f4f, 0x444444, 0x393939, 0x2e2e2e, 0x232323);
case ChartColorPalette.Light:
return GetColors(0xe6e6fa, 0xfff0f5, 0xffdab9, 0xfffacd, 0xffe4e1, 0xf0fff0, 0xf0f8ff, 0xf5f5f5, 0xfaebd7, 0xe0ffff);
case ChartColorPalette.Pastel:
return GetColors(0x87ceeb, 0x32cd32, 0xba55d3, 0xf08080, 0x4682b4, 0x9acd32, 0x40e0d0, 0xff69b4, 0xf0e68c, 0xd2b48c, 0x8fbc8b, 0x6495ed, 0xdda0dd, 0x5f9ea0, 0xffdab9, 0xffa07a);
case ChartColorPalette.SeaGreen:
return GetColors(0x2e8b57, 0x66cdaa, 0x4682b4, 0x008b8b, 0x5f9ea0, 0x3cb371, 0x48d1cc, 0xb0c4de, 0xffffff, 0x87ceeb);
case ChartColorPalette.SemiTransparent:
return GetColors(0xff6969, 0x69ff69, 0x6969ff, 0xffff69, 0x69ffff, 0xff69ff, 0xcdb075, 0xffafaf, 0xafffaf, 0xafafff, 0xffffaf, 0xafffff, 0xffafff, 0xe4d5b5, 0xa4b086, 0x819ec1);
case ChartColorPalette.None:
default:
return GetColors(0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000);
}
}
private static Color[] GetColors(params Int32[] values)
{
return values.Select(value => Color.FromArgb(255, Color.FromArgb(value))).ToArray(); // alpha channel of 255 for fully opaque
}
}
}
关于propertygrid - 是否存在类型“ChartColorPalette”的PropertyGrid UITypeEditor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3248180/
我是C#/WPF的初学者,正在尝试使用Xceed PropertyGrid。在他们的网站上,他们显示了一个示例:
对 PropertyGrid 控件进行了一些运行,现在偶然发现了一个奇怪的问题。我在一个类中有一个 Uint32 属性,它是一个位掩码。因此,我决定创建一个带有 32 个按钮的自定义下拉 UserCo
我有一个项目,我们必须以所见即所得的方式在用户控件上表示一些图形对象。还需要编辑每个对象的属性(颜色、位置等)。 alt text http://lh6.ggpht.com/_1TPOP7DzY1E/
我正在使用 PropertyGrid (在 CollectionEditor 中)编辑类的一些属性。这些属性实际上包含在实现 ICustomTypeDescriptor 的类中。 .其中之一使用继承自
我见过的所有 PropertyGrid 示例都允许用户编辑单个对象,PropertyGrid 通过反射扫描该对象。我希望用户能够编辑一个 ini 文件或一本普通的字典,每个键值对一行。这可能吗? 最佳
有没有办法使 ExtJS4 PropertyGrid (Ext.grid.property.Grid) 不可编辑? 没有“可编辑”或“只读”配置选项 AFAICS。 最佳答案 另一种解决方案是添加一个
在 PropertyGrid 表单元素中,当我将属性添加到我的类别时,一些属性以粗体显示。 现在,我知道它表明它们是该类别中的默认值。我的问题是如何使所有属性不加粗? 我知道一种可能的方法是更改
我有: class Foo1 { private string name1; [CategoryAttribute("Category1")] public string Na
我有一个 PropertyGrid,我向其中添加了一个 bool 值数组。数组本身被标记为只读,属性网格可以正确识别它。 但是:如果我在网格中展开数组,所有项目都可以由用户编辑。当然那不是我想要的。如
我一直在研究 PropertyGrids,将它们链接到类,并试图弄清楚如何(如果可能)我可以显示一个类,在 扁平结构(好像它们都在一个类中) 我有几个类,Foo 和 Bar,如下所示: [Serial
在 C# 中,当使用对象具有 Collection 的 PropertyGrid 时,什么决定 DisplayName 旁边的值是否显示该值“(集合)”? 这个值是否有特定的属性? 谢谢 最佳答案 您
我在使用 propertygrid 时遇到了一些问题。即: 当我在 visual studio 设计器中使用 propertygrid 时,行为与在运行时以及调试时不同。 需要注意的几点(这是在设计器
我正在尝试使用 VS2005 (.NET 2.0) 在 C# 中实现对属性网格的拖放支持。 propertygrid 可以处理 dragenter 等事件,但似乎没有办法在拖动事件期间将 gridit
我正在使用 PropertyGrid 来显示通过实现 ICustomTypeDescriptor 公开的自定义属性。 我的对象设置在树结构中,每个属性的值要么在每个对象中设置,要么从父对象继承。在 P
是否可以在属性网格提示中添加可点击的超链接? 我的类(class)有以下内容(作为 SelectedObject 分配给属性网格): [Browsable(true), ReadOnly(false)
是否有一种简单的方法可以查明用户当前是否正在编辑属性网格? 我的用例如下:我每秒更新一次网格数据。如果用户正在编辑一个值,则在调用我的更新时所有输入都会丢失。所以我想做的是仅在用户未编辑内容时更新。
我有 类 PGMain 作为 propertygrid 中的 SelectedObject: [DefaultPropertyAttribute("Basic")] [Seriali
我有一个包含两个属性网格的表单。第一个网格的 SelectedObject 属性设置为包含 item 对象。而第二个设置为item.Test; public MainForm() { Init
我有一个 PropertyGrid。当我输入格式错误的值(即 - 将字符串转换为整数项)时,我收到一条错误消息。如果我单击“确定”,则错误值会一直存在,直到我更改它为止。如果我点击“取消”,原始值又回
在 C# (.Net 2.0) 的一个项目中,我使用了一个 propertygrid。此属性网格显示通过 SOAP 从 PHP 后端检索的对象。某些对象包含字符串属性,其中空字符串的含义与 NULL
我是一名优秀的程序员,十分优秀!