Kadmos.com

  Home | Products | Download | Purchase | Support | Language

Google
Search site:

Products
DXFReader ActiveX Control
IXF ActiveX Control
Postel ActiveX Control
Tech Support
OnLine Support
Phone Support
Sample Code
Registered Users
FAQ
References
Kadmos
Contact Kadmos
Environment
Customer List
Newsletter
Download
ActiveX Controls
Updates
Purchase
Price List
International Resellers
Our Guarantee
Shipment Options
Payment Options
Shopping Cart
    Kadmos - Using DXFReader ActiveX Control in Visual Studio .NET

Using DXFReader ActiveX Control in Visual Studio .NET

Microsoft designed Visual Studio .NET as a single integrated development environment – which Microsoft refers to as the Microsoft Development Environment – for Visual Basic, Visual C#, and Visual C++ programmers. The Microsoft Development Environment offers several features and tools accessible from all .NET languages. For example, the Toolbox in Visual Basic 6.0 is now available when you use any .NET language.

Visual Studio .NET offers a new platform for creating graphical user interfaces in any .NET language – Windows Forms. You interact with Windows Forms and design user interfaces much the same as you do in Visual Basic 6.0. Visual Basic 6.0 forms are ActiveX control containers, designed specifically to host ActiveX controls or COM-based components. Visual Studio .NET Windows Forms are designed to host standard Windows Forms controls. Visual Studio .NET offers many standard controls for creating user interfaces.

Because Windows Forms can host only Windows Forms controls, Visual Studio .NET automatically creates wrappers for ActiveX controls so you can continue to use them in Visual Studio .NET projects. When you place DXFReader ActiveX control on a Windows Form, Visual Studio .NET uses the COM type library to automatically create two DLLs for the entire OCX, which is a distributable package that contains one or several ActiveX controls. One DLL contains a common language runtime proxy for the OCX, and the second contains a Windows Form proxy for the OCX.

The common language runtime proxy DLL is known as the Runtime Callable Wrapper (RCW) and contains a .NET version of the COM type library. It defines all objects and interfaces found in the original COM type library and the classes that implement the interfaces. Visual Studio .NET names this DLL Interop.DXFREADERlib.dll.

The Interop prefix denotes that the RCW incorporates services from the Interop layer, which controls marshalling and interoperability between COM and the .NET Framework. The Windows Form proxy DLL provides a .NET control that calls the RCW; that is, this DLL defines the properties, methods, and events you can set, call, and handle programmatically. Visual Studio .NET names this DLL AxInterop.DXFREADERlib.dll.
The Ax prefix denotes that the wrapper classes inherit from the AxHost class to expose the ActiveX control as a Windows Forms control.

You can view references to both of these files in the References node of the Solution Explorer, and you can explore both files in the Object Browser.

Loading DXFReader ActiveX Control in Visual Studio .NET

Unlike the Toolbox in Visual Basic 6.0, which retains customizations for a single project, the Visual Studio .NET Toolbox retains customizations for the entire development environment. When you load DXFReader ActiveX Control in the Toolbox, as described below, they are available in any Windows Form designer, regardless of the language.

  1. Open a Windows Form in a Visual Basic .NET or Visual C# .NET project.
  2. Right click anywhere in the Toolbox and select Customize Toolbox. If the Toolbox is not visible, first select View»Toolbox.
  3. From the COM Components list, select the ActiveX controls that you want in the project. You will find DXFReader ActiveX Control with the names DXFREADERlib.DXFReader and DXFREADERlib.DXFPlot


  4. Click OK. Visual Studio .NET loads the selected controls on the currently selected tab of the Toolbox.

Browsing Properties

Place DXFReader ActiveX Control on the Windows Form and explore its properties (View»Properties Window). You might notice that several properties have been added or changed, including the default name of the control. Visual Studio .NET prefixes all ActiveX controls with Ax (in Visual Basic .NET) or ax (in Visual C# .NET). For example, when you drop the first instance DXFReader ActiveX Control on a Visual Basic 6.0 form, Visual Basic 6.0 names that control DXFReader1. When you drop the first instance of DXFReader in Visual Studio .NET, Visual Basic .NET names the control AxDXFReader1.

Browsing Generated Code

Open the code editor, and examine the code that Visual Studio .NET automatically generated. In both Visual Basic .NET and Visual C# .NET, the code generated contains a call to InitializeComponent() to initialize properties on the Windows Form and controls, a call to Dispose() for resource cleanup, and declaration of and reference to the instance of the DXFReader you placed on the form. Microsoft recommends that you do not directly modify the generated code. If you need to change properties for the Windows Form or controls that you placed on the Windows Form, use the Properties window.

Unlike Visual Basic 6.0, Visual Basic .NET does not support default properties, which are the most commonly used properties of the control.

Also be sure to specify all optional parameter when you use methods. For example, to use the WriteDXF method you must specify all parameteres in the following way:


AxDXFReader1.WriteDXF("MyDXFFile.dxf", False, 6, 14)

You can retrieve an item from a collection in Visual Basic 6.0 without explicitly stating the Item method, as demonstrated in the following example:

In Visual Studio .NET, you must explicitly use the Item method when you retrieve items from a collection, as shown in the following example:

	
'This code in VB.NET will find the area of a closed polyline

Dim Vertex As DXFREADERlib.DXFReaderVertex
Dim Entity As DXFREADERlib.DXFReaderEntity
Dim np As Integer
Dim k As Integer
Dim i As Integer
Dim Area As Single

With AxDXFReader1

 If .FileStatus = DXFREADERlib.FileStatusEnum.drLoaded Then 
 np = 0
 For Each Entity In .Entities
   If Entity.EntityType = "POLYLINE" _
       Or Entity.EntityType = "LWPOLYLINE" Then
      np = np + 1
      Area = 0
      For k = 1 To Entity.Vertexes.Count
        If k = Entity.Vertexes.Count Then
          i = 1
         Else
           i = k + 1
         End If
         Area = Area + _
            Entity.Vertexes.Item(k).X0 * Entity.Vertexes.Item(i).Y0 _
          - Entity.Vertexes.Item(i).X0 * Entity.Vertexes.Item(k).Y0
       Next k

       Area = Math.Abs(Area) / 2
       MsgBox(Entity.EntityType + " #" + Format$(np, "###,##0") + _
        " Area: " + Format$(Area, "###,###,##0.0"))
    End If
  Next Entity
 End If
End With

Event Handling

Microsoft implemented a new event model in Visual Studio .NET. In this event model, an object generates an event in response to some action or change in state, such as a mouse click or x number of points being acquired. The object that generates the event is called the event sender. Another object, called the event receiver, captures the event and responds by executing an event handler, which processes the event. However, the event sender needs a pointer to the event receiver. The .NET Framework refers to this pointer as a delegate. A delegate is a class that holds a reference to a method.

Consider a MouseMove event, which occurs when you move the mouse pointer on DXFReader ActiveX Control. Visual Basic .NET generates the following event handler skeleton for you. In this example, the Handles keyword indicates that the event handler (named AxDXFReader1_MouseMoveEvent) is called when the control names AxDXFReader1 generates a MouseMove event.

    Private Sub AxDXFReader1_MouseMoveEvent(ByVal eventSender As System.Object, _
       ByVal eventArgs As AxDXFREADERlib.__DXFReader_MouseMoveEvent)_
	 Handles AxDXFReader1.MouseMoveEvent
        
        AxDXFReader1.ShowRubberBox(X0, Y0, eventArgs.x, eventArgs.y)

    End Sub

To generate the same event handler in Visual C# .NET, select the DXFReader on the Windows Form, and view the Events in the Properties window. Locate the MouseMove event and enter a name for event handler. For example, you might name the event handler MouseMoveEvent. Visual C# .NET then generates the following event handler for the MouseMov event:

private void axDXFReader1_MouseMoveEvent(object sender,
           AxDXFREADERlib.__DXFReader_MouseMoveEvent e)
{
	
	axDXFReader1.ShowRubberBox(X0,Y0,e.x,e.y);
	
}

Visual C# .NET automatically adds the following event handler reference to the code:

this.axDXFReader1.MouseMoveEvent += new _ 
 AxDXFREADERlib.__DXFReader_MouseMoveEventHandler( _
 this.axDXFReader1_MouseMoveEvent);

Each DXFReader event returns two data items. The first item, named sender, is the object that raised the event. The second item, named e, contains all data returned from the event.

Distributing Visual Studio .NET Applications

Visual Studio .NET offers several built-in setup and deployment project templates and a Setup Wizard, so you can add setup and deployment directly to a Visual Studio .NET solution. The Setup Wizard includes all files necessary to distribute the application and is a good place to start if you are not sure which type of deployment project you need. For information about Visual Studio .NET solutions, refer to Solution Explorer. For information about setup and deployment projects, refer to Deploying Applications and Components. For information about the Setup Wizard, refer to Setup Wizard.

Copyright © 2009 Kadmos.com. All rights reserved. Privacy Policy