使用嵌入的资源而不是文件名设置ImageAnnoation图像

Dan*_*ely 2 c# mschart winforms

我正在使用DataVisualization库中的Chart控件,并希望在我的图表上使用图像注释.问题是该ImageAnnotation.Image属性是图像的路径,并且似乎没有Bitmap可用于从Resources对象加载图像的公开属性,就像我可以用于任何其他.net控件一样.

无论如何,我忽略了使用嵌入式资源加载它而不是从磁盘读取单独的文件?

Dan*_*ely 5

我找到了答案.您需要将图像添加到父图表的NamedImage集合中.

private string imageName = "myImage";

//in constructor
NamedImage namedImage = new NamedImage(imageName, Properties.Resources.myImage);
mChart.Images.Add(namedImage);

//where creating the annotation
ImageAnnotation imageAnnotation = new ImageAnnotation();
imageAnnotation.Image = imageName;
Run Code Online (Sandbox Code Playgroud)