It's not easy to find the old post on "creating ActiveX dll parts for an independent control interface in VB" 2000/02/01!

Source: Internet
Author: User

The Component Object Model (COM) proposed by Microsoft, including automation and ActiveX specifications. ActiveX
The component technology can combine the created object-based parts, which can be created using many different tools. Application Department
Software development methods include:CodeReuse, clear module functions, and many other benefits. The following describes how to create an independent interface to Control ActiveX DLL.
For further analysis:

The following two ActiveX dll parts implement "Responding to events within the component", that is, reference an object with an event in the class module
AndProgramDynamically add controls in the running stage (for technical details, see msdn).
Example 2: The splitter control is provided in Delphi, which easily implements the split view of the form interface. In VB
Function requires a lot of code.
You can refer to the "Tree View list view sharding" control set or "VB Application Wizard --> Resource Manager style" code in VB 6,
Now it is processed and transplanted as ActiveX dll parts:
Create an ActiveX DLL (named easyviews) project and name it splitview in the class module)
Add the following code:

Option explicit
Dim mbmoving as Boolean

Const ierror = 120
Const ierrorxy= 150
Const splitterhw = 80

Dim leftctl as control
Dim rightctl as control
Dim topctl as control
Dim bottomctl as control

Dim withevents imgsplitterh as image
Dim withevents imgsplitterv as image

Dim pictureh as picturebox
Dim picturev as picturebox

Dim withevents formx as form

Dim iminwidth as integer
Dim iminheight as integer
Dim ileftmargin as integer
Dim irightmargin as integer
Dim itopmargin as integer
Dim ibottommargin as integer

Public property get leftmargin () as integer
Leftmargin = ileftmargin
End Property

Public property let leftmargin (byval vnewvalue as integer)
Ileftmargin = vnewvalue
End Property

Public property get rightmargin () as integer
Rightmargin = irightmargin
End Property

Public property let rightmargin (byval vnewvalue as integer)
Irightmargin = vnewvalue
End Property

Public property get topmargin () as integer
Topmargin = itopmargin
End Property

Public property let topmargin (byval vnewvalue as integer)
Itopmargin = vnewvalue
End Property

Public property get bottommargin () as integer
Bottommargin = ibottommargin
End Property
Public property let bottommargin (byval vnewvalue as integer)
Ibottommargin = vnewvalue
End Property

Public property get minwidth () as integer
Minwidth = iminwidth
End Property

Public property let minwidth (byval vnewvalue as integer)
Iminwidth = vnewvalue
End Property

Public property get minheight () as integer
Minheight = iminheight
End Property

Public property let minheight (byval vnewvalue as integer)
Iminheight = vnewvalue
End Property

Private sub formx_load ()
Dim temp as string

Temp = "dynamicimageh"
On Error goto errorhandler
Formx. Controls. Add "VB. Image", temp, formx
On Error goto 0
With formx. Controls. Item (temp)
. Visible = true
End
Set imgsplitterh = formx. Controls. Item (temp)
Imgsplitterh. mousepointer = 7' ccsizeew

Temp = "dynamicimagev"
On Error goto errorhandler
Formx. Controls. Add "VB. Image", temp, formx
On Error goto 0
With formx. Controls. Item (temp)
. Visible = true
End
Set imgsplitterv = formx. Controls. Item (temp)
Imgsplitterv. mousepointer = 9 'cc2sizens

Temp = "dynamicpictureh"
On Error goto errorhandler
Formx. Controls. Add "VB. picturebox", temp, formx
On Error goto 0
Set pictureh = formx. Controls. Item (temp)
Pictureh. borderstyle = 0
Pictureh. backcolor = vbblack

Temp = "dynamicpicturev"
On Error goto errorhandler
Formx. Controls. Add "VB. picturebox", temp, formx
On Error goto 0

Set picturev = formx. Controls. Item (temp)

Picturev. borderstyle = 0
Picturev. backcolor = vbblack
Leftctl. Move leftmargin, topmargin
Imgsplitterv. Move leftctl. Left + leftctl. Width, leftctl. Top, splitterhw, leftctl. Height
Rightctl. Move imgsplitterv. Left + splitterhw, leftctl. Top
Rightctl. Height = leftctl. Height
Imgsplitterh. Move leftctl. Left, leftctl. Top + leftctl. Height, formx. Width-leftmargin-rightmargin, splitterhw
Bottomctl. Move leftctl. Left, leftctl. Top + leftctl. height + splitterhw 'leftctl. Height

Exit sub
Errorhandler:
Temp = temp & "X"
Resume
End sub

Public sub create (leftctlx as object, rightctlx as object, bottomctlx as object)
Set leftctl = leftctlx
Set rightctl = rightctlx
'Set topctl = topctlx
Set bottomctl = bottomctlx
Set formx = leftctlx. Container
Formx_load
End sub

Private sub formx_resize ()
If formx. windowstate <> vbminimized then
If formx. width <leftmargin + rightmargin + splitterhw + minwidth + leftctl. Width + ierrorxy then
Formx. width = leftmargin + rightmargin + splitterhw + minwidth + leftctl. Width + ierrorxy
End if
If formx. height <topmargin + bottommargin + splitterhw + minheight + leftctl. height + ierrorxy + 6 then
Formx. Height = topmargin + bottommargin + splitterhw + minheight + leftctl. height + ierrorxy + 6
End if
Rightctl. width = formx. Width-leftctl. Width-splitterhw-leftmargin-rightmargin-ierrorxy
Imgsplitterh. width = formx. Width-leftmargin-rightmargin-ierrorxy
Bottomctl. width = imgsplitterh. Width
Bottomctl. Height = formx. Height-imgsplitterh. Top-bottommargin-splitterhw-405
End if
End sub

private sub imgsplitterh_mousedown (button as integer, shift as integer, X as single, y as single)
with imgsplitterh
pictureh. move. left-10 ,. top ,. width + 30 ,. height/2
end with
pictureh. visible = true
mbmoving = true
end sub

private sub imgsplitterh_mousemove (button as integer, shift as integer, X as single, y as Single)
If Button = vbleftbutton then
If mbmoving then
if y + imgsplitterh. top pictureh. top = leftctl. top + minheight
elseif y + imgsplitterh. top> formx. height-bottommargin-splitterhw-minheight-ierrorxy then
pictureh. top = formx. height-bottommargin-splitterhw-minheight-ierrorxy
else
pictureh. top = Y + imgsplitterh. top
end if
end sub

Private sub imgsplitterh_mouseup (button as integer, shift as integer, X as single, y as Single)
Leftctl. Height = pictureh. Top-leftctl. Top
Imgsplitterv. Height = leftctl. Height
Rightctl. Height = leftctl. Height
Imgsplitterh. Top = pictureh. Top
Bottomctl. Height = formx. Height-imgsplitterh. Top-bottommargin-splitterhw-400-5
Bottomctl. Top = pictureh. Top + splitterhw
Pictureh. Visible = false
Mbmoving = false
End sub

Private sub imgsplitterv_mousedown (button as integer, shift as integer, X as single, y as Single)
Picturev. Visible = true
With imgsplitterv
Picturev. Move. Left,. Top-10,. width/2,. Height
End
Mbmoving = true
End sub

private sub imgsplitterv_mousemove (button as integer, shift as integer, X as single, y as Single)
If Button = vbleftbutton then
If mbmoving then
If x + imgsplitterv. left picturev. left = leftctl. left + minwidth
elseif x + imgsplitterv. left> formx. width-splitterhw-rightmargin-minwidth-ierrorxy then
picturev. left = formx. width-splitterhw-rightmargin-minwidth-ierrorxy
else
picturev. left = x + imgsplitterv. left
end if
picturev. height = leftctl. height
end if
end sub

Private sub imgsplitterv_mouseup (button as integer, shift as integer, X as single, y as Single)
Imgsplitterv. Left = picturev. Left
Leftctl. width = picturev. Left-leftctl. Left
Rightctl. width = formx. Width-leftctl. Width-splitterhw-leftmargin-rightmargin-ierrorxy '- ierror-200
Rightctl. Left = picturev. Left + splitterhw
Picturev. Visible = false
Mbmoving = false
End sub

This part has been created.
Next, create a standard project, draw any three controls on the form, such as Treeview, listview, and DataGrid, and write
Run the following code to test the class splitview of the easyviews component:

Option explicit
Dim X as new easyviews. splitview
Private sub form_load ()
'...
X. topmargin = 500 'toolbar1.height + 100
X. leftmargin = 1000
X. rightmargin = 1000
X. bottommargin = 500 'statusbar1. Height
X. minheight = 1000
X. minwidth = 1200
X. Create treeview1, listview1, datagrid1
'...
End sub

Example 1: people who have used Delphi and Pb should know that their form and window can implement rolling windows without programming. In
To implement a rolling window in VB, you need to write some code. Refer to msdn:
Scroll bar control solution: Create a scrollable graphical view, and now process it as ActiveX DLL
Parts:
Create an ActiveX DLL (named easyviews) project and add the following to the class module (named scrollview ):
Code:

Option explicit
Dim picture1 as picturebox
Dim picture2 as picturebox
Dim picture3 as picturebox

Dim withevents hscroll1 as hscrollbar
Dim withevents vscroll1 as vscrollbar
Dim withevents formx as form

Dim iwidth as integer
Dim iheight as integer
Dim ileft as integer
Dim iTOP as integer

Dim ileftmargin as integer
Dim irightmargin as integer
Dim itopmargin as integer
Dim ibottommargin as integer

Dim balignform as Boolean

Const ierrorxy= 135
Const dxy = 60

Public sub create (picturebox as object, optional balignformx as Boolean = true)
Set picture2 = picturebox
Set formx = picturebox. Container
Balignform = balignformx
Formx_load
End sub

Private sub formx_load ()
Dim temp as string

Temp = "dynamicpicture1"
On Error goto errorhandler
Formx. Controls. Add "VB. picturebox", temp, formx
On Error goto 0
With formx. Controls. Item (temp)
. Visible = true
End
Set picture1 = formx. Controls. Item (temp)

Temp = "dynamicpicture3"
On Error goto errorhandler
Formx. Controls. Add "VB. picturebox", temp, formx
On Error goto 0
With formx. Controls. Item (temp)
. Visible = true
End
Set picture3 = formx. Controls. Item (temp)

Temp = "dynamichscroll1"
On Error goto errorhandler
Formx. Controls. Add "VB. hscrollbar", temp ', formx
On Error goto 0
With formx. Controls. Item (temp)
. Visible = true
End
Set hscroll1 = formx. Controls. Item (temp)

Temp = "dynamichscroll1"
On Error goto errorhandler
Formx. Controls. Add "VB. vscrollbar", temp ', formx
With formx. Controls. Item (temp)
. Visible = true
End
Set vscroll1 = formx. Controls. Item (temp)

Hscroll1.tabstop = false
Vscroll1.tabstop = false
Set picture1.container = picture3
Set hscroll1.container = picture3
Set vscroll1.container = picture3
Set picture2.container = picture1
'Picture3. borderstyle = 0
Picture1.borderstyle = 0
Picture2.borderstyle = 0
If not balignform then
Picture3.move left, top, width, height
Hscroll1.move 0, picture3.height-hscroll1.height-dxy, picture3.width-vscroll1.width-dxy
Vscroll1.move picture3.width-vscroll1.width-dxy, 0, vscroll1.width, picture3.height-hscroll1.height-dxy
Picture1.move 0, 0, picture3.width-vscroll1.width-dxy, picture3.height-hscroll1.height-dxy
Picture2.move 0, 0
Hscroll1.largechange = hscroll1.max/5
Vscroll1.largechange = vscroll1.max/5
If picture1.height> = picture2.height then
Hscroll1.width = picture3.width-dxy
Picture1.width = picture3.width-dxy
End if
If picture1.width> = picture2.width then
Vscroll1.height = picture3.height-dxy
Picture1.height = picture3.height-dxy
End if
Hscroll1.max = picture2.width-picture1.width '+ 10' + dxy
Vscroll1.max = picture2.height-picture1.height '+ 10' + dxy
Hscroll1.smallchange = 100
Vscroll1.smallchanges = 100
Hscroll1.visible = (picture1.width <picture2.width)
Vscroll1.visible = (picture1.height <picture2.height)
End if
Exit sub
Errorhandler:
Temp = temp & "X"
Resume
End sub

Private sub formx_resize ()
On Error resume next
If balignform then
Picture3.move leftmargin, topmargin, formx. Width-leftmargin-rightmargin-ierrorxy, formx. Height-topmargin-bottommargin-ierrorxy
Hscroll1.move 0, picture3.height-hscroll1.height-dxy, picture3.width-vscroll1.width-dxy
Vscroll1.move picture3.width-vscroll1.width-dxy, 0, vscroll1.width, picture3.height-hscroll1.height-dxy
Picture1.move 0, 0, picture3.width-vscroll1.width-dxy, picture3.height-hscroll1.height-dxy
Picture2.move 0, 0
Hscroll1.largechange = hscroll1.max/5
Vscroll1.largechange = vscroll1.max/5
If picture1.height> = picture2.height then
Hscroll1.width = picture3.width-dxy
Picture1.width = picture3.width-dxy
End if
If picture1.width> = picture2.width then
Vscroll1.height = picture3.height-dxy
Picture1.height = picture3.height-dxy
End if
Hscroll1.max = picture2.width-picture1.width' + dxy
Vscroll1.max = picture2.height-picture1.height '+ dxy
Hscroll1.smallchange = 100
Vscroll1.smallchanges = 100
Hscroll1.visible = (picture1.width <picture2.width)
Vscroll1.visible = (picture1.height <picture2.height)
End if
End sub

Private sub hscroll1_change ()
Picture2.left =-hscroll1.value
End sub

Private sub vscroll1_change ()
Picture2.top =-vscroll1.value
End sub

Public property get width () as integer
Width = iwidth
End Property

Public property let width (byval vnewvalue as integer)
Iwidth = vnewvalue
End Property

Public property get height () as integer
Height = iheight
End Property

Public property let height (byval vnewvalue as integer)
Iheight = vnewvalue
End Property

Public property get left () as integer
Left = ileft
End Property

Public property let left (byval vnewvalue as integer)
Ileft = vnewvalue
End Property

Public property get top () as integer
Top = iTOP
End Property

Public property let top (byval vnewvalue as integer)
ITOP = vnewvalue
End Property

Public property get leftmargin () as integer
Leftmargin = ileftmargin
End Property

Public property let leftmargin (byval vnewvalue as integer)
Ileftmargin = vnewvalue
End Property

Public property get rightmargin () as integer
Rightmargin = irightmargin
End Property

Public property let rightmargin (byval vnewvalue as integer)
Irightmargin = vnewvalue
End Property

Public property get topmargin () as integer
Topmargin = itopmargin
End Property

Public property let topmargin (byval vnewvalue as integer)
Itopmargin = vnewvalue
End Property

Public property get bottommargin () as integer
Bottommargin = ibottommargin
End Property

Public property let bottommargin (byval vnewvalue as integer)
Ibottommargin = vnewvalue
End Property

This part has been created.
Next, create a standard project, draw a picturebox (picture1) control on the form, and then draw a certain number of controls.
In the picturebox control, write the following code to test the scrollview class of the easyviews component:

Option explicit
Dim X as new easyviews. scrollview
Dim y as new easyviews. scrollview
Private sub form_load ()
'...
X. Left = 1000
X. Top = 200
X. Height = 3000
X. width = 4000
X. topmargin = 3000
X. leftmargin = 500
X. rightmargin = 500
X. bottommargin = 600
X. Create picture2', false

Y. Left = 2000
Y. Top = 300
Y. Height = 2500
Y. width = 4000
'Y. topmargin = 1000
Y. leftmargin = 1000
Y. rightmargin = 1000
Y. bottommargin = 4000
Y. Create picture1, false

'...
End sub

This solution makes the main program code of the calling part concise and clear, and separates the "Code Part" that implements interface control from the code that implements other functions,
Clearly defined and clear.

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.