2. Save the project to any directory, for instance: c:\Users\{UserName}\Documents\CAD .NET 15\demo_sources\MyDemo.
3. Copy CADImport.dll file to Debug directory, for instance: c:\Users\{UserName}\Documents\CAD .NET 15\demo_sources\MyDemo\WindowsApplication1\WindowsApplication1\bin\Debug\CADImport.dll.
4. Add reference to CADImport.dll in MS Studio: View > Solution Explorer > References > Right mouse click > Add Reference > Browse >c:\Users\{UserName}\Documents\CAD .NET 15\demo_sources\MyDemo\WindowsApplication1\WindowsApplication1\bin\Debug\CADImport.dll or your path to the file CADImport.dll> OK.
Please check whether you see CADImport in the References section like on the picture below:

5. Open code (Solution Explorer > Form1.cs > View code) and add CADImport namespace:
| C# | Copy Code |
|---|---|
.. using System.Windows.Forms; using CADImport; .. | |
6. Create a new CADImage class instance and load a CAD file using the following code:
| C# | Copy Code |
|---|---|
public partial class Form1 : Form
{
CADImage cadImage;
public Form1()
{
InitializeComponent();
string path = @"c:\CADSoftTools.dxf";
cadImage = CADImage.CreateImageByExtension(path);
cadImage.LoadFromFile(path);
}
} | |
Please note that it is necessary to use exactly CADImage.CreateImageByExtension method to create the object of the right class.
7. In Form Properties (View > Properties window) please select Events > Paint. Double-click there and write the following code to draw the CAD image onto a form with 500 pixels width.
| C# | Copy Code |
|---|---|
private void Form1_Paint(object sender, PaintEventArgs e)
{
if (cadImage != null)
{
RectangleF R;
R = new RectangleF(0, 0, 500, 500);
R.Height = (float) (R.Width * cadImage.Extents.Height /
cadImage.Extents.Width);
// width of image is 500, height depends on height/width of the drawing
cadImage.Draw(e.Graphics, R);
}
} | |