加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

【VB/.NET】Converting VB6 to VB.NET 【Part I】【之三】

发布时间:2020-12-17 08:16:55 所属栏目:百科 来源:网络整理
导读:第三部分 原文 Bad News and Good News While most VB6 controls convert well,there are exceptions. For example,line and shape controls and commands do not convert very well,and the DB,OLE,and UpDown counter controls do not convert at all. I'l

第三部分

原文

Bad News and Good News

While most VB6 controls convert well,there are exceptions. For example,line and shape controls and commands do not convert very well,and the DB,OLE,and UpDown counter controls do not convert at all. I'll discuss these in more detail in my next article.

Form.Print doesn't exist in VB.NET,and there is no real workaround that I know of. This has got to be the one thing I miss most from VB6. This was also true when I used C++ 6.0 instead of VB6 to write user interfaces. The general solution is to get a bitmap of the form and print that. If you do the scaling right,this can work well,but in many cases,the result is a low quality print. This can be especially true of text. Items that the programmer draws,such as user draw items and general graphics,can be drawn on the printer canvas instead of the screen canvas. Scaled right,this tends to work well,but for controls and other items that draw themselves,creating and printing a bitmap is the only option.

Another feature missing from VB.NET is control arrays. However,there is a fix for this in the Microsoft.VisualBasic.Compatablity.VB6 namespace. This little gem of a namespace has a number of classes that emulate missing VB6 features. Among other things,it contains a control array class for each of the major VB6 controls. The upgrade wizard uses these classes to seamlessly upgrade control arrays. This works really well.

Some of the other things in this namespace are classes for converting VB6 fonts to VB.NET Font objects,image format conversions,and loading resources. Also included are replacements for the VB6 Format,Equ,Imp,ValidateControls,WhatsThisMode,and SendsKeys functions. .NET uses different coordinates from VB6 for windows and graphics. This namespace includes functions to convert between the two. It also contains replacements for File and Dir listboxes,the EXEName and Hinstance functions in the VB6 App object,and some functions missing from the VB.NET Button control. The namespace also has a CopyArray function that allows assigning an array to a variant.

译文:

坏消息和好消息

(看到这个略带喜感的标题,真是乐趣无穷啊,这个外国人到底是重点要说坏消息呢,还是命名上习惯性的把重要的好消息放在后面呢?不得而知...)

虽然大多数VB6控件能够良好的转换,但是仍然有一些Exception存在。例如,Line、Shape、Command控件并不能转换得很好,甚至像DB、OLE、UpDown counter(加减计数器,难道是Timer?)这些控件一点都不会被转换。我将会在下一篇文章详述这些问题。

Form.Print在VB.NET里面已经不存在了,并且据我所知没有什么可替代的东西来解决这个问题了(这意味着必须放弃与From.Print相关的东西,当然了,并不排除自己写个Print来实现Form.Print,但我想这已经没有必要了吧,既然去掉的东西一定是不好的或者被遗弃的或者用的少的,总之它的消失一定有一个充分的理由的)。这个是我在VB6中最怀念的东西。这导致了我在编写UI的时候是使用的C++ 6.0而不是VB6。这个问题通用的一个解决办法就是获取Form的BMP信息修改后在重新Print之。如果你正确地编写了缩放的代码,这将变得很有效,但是在许多情况下,Print的效果会很差。我说的一定是实话,没有骗你。程序员所要绘制的例如用户绘制的文本或者一般的图形,可以被画在打印机画布上,而不是屏幕画布。当然了,如果正确的缩放了,代码就会如你所愿执行,但是对于控件和其它自我绘制的项目来说,唯一的选择就是创建并输出BMP来实现相应的功能。

另一个VB.NET中消失的特性就是控件数组。但是这在Microsoft.VisualBasic.Compatablity.VB6 命名控件中对此有一定的弥补。这个精致的命名空间有许多的类来模拟所缺失的VB6特性。在这之中,它包含了一个为每一个主要的VB6控件准备了一个控件数组类。升级向导使用这些类无漏洞地升级控件数组,而且做的还不错。

除此之外,在命名空间还有一些用来转换VB6字体为VB.NET字体对象、图像格式转换、以及资源加载的类。当然也包括用来替代VB6中Format、Equ、Imp、ValidateControls、 WhatsThisMode 以及 SendsKeys函数的类。.NET中对于Windows和Graphics使用不同于VB6的坐标系。(因而,)我们这个命名空间包括了在两者之间进行转换的函数。它同样为FILE和DIR列表框提供了替代品,以及VB6 APP对象中的与EXEName和Hinstance相关的函数,以及VB.NET中消失的关于Button控件的一些函数(原Command)。它还有一个CopyArray函数来给变体类型指定一个数组。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读