负载在微软标志形象图控制的资源Load Marker image in microsoft chart control from resources

- 此内容更新于:2015-01-06
主题:

平台:c# Visual Studio 2010 IDE:微软 我试图加载标记图像点图控制的资源路径,但它无法加载文件路径。什么建议吗? 错误:ImageLoader——不能从这个位置加载图像: System.Drawing。位图在Program.cs

原文:

Platform : C# IDE: Microsoft Visual Studio 2010

I am trying to load marker image at a point in chart control from Resources path, but its not able to load the file path. Any suggestions ?

foreach (var pt in chart1.Series["Series1"].Points)
{
    foreach (DataRow dr in ds.Tables[0].Rows)
    {
        if (dr["OverNo"].Equals(pt.XValue) && Convert.ToInt32(dr["Fow"]) > 0)
        {
            //   pt.XValue +=5;
            if (Convert.ToInt32(dr["Fow"]) > 0)
            {
                //pt.MarkerImage = s + SC.whiteBall; // this works fine 
                //pt.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;

                if (Convert.ToInt32(dr["Fow"]) == 1)
                {
                    //   Bitmap b = new Bitmap(Properties.Resources.WhiteBall1);
                    pt.MarkerImage = s + SC.whiteBall;
                    pt.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
                }
            }
        }
    }
}

Error : ImageLoader - Cannot load image from this location: System.Drawing.Bitmap in Program.cs

segarci的回复:你能告诉更多的代码和错误吗?

(原文:Can you show more code and the error?)

Harsh Kumar Singhi的回复:我增加了两个代码和错误@segarci

(原文:I have added both the code and error @segarci)

解决方案:
原文:
  1. Include the image file as content in your application, copy to output directory.
  2. Use the full path for MarkerImage like MainApplicationPathImagesyourImage.bmp. Check File.Exists.
  3. You can use the MarkerImage property on both data points and series. If you use a particular image for your data series all data points will inherit that. You can override it for specific data points.
  4. Use MarkerStyle.None when using custom images.
  5. If switching from custom images to regular markers and back use DeleteCustomProperty("MarkerImage") and DeleteCustomProperty("MarkerStyle") on your data points, then reset.