第二部分
原文:
VB6 and ActiveX Controls
Most of the basic VB6 controls will be upgraded by the wizard without any issues, as will many advanced and third-party controls. Even complex ActiveX controls like the MSChart and third party controls are likely to convert with only minor changes in syntax. For instance, the MSChart control converts and mostly behaves like the original. The biggest difference is that the Axis is accessed as a property in VB6, but this is done by using an accessor in VB.NET. For example, in VB6 the XAxis maximum value is set by the statement:
MSChart1.Plot.Axis(VtChAxisIdY,0).ValueScale.Maximum = 370
In VB.NET, it is set by the statement:
MSChart1.Plot.get_Axis(VtChAxisIdY,0).ValueScale.Maximum = 370;
As far as I can tell, this is the only property of MSChart that is treated with this minor difference. The wizard will automatically create a wrapper for any ActiveX controls used in the project. You can also create a wrapper for any ActiveX control you want to use in a .NET program by simply right-clicking on the toolbox, selecting add/remove items, and then choosing the ActiveX control from the COM tab of the Dialog Box. This task can also be accomplished by running the TlbImp.exe utility that comes with the free .NET SDK. One small difference: an "upgraded" ActiveX control is referred to by its original name when referenced in the program, but an ActiveX control added to a new .NET project gets an "ax" prefix. For instance, when upgraded from a VB6 project, MSChart stays MSChart; when added to a .NET project, it becomes axMSChart.
While complex components and ActiveX controls are moved to .NET via the use of wrappers, basic VB6 controls are upgraded to (replaced by) VB.NET controls.
译文
VB6及其Active控件
在VB6中XAxis最大值通过如下的语句来设置:
MSChart1.Plot.Axis(VtChAxisIdY,0).ValueScale.Maximum = 370
同时,在VB.NET中,应该这样做:
MSChart1.Plot.get_Axis(VtChAxisIdY,0).ValueScale.Maximum = 370
正如我所说的,这就是MSChart上唯一一个关于我所说的微小差别的属性。我们的向导会为项目中使用过的AX控件自动创建一个包装类。同样你也可以自己创建一个包装类(为任何你想要在一个.NET程序中使用的AX控件),通过这样的方法:右击工具箱(ToolBox)->选择“添加/移除项目(Add/Remove items)”->从COM选项卡对话框中选择AX控件。这个任务你也可以通过使用.NET SDK附带的Tlbimp.exe实用工具来完成。同时又这么一个小区别:通过“升级”的来的AX控件使用原来的名字被引用,但是作为一个AX控件被添加进一个.NET新项目会被冠之以"ax"作为前缀。例如,当从VB6项目升级后,NSChart使用MSChart的名字,然而被添加进.NET项目的变成了axMSChart。
虽然复杂的组件和AX控件通过类包装移植到.NET,但是基本的VB6控件以替换的形式来升级。