"ActiveX DLL Parts for Creating Independent Control Interfaces in VB" 20000201 old posts are really not easy!

xiaoxiao2021-03-06  98

The component object model (COM) proposed by Microsoft, including the Automation and ActiveX specifications. The ActiveX component technology can be combined with an object-based component that can be created by many different tools. Applying "Part Software Development" method has a lot of benefits such as code reuse, module functionality. Below to create an independent interface to control the ActiveX DLL component, further analysis:

The following two ActiveX DLL components implemented "In Partial Internal Response Events", ie references objects with events within class modules, and dynamically add controls in the program run phase (see "MSDN"). Example 2: The splitter control is provided in Delphi, and it is easy to implement the split view of the form interface, and this feature to be implemented in VB will write a large number of code. Referring to the "Tree View List-Removal Branch" control set or "VB Application Wizard -> Explorer Style" code of VB 6, it is now granted to ActiveX DLL components: Create an ActiveX DLL (named: EasyViews) Engineering and add the following code (named: splitView):

Option explicitdim mbmoving as boolean

Const Ierror = 120const Irrorxy = 150const SplitterHW = 80

DIM LEFTCTL AS ControlDim Rightctl As ControlDim Topctl As ControlDim Bottomctl As Control

Dim Withevents Imgsplitterh as imagedim withevents Imgsplitterv as image

DIM Pictureh As PictureBoxdim Picturev As PictureBox

DIM WITHEVENTS FORMX AS FORM

DIM IMINWIDTH AS INTEGERDIM IMINHETIGHT AS INTEGERDIM IRIGHTMARGIN AS INTEGERDIM ITOPMARGIN AS INTEGERDIM IBOTMMARGIN AS INTEGER

Public property get leftmargin () as integer leftmargin = ineftmarginend property

Public Property Let Leftmargin (Byval VNewValue As Integer) ileftmargin = VNewValueEnd Property

Public property get rightmargin () as integer Rightmargin = IRIGHTMARGINEEND Property

Public property let rightmargin (byval vnewvalue as integer) IRight Margin = VNewValueEnd Property

Public property get TopMargin () as integer TopMargin = ITOPMARGINEND Property

Public property let topmargin (Byval VNewValue As INTEGER) ITOPMargin = VNewValueEnd Property

Public Property Get BottomMargin () As Integer BottomMargin = iBottomMarginEnd PropertyPublic Property Let BottomMargin (ByVal vNewValue As Integer) iBottomMargin = vNewValueEnd PropertyPublic Property Get MinWidth () As IntegerMinWidth = iMinWidthEnd Property

Public property let minwidth (byval vnewvalue as integer) iMINWIDTH = VNewValueEnd Property

Public property get minheight () as integerminHeight = iMinHeightenD Property

Public property let Minheight (Byval VNewValue As Integer) iMinHeight = VNewValueEnd Property

Private Sub Formx_Load () Dim Temp As String

temp = "DynamicImageH" On Error GoTo ErrorHandlerFormX.Controls.Add "VB.Image", temp, FormXOn Error GoTo 0With FormX.Controls.Item (temp) .Visible = TrueEnd WithSet ImgSplitterH = FormX.Controls.Item (temp) ImgSplitterH. MousePointer = 7 'CCSIZEEW

temp = "DynamicImageV" On Error GoTo ErrorHandlerFormX.Controls.Add "VB.Image", temp, FormXOn Error GoTo 0With FormX.Controls.Item (temp) .Visible = TrueEnd WithSet ImgSplitterV = FormX.Controls.Item (temp) ImgSplitterV. MousePointer = 9 'cc2sizens

temp = "DynamicPictureH" On Error GoTo ErrorHandlerFormX.Controls.Add "VB.PictureBox", temp, FormXOn Error GoTo 0Set PictureH = FormX.Controls.Item (temp) PictureH.BorderStyle = 0PictureH.BackColor = vbBlack

Temp = "DynamicPicturev" on error goto errorhandlerformx.controls.add "vb.picturebox", Temp, Formxon Error Goto 0

Set picturev = formx.controls.Item (TEMP)

PictureV.BorderStyle = 0PictureV.BackColor = vbBlackLeftCtl.Move LeftMargin, TopMarginImgSplitterV.Move LeftCtl.Left LeftCtl.Width, LeftCtl.Top, SplitterHW, LeftCtl.HeightRightCtl.Move ImgSplitterV.Left SplitterHW, LeftCtl.TopRightCtl.Height = LeftCtl.HeightImgSplitterH .Move LeftCtl.Left, LeftCtl.Top LeftCtl.Height, FormX.Width - LeftMargin - RightMargin, SplitterHWBottomCtl.Move LeftCtl.Left, LeftCtl.Top LeftCtl.Height SplitterHW 'LeftCtl.HeightExit SubErrorHandler: temp = temp & "X "Resumend Sub

Public Sub Create (LeftCtlX As Object, RightCtlX As Object, BottomCtlX As Object) Set LeftCtl = LeftCtlXSet RightCtl = RightCtlX'Set TopCtl = TopCtlXSet BottomCtl = BottomCtlXSet FormX = LeftCtlX.ContainerFormX_LoadEnd Sub

Private Sub FormX_Resize () If FormX.WindowState <> vbMinimized Then If FormX.Width

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 FormX.Height - BottomMargin - SplitterHW - MinHeight - iErrorXY - iErrorXY - iErrorXY Then PictureH.Top = FormX.Height - BottomMargin - SplitterHW - MinHeight - iErrorXY - iErrorXY - iErrorXY Else PictureH.Top = Y ImgSplitterH .Top End If End If End IfEnd SubPrivate 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 mb MOVING = false

Private Sub ImgSplitterV_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single) PictureV.Visible = TrueWith ImgSplitterV PictureV.Move .Left, .Top - 10, .Width / 2, .HeightEnd WithmbMoving = TrueEnd 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 FormX.Width - SplitterHW - RightMargin - MinWidth - iErrorXY Then PictureV.Left = FormX.Width - SplitterHW - RightMargin - MinWidth - iErrorXY Else PictureV.Left = X ImgSplitterV.Left End If End If PictureV. Height = LeftCtl.HeightEnd IfEnd SubPrivate Sub ImgSplitterV_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single) ImgSplitterV.Left = PictureV.LeftLeftCtl.Width = PictureV.Left - LeftCtl.LeftRightCtl.Width = FormX.Width - Leftctl.width - splitterhw - leftmargin - Right Margin - Irrorxy '- Irror - 200rightctl.left = Picturev.veft splitterHWPICTUREV.Visible = falsembmoving = false

To this part is created. Next, create a standard project and draw any three controls on the form, such as: TreeView, ListView, DataGrid, and write the following code to test the class splitview of the EasyViews part:

Option ExplicitDim x As New EasyViews.SplitViewPrivate Sub Form_Load () '... x.TopMargin = 500' Toolbar1.Height 100x.LeftMargin = 1000x.RightMargin = 1000x.BottomMargin = 500 'StatusBar1.Heightx.MinHeight = 1000x.MinWidth = 1200x.create TreeView1, ListView1, DataGrid1 '... End Sub

Example 1: People who have used Delphi and PB should know that their Form and Window do not need to program, you can implement scrolling windows. In VB, you want to implement the scroll window, you need to write some code, you can refer to the MSDN: "Scroll Bar Control Scene: Create Scrollabable Graphics Viewport", which is now machined into an ActiveX DLL component: Create ActiveX DLL (named : EasyViews) Engineering and add the following code in class module (named: scrollview):

Option ExplicitDim Picture1 As PictureBoxDim Picture2 As PictureBoxDim Picture3 As PictureBoxDim WithEvents HScroll1 As HScrollBarDim WithEvents VScroll1 As VScrollBarDim WithEvents FormX As Form

DIM IWIDTH AS INTEGERDIM IHEIGHT AS INTEGERDIM ILEFT AS INTEGERDIM ITOP AS INTEGER

DIM ILEFTMARGIN AS INTEGERDIM IRIGHTMARGIN AS INTEGERDIM IBOTTOMMARGIN As INTEGERDIM IBOTTOMMARGIN AS INTEGER

Dim Balignform as Boolean

Const Irrorxy = 135const DXY = 60

Public Sub Create (PictureBox As Object, Optional BalignFormx as Boolean = true) set picture2 = PictureBoxSet Formx = PictureBox.ContainerbalignForm = BalignFormxFormX_loadend Sub

Private Sub Formx_Load () Dim Temp As String

temp = "DynamicPicture1" On Error GoTo ErrorHandlerFormX.Controls.Add "VB.PictureBox", temp, FormXOn Error GoTo 0With FormX.Controls.Item (temp) .Visible = TrueEnd WithSet Picture1 = FormX.Controls.Item (temp)

temp = "DynamicPicture3" On Error GoTo ErrorHandlerFormX.Controls.Add "VB.PictureBox", temp, FormXOn Error GoTo 0With FormX.Controls.Item (temp) .Visible = TrueEnd WithSet Picture3 = FormX.Controls.Item (temp)

temp = "DynamicHScroll1" On Error GoTo ErrorHandlerFormX.Controls.Add "VB.HScrollBar", temp ', FormXOn Error GoTo 0With FormX.Controls.Item (temp) .Visible = TrueEnd WithSet HScroll1 = FormX.Controls.Item (temp)

temp = "DynamicHScroll1" On Error GoTo ErrorHandlerFormX.Controls.Add "VB.VScrollBar", temp ', FormXWith FormX.Controls.Item (temp) .Visible = TrueEnd WithSet VScroll1 = FormX.Controls.Item (temp)

HScroll1.TabStop = FalseVScroll1.TabStop = FalseSet Picture1.Container = Picture3Set HScroll1.Container = Picture3Set VScroll1.Container = Picture3Set Picture2.Container = Picture1'Picture3.BorderStyle = 0Picture1.BorderStyle = 0Picture2.BorderStyle = 0If 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.heigh t - dXY End If HScroll1.Max = Picture2.Width - Picture1.Width ' 10' dXY VScroll1.Max = Picture2.Height - Picture1.Height ' 10' dXY HScroll1.SmallChange = 100 VScroll1.SmallChange = 100 HScroll1 .Visible = (Picture1.width

Private Sub FormX_Resize () On Error Resume NextIf bAlignForm Then Picture3.Move LeftMargin, TopMargin, FormX.Width - LeftMargin - RightMargin - iErrorXY, FormX.Height - TopMargin - BottomMargin - iErrorXY - iErrorXY - 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.SmallChange = 100 HScroll1.Visible = (Picture1.Width

Private sub vscroll1_change () Picture2.top = -vscroll1.valueEnd SUB

Public property get width () as integer width = iWidThend property

Public property let width (byval vnewvalue as integer) iWidth = VNewValueEnd Property

Public property Get Height () AS Integer Height = Iheightens Property

Public Property Let Height (Byval VNewValue As Integer) Iheight = VNewValueEnd PropertyPublic Property Get Left () AS Integer LEFT = Ileftend Property

Public Property Let Left (Byval VNewValue As Integer) Ileft = VNewValueEnd Property

Public property get top top () AS integer top = itopend property

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

Public property get leftmargin () as integer leftmargin = ineftmarginend property

Public Property Let Leftmargin (Byval VNewValue As Integer) ileftmargin = VNewValueEnd Property

Public property get rightmargin () as integer Rightmargin = IRIGHTMARGINEEND Property

Public property let rightmargin (byval vnewvalue as integer) IRight Margin = VNewValueEnd Property

Public property get TopMargin () as integer TopMargin = ITOPMARGINEND Property

Public property let topmargin (Byval VNewValue As INTEGER) ITOPMargin = VNewValueEnd Property

Public property get bottommargin () as integer bottommargin = ibottommarginend property

Public property lettommargin (byval vnewvalue as integer) ibottommargin = VNewValueEnd property

To this part is created. Next, a standard project is created, and a PictureBox (Picture1) control is drawn on the form, plot a certain number of controls in the Picturebox control, and write the following code to test the class scrollview of the EasyViews part:

Option ExplicitDim x As New EasyViews.ScrollViewDim y As New EasyViews.ScrollViewPrivate Sub Form_Load () '... x.Left = 1000x.Top = 200x.Height = 3000x.Width = 4000x.TopMargin = 3000x.LeftMargin = 500x.RightMargin = 500x.bottommargin = 600x.create pictures, false

y.left = 2000y.top = 300y.height = 2500y.width = 4000'y.topmargin = 1000y.rightmargin = 1000y.Rightmargin = 4000y.create Picture1, False '... End Sub

This scheme makes the main program code of the calling component, so that the "code part" that implements interface control is separated from the code to achieve other functions, and the boundaries are clear.

转载请注明原文地址:https://www.9cbs.com/read-124112.html

New Post(0)