![]() |
||
|
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.
Loading DXFReader ActiveX Control in Visual Studio .NETUnlike 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.
Browsing PropertiesPlace 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.
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:
'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.
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 ApplicationsVisual 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 |