Use the library with Windows Forms

Let me remind you that the graphic library was specially designed for WPF applications, but we can do a little trick to use it with Windows Forms applications or even in ASP webpages.

For using it in a Windows Forms project, for starters we need to do the same basic steps as in the previous post How to integrate the library.

After that, we need to include 3 more references (Project->Add Reference->.NET component) to our project so that we can “sustain” the WPF core inner mechanisms:

  1. PresentationCore
  2. PresentationFramework
  3. WindowsBase

Don’t forget about adding the main library reference: SoftwareGFX_Library.

Imagine we have a simple form with a PictureBox control. For displaying a nice graph inside that Picturebox we can use solely this code, that is perfectly compatible with SoftwareGFX Library:

private void afiseazaGrafic()
{
SoftwareGFX_Library.Lines_Chart graph = new SoftwareGFX_Library.Lines_Chart();
string tempFile="";

graph.graphType = 0;
graph.showItemsMarker = true;
graph.marker_size = 10;
graph.marker_type = 0;
graph.showLegend = false;

System.Windows.Controls.Canvas cv = new System.Windows.Controls.Canvas();
cv.Height = 350;
cv.Width = 700;

graph.drawLines(ref cv);

// save the picture
tempFile = System.IO.Path.GetTempFileName();

SoftwareGFX_Library.GlobalTools.ExportToPng(tempFile, ref cv);

pctGrafic.Image = System.Drawing.Bitmap.FromFile(tempFile);
}

The same principle applies when trying to integrate the library to an ASP.NET project.

Leave a Reply

You must be logged in to post a comment.