对VB的IDE环境的扩展 作者:董科科 VB、Delphi 作 为Windows 下 的 可 视 化 编 程 环 境, 已 被 大 家 广 为 采 用。 笔 者 在 编 程 中, 通 过 对 二 者 的IDE 开 发 环 境 的 比 较, 利 用VB 的Add In 接 口, 完 全 模 拟 了Delphi 对 一 组 控 件 的 位 置、 大 小 的 快 速 操 作 和 模 板 功 能, 对VB 的 开 发 环 境 作 了 一 个 有 益 的 扩 展, 大 大 的 提 高 了VB 的 速 度 和 方 便 性。 一、 控 件 1、 控 件 对 齐(Alignment) 在VB 的 编 程 中,From 上 的 单 个 控 件 的 位 置、 大 小 虽 可 方 便 的 调 整, 但 对 一 组 控 件 的 位 置 关 系、 尺 寸 关 系 却 难 以 自 如 的 操 作, 而Delphi 中 有Align、Size 提 供 了 此 功 能, 对 用 户 来 说 非 常 方 便, 笔 者 再 编 程 过 程 中 就 常 常 遇 到 这 样 的 问 题, 笔 者 通 过 编 程 成 功 的 模 拟 了Delphi 这 一 功 能。 a、 完 成 功 能 b、编 程 思 想 初 始 化 系 统 和 变 量 Set TheseControls= VBInstance.ActiveProject.ActiveForm.SelectedControlTemplates 选择对齐方式 For Each Control In TheseControls iCount=iCount+1 Set MinHorControl=MinHou(Control) Set MaxHorControl=MaxHor(Control) Set MinVerControl=MinVer(Control) Set MaxVerControl=MaxVer(Control) Set HorControls(iCount 1)=SortHorControl(Control) Set VerControls(iCount 1)=SortVerControl(Control) Next Control 计算控件位移 For I=0 To iCount 1 HorControl(I).Properties(“Left”)= 新 值 HorControl(I).Properties(“Width”)= 新值 VerControl(I).Properties(“Top”)= 新值 VerControl(I).Properties(“Height”)= 新值 Next I Exit Sub 2、控件尺寸(Size) a、完成功能 b、编程思想 初始化系统和变量 Set TheseControls= VBInstance.ActiveProject.ActiveForm.SelectedControlTemplates 选择尺寸变换方式 For Each Control In TheseControls iCount=iCount+1 MinWidth=MinWidth(Control) MaxWidth=MaxWidth(Control) MinHeight=MinHeight(Control) MaxHeight=MaxHeight(Control) Set Controls(iCoun 1)=Control Next Control For I=0 To iCount 1 Countrol(I).Properties(“Width”)=MinWidth OR MaxWidth Countrol(I).Properties(“Height”)=MinHeight OR MaxHeight Next I Exit Sub 二、 模 板 各 种 字 处 理 软 件 现 在 均 提 供 了 模 板 功 能,Delphi 也 提 供 了Gallery 功 能 提 供 了 一 些 模 板 来 降 低 用 户 编 程 的 重 复 性, 笔 者 也 对VB 提 供 了 这 个 功 能。 初 始 化 系 统 和 变 量 Set frmNewForm=IDEApp.ActiveProject.AddFormTemplate() On Error Resume Next For I=0 To frmNewForm.Properties.Count 1 PropName=frmNewForm.Properties(I).Name If(InStr(“Name Left Top”,PropName) 0)Then frmNewForm.Properties(I).Value=fnGetProperty(tuForm.ropName) End If Next I For Each Control In tuForm.Controls ControlTypeName=fnGetControlTypeName(Control) With frmNewForm.ControlTemplates.Add(ControlTypeName) For I=0 To.Properties.Count 1 PropName=.Properties(I).Name .Properties(I).Value=fnGetProperty(Control,PropName) Next I End With Next Control fnHandle=FreeFile Open App.Path &“ \DesiTemp.MOD”For Output As fnHandle tuForm.prWriteFormCode fnHandle Close fnHandle frmNewForm.InsertFile App.Path &“ \DesiTemp.MOD” Kill App.Path &“ \DesiTemp.MOD” On Error Go To 0 Exit Sub