home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1999 April / CD_Shareware_Magazine_31.iso / Free / Prg / splitpanel.exe / SplitPanel.ctl (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-12-07  |  6.8 KB  |  187 lines

  1. VERSION 5.00
  2. Begin VB.UserControl SplitPanel 
  3.    Alignable       =   -1  'True
  4.    BorderStyle     =   1  'Fixed Single
  5.    ClientHeight    =   1185
  6.    ClientLeft      =   0
  7.    ClientTop       =   0
  8.    ClientWidth     =   1170
  9.    ControlContainer=   -1  'True
  10.    ScaleHeight     =   1185
  11.    ScaleWidth      =   1170
  12.    Begin VB.PictureBox Splitter 
  13.       BorderStyle     =   0  'None
  14.       Height          =   3540
  15.       Left            =   855
  16.       ScaleHeight     =   3540
  17.       ScaleWidth      =   165
  18.       TabIndex        =   0
  19.       Top             =   30
  20.       Width           =   165
  21.    End
  22. Attribute VB_Name = "SplitPanel"
  23. Attribute VB_GlobalNameSpace = False
  24. Attribute VB_Creatable = True
  25. Attribute VB_PredeclaredId = False
  26. Attribute VB_Exposed = False
  27. Option Explicit
  28. '********************************
  29. ' SplitPanel V1.0  (C)1998 David Crowell
  30. ' You may use this source code within
  31. ' your own applications.  You may not
  32. ' distribute it on a website without my express
  33. ' permission.  You may not use it to compile
  34. ' an OCX that is for distribution.  You may compile
  35. ' to OCX for testing purposes. You may compile
  36. ' within an application, whether for commercial
  37. ' or non-commercial use.
  38. '********************************
  39. ' Properties:
  40. ' HorizontalSplit (Boolean, r/w) True: the splitter
  41. '               bar will be horizontal
  42. ' SplitPercent (Byte, r/w)   10-90 Percentage
  43. '               of the width of the control for
  44. '               first pane
  45. ' Control1 (Object, r/w) The control to act as
  46. '               pane1, the upper or left pane
  47. ' Control2 (Object, r/w) The control to act as
  48. '               pane2, the lower or right pane
  49. ' Be sure to set the Control1 and Control2
  50. ' properties in the form load event to controls
  51. ' contained within the SplitPanel control.
  52. ' The SplitPanel has a border during design time
  53. ' which disappears at run time.  Makes designing
  54. ' forms easier.
  55. '********************************
  56. Private Const SPLITWIDTH As Single = 80     ' width of splitterbar
  57. '********************************
  58. ' Variables for properties
  59. '********************************
  60. Private mHorizontalSplit As Boolean
  61. Private mControl1 As Object
  62. Private mControl2 As Object
  63. Private mSplitPercent As Single
  64. '********************************
  65. ' Read-Write Properties
  66. '********************************
  67. Public Property Get HorizontalSplit() As Boolean
  68.     HorizontalSplit = mHorizontalSplit
  69. End Property
  70. Public Property Let HorizontalSplit(val As Boolean)
  71.     mHorizontalSplit = val
  72.     If mHorizontalSplit Then
  73.         Splitter.MousePointer = 7
  74.     Else
  75.         Splitter.MousePointer = 9
  76.     End If
  77.     PropertyChanged "HorizontalSplit"
  78.     UserControl_Resize
  79. End Property
  80. Public Property Get Control1() As Object
  81.     Set Control1 = mControl1
  82. End Property
  83. Public Property Set Control1(ctl As Object)
  84.     Set mControl1 = ctl
  85.     PropertyChanged "Control1"
  86.     UserControl_Resize
  87. End Property
  88. Public Property Get Control2() As Object
  89.     Set Control2 = mControl2
  90. End Property
  91. Public Property Set Control2(ctl As Object)
  92.     Set mControl2 = ctl
  93.     PropertyChanged "Control2"
  94.     UserControl_Resize
  95. End Property
  96. Public Property Get SplitPercent() As Byte
  97.     SplitPercent = mSplitPercent * 100
  98. End Property
  99. Public Property Let SplitPercent(val As Byte)
  100.     mSplitPercent = val / 100
  101.     PropertyChanged "SplitPercent"
  102.     UserControl_Resize
  103. End Property
  104. '********************************
  105. ' Set up the defaults
  106. '********************************
  107. Private Sub UserControl_InitProperties()
  108.     HorizontalSplit = False
  109.     SplitPercent = 50
  110. End Sub
  111. '********************************
  112. ' Reload design-time settings
  113. '********************************
  114. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  115.     On Error Resume Next
  116.     HorizontalSplit = PropBag.ReadProperty("HorizontalSplit", False)
  117.     SplitPercent = PropBag.ReadProperty("SplitPercent", 50)
  118. End Sub
  119. '********************************
  120. ' Save design-time settings
  121. '********************************
  122. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  123.     PropBag.WriteProperty "HorizontalSplit", HorizontalSplit, False
  124.     PropBag.WriteProperty "SplitPercent", SplitPercent, 50
  125. End Sub
  126. '********************************
  127. ' These next three subs handle the actual
  128. ' dragging of the splitterbar.  The panes
  129. ' are updated when the mouse button is
  130. ' released.
  131. '********************************
  132. Private Sub splitter_mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  133.     Splitter.BackColor = &H80000008     ' Make the splitter visible
  134.     Splitter.ZOrder
  135. End Sub
  136. Private Sub splitter_mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  137.     If Button = vbLeftButton Then
  138.         If mHorizontalSplit Then        ' horizontal figures
  139.             Y = Splitter.Top - (SPLITWIDTH - Y)
  140.             mSplitPercent = Y / UserControl.Height
  141.             Splitter.Move 0, Y
  142.         Else                                    ' vertical
  143.             X = Splitter.Left - (SPLITWIDTH - X)
  144.             mSplitPercent = X / UserControl.Width
  145.             Splitter.Move X
  146.         End If
  147.         If mSplitPercent < 0.1 Then mSplitPercent = 0.1     ' Check if in range
  148.         If mSplitPercent > 0.9 Then mSplitPercent = 0.9
  149.     End If
  150. End Sub
  151. Private Sub splitter_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  152.     Splitter.BackColor = &H8000000F     ' change the color back to normal
  153.     UserControl_Resize                          ' update the panes
  154. End Sub
  155. '********************************
  156. ' The resize event is where it get's ugly
  157. ' Here we must figure out the sizes and
  158. ' positions of everything based on the splitter
  159. ' position, and the controls properties, then
  160. ' set everything
  161. '********************************
  162. Private Sub UserControl_Resize()
  163.     On Error Resume Next
  164.     If UserControl.Ambient.UserMode Then    ' get rid of border in run mode
  165.         UserControl.BorderStyle = 0
  166.     End If
  167.     Dim pane1 As Single
  168.     Dim pane2 As Single
  169.     Dim totwidth As Single
  170.     Dim totheight As Single
  171.     totwidth = UserControl.Width
  172.     totheight = UserControl.Height
  173.     If mHorizontalSplit Then
  174.         pane1 = (totheight - SPLITWIDTH) * mSplitPercent
  175.         pane2 = (totheight - SPLITWIDTH) * (1 - mSplitPercent)
  176.         mControl1.Move 0, 0, totwidth, pane1
  177.         mControl2.Move 0, pane1 + SPLITWIDTH, totwidth, pane2
  178.         Splitter.Move 0, pane1, totwidth, SPLITWIDTH
  179.     Else
  180.         pane1 = (totwidth - SPLITWIDTH) * mSplitPercent
  181.         pane2 = (totwidth - SPLITWIDTH) * (1 - mSplitPercent)
  182.         mControl1.Move 0, 0, pane1, totheight
  183.         mControl2.Move pane1 + SPLITWIDTH, 0, pane2, totheight
  184.         Splitter.Move pane1, 0, SPLITWIDTH, totheight
  185.     End If
  186. End Sub
  187.