vb function extension

Source: Internet
Author: User

When we design a VB form, we often put a number of controls, in order to make these controls look neat, we have to set a lot of left, top, Height, Width properties, you have been tired and want to turn to PowerBuilder or Delphi, etc. Let's extend the function of VB now.

VB4.0 provides a new feature: Add-ins, using this feature we can add our own program to the VB4 system menu Add-ins, as a function of VB expansion. The program we designed will have the following features: Select some controls on the form and select them by menu to make them the same size, spacing, edge alignment, and so on. With these features, we can design the interface to save a lot of time, greatly improve work efficiency. Limited to space, here is only one feature: Make the selected controls the same size from left to right. Understanding this program, other functions are easy to achieve. Start with a new project: Alignment.mark, do not need any forms, select Project Options in the Tools menu, set project name to \exam, and set start Mode to object application exit. Then select Classmodule in the menu ins ert to create a new class with the properties set as follows:

Name=hsizealign; Creatable=false; Public=true Enter the following program:

Public VBInstance As Object ’当前所运行的VB
Private TheseControls As Object
Private Control As Onject ’控件对象变量
Private AllHeight As Long
Private AllWidth As Long
Private MinLeft As Long ’标记最左边界值
Public Sub AfterClick()
MinLeft=99999 ’设一极大初值
Set ThereControls = VBInstance.ActiveProject.Ac - tiveForm.SelectedControlTemplates
For Each Control In TheseControls
If Control.Properties(Left)<MinLeft Then
AllHeight=Control.Properties(Height)
AllWidth=Control.Properties(Width)
MinLeft=Control.Properties(Left)
End If
Next
For Each Control In TheseControls
Control.Properties(Height)=AllHeight
Control.Properties(Width)=AllWidth
Next
End Sub

To define a new class, the property is set as follows:

Name=alignment; Creatable=true; Public=true
Dim Thisinstance as Object
Dim Hsizealignmenu as Object
Dim Hsizealignhandler as New hsizealign
Dim Hsizeconnectcookie as Long
Sub connecta N (vbinstance as Object)
' Add menu item, connect
Set thisinstance=vbinstance
Set Hsizealignmenu=thisinstance.addinmenu.
Menuitems.add (hsize Alignment)
Set hsizealignhandler.vbinstance=thisinstance
Hsizeconnectcookie=hsizealignmenu.connectevents
(Hsizealignhandler)
End Sub
Sub Disconnectaddin (Mode as Integer)
' Disconnect, delete menu items
Hsizealignmenu.disconnectevents Hsizeconnect-cookie
ThisInstance.AddinMenu.MenuItems.Remove Hsizealignmenu
End Sub
Add a module and enter the following program:
Declare Function writeprivateprofilestring Lib
KERNEL (ByVal appname$,byval keyname$,byval keydefault$,byval filename$)
Declare Function getprivateprofilestring Lib
KERNEL (ByVal appname$,byval keyname$,byval keydefault$,byval returnstring$,by
Val numbytes as Integer,byval filename$)
' Above description available API Text Viewer copy
Sub Main ()
Dim returnstring as String
Section$=add-ins16
returnstring=string$ (255,chr$ (0))
Errcode=getprivateprofilestring (section$,
Exam.alignment,notfound,returnstring,len (returnstring) +1,vb. INI)
If Left (returnstring,instr (RETURNSTRING,CHR (0))-1) =notfoundthen
errcode=writeprivateprofilestring% (SECTION$,EXAM.ALIGNMENT,0,VB. INI)
End If
End Sub

Exam.alignment, \exam "for project name, \alignment" is the name of the class that is connected to the Add-in menu. After compiling and running the above program, select Add-in Manager in VB menu Add-ins, will pop up a dialog box, choose Exam. Alignment Exit, the Add-ins menu is more than one hsize alignment; When you use it, select the desired arrangement of controls, and then select the menu item. The operating environment of this program is: vb4.0,windows3.1;486 dx2/66 8M.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.