home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / drawfram / drawfram.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-07  |  15.0 KB  |  456 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "DrawFrameOn"
  6.    ClientHeight    =   3390
  7.    ClientLeft      =   105
  8.    ClientTop       =   1710
  9.    ClientWidth     =   6645
  10.    Height          =   4080
  11.    Icon            =   0
  12.    Left            =   45
  13.    LinkTopic       =   "Form1"
  14.    ScaleHeight     =   3390
  15.    ScaleWidth      =   6645
  16.    Top             =   1080
  17.    Width           =   6765
  18.    Begin TextBox Text1 
  19.       BackColor       =   &H00C0C0C0&
  20.       BorderStyle     =   0  'None
  21.       FontBold        =   0   'False
  22.       FontItalic      =   0   'False
  23.       FontName        =   "MS Sans Serif"
  24.       FontSize        =   8.25
  25.       FontStrikethru  =   0   'False
  26.       FontUnderline   =   0   'False
  27.       ForeColor       =   &H00000000&
  28.       Height          =   705
  29.       Left            =   1380
  30.       MultiLine       =   -1  'True
  31.       TabIndex        =   7
  32.       Text            =   "Text1"
  33.       Top             =   2310
  34.       Width           =   4065
  35.    End
  36.    Begin PictureBox Picture7 
  37.       AutoSize        =   -1  'True
  38.       BackColor       =   &H00C0C0C0&
  39.       BorderStyle     =   0  'None
  40.       Height          =   480
  41.       Left            =   4830
  42.       Picture         =   DRAWFRAM.FRX:0000
  43.       ScaleHeight     =   480
  44.       ScaleWidth      =   480
  45.       TabIndex        =   6
  46.       Top             =   1350
  47.       Width           =   480
  48.    End
  49.    Begin PictureBox Picture5 
  50.       AutoSize        =   -1  'True
  51.       BackColor       =   &H00C0C0C0&
  52.       BorderStyle     =   0  'None
  53.       Height          =   480
  54.       Left            =   3600
  55.       Picture         =   DRAWFRAM.FRX:0302
  56.       ScaleHeight     =   480
  57.       ScaleWidth      =   480
  58.       TabIndex        =   5
  59.       Top             =   1350
  60.       Width           =   480
  61.    End
  62.    Begin PictureBox Picture6 
  63.       AutoSize        =   -1  'True
  64.       BackColor       =   &H00C0C0C0&
  65.       BorderStyle     =   0  'None
  66.       Height          =   480
  67.       Left            =   4215
  68.       Picture         =   DRAWFRAM.FRX:0604
  69.       ScaleHeight     =   480
  70.       ScaleWidth      =   480
  71.       TabIndex        =   0
  72.       Top             =   1350
  73.       Width           =   480
  74.    End
  75.    Begin PictureBox Picture4 
  76.       AutoSize        =   -1  'True
  77.       BackColor       =   &H00C0C0C0&
  78.       BorderStyle     =   0  'None
  79.       Height          =   480
  80.       Left            =   2985
  81.       Picture         =   DRAWFRAM.FRX:0906
  82.       ScaleHeight     =   480
  83.       ScaleWidth      =   480
  84.       TabIndex        =   4
  85.       Top             =   1350
  86.       Width           =   480
  87.    End
  88.    Begin PictureBox Picture3 
  89.       AutoSize        =   -1  'True
  90.       BackColor       =   &H00C0C0C0&
  91.       BorderStyle     =   0  'None
  92.       Height          =   480
  93.       Left            =   2370
  94.       Picture         =   DRAWFRAM.FRX:0C08
  95.       ScaleHeight     =   480
  96.       ScaleWidth      =   480
  97.       TabIndex        =   3
  98.       Top             =   1350
  99.       Width           =   480
  100.    End
  101.    Begin PictureBox Picture2 
  102.       AutoSize        =   -1  'True
  103.       BackColor       =   &H00C0C0C0&
  104.       BorderStyle     =   0  'None
  105.       Height          =   480
  106.       Left            =   1740
  107.       Picture         =   DRAWFRAM.FRX:0F0A
  108.       ScaleHeight     =   480
  109.       ScaleWidth      =   480
  110.       TabIndex        =   2
  111.       Top             =   1350
  112.       Width           =   480
  113.    End
  114.    Begin PictureBox Picture1 
  115.       AutoSize        =   -1  'True
  116.       BackColor       =   &H00C0C0C0&
  117.       BorderStyle     =   0  'None
  118.       Height          =   480
  119.       Left            =   1125
  120.       Picture         =   DRAWFRAM.FRX:120C
  121.       ScaleHeight     =   480
  122.       ScaleWidth      =   480
  123.       TabIndex        =   1
  124.       Top             =   1350
  125.       Width           =   480
  126.    End
  127.    Begin Label Label2 
  128.       BackColor       =   &H00C0C0C0&
  129.       Caption         =   "Label2"
  130.       Height          =   285
  131.       Left            =   2490
  132.       TabIndex        =   9
  133.       Top             =   810
  134.       Width           =   2355
  135.    End
  136.    Begin Label Label1 
  137.       BackColor       =   &H00C0C0C0&
  138.       Caption         =   "Label1"
  139.       FontBold        =   0   'False
  140.       FontItalic      =   0   'False
  141.       FontName        =   "MS Sans Serif"
  142.       FontSize        =   8.25
  143.       FontStrikethru  =   0   'False
  144.       FontUnderline   =   0   'False
  145.       Height          =   465
  146.       Left            =   240
  147.       TabIndex        =   8
  148.       Top             =   120
  149.       Width           =   6195
  150.    End
  151.    Begin Menu menuBar 
  152.       Caption         =   "Color"
  153.       Index           =   0
  154.       Begin Menu menuColor 
  155.          Caption         =   "Black"
  156.          Index           =   0
  157.       End
  158.       Begin Menu menuColor 
  159.          Caption         =   "Dark Blue"
  160.          Index           =   1
  161.       End
  162.       Begin Menu menuColor 
  163.          Caption         =   "Dark Green"
  164.          Index           =   2
  165.       End
  166.       Begin Menu menuColor 
  167.          Caption         =   "Dark Cyan"
  168.          Index           =   3
  169.       End
  170.       Begin Menu menuColor 
  171.          Caption         =   "Dark Red"
  172.          Index           =   4
  173.       End
  174.       Begin Menu menuColor 
  175.          Caption         =   "Dark Purple"
  176.          Index           =   5
  177.       End
  178.       Begin Menu menuColor 
  179.          Caption         =   "Dark Yellow"
  180.          Index           =   6
  181.       End
  182.       Begin Menu menuColor 
  183.          Caption         =   "Light Gray"
  184.          Index           =   7
  185.       End
  186.       Begin Menu menuColor 
  187.          Caption         =   "Dark Gray"
  188.          Index           =   8
  189.       End
  190.       Begin Menu menuColor 
  191.          Caption         =   "Bright Blue"
  192.          Index           =   9
  193.       End
  194.       Begin Menu menuColor 
  195.          Caption         =   "Bright Green"
  196.          Index           =   10
  197.       End
  198.       Begin Menu menuColor 
  199.          Caption         =   "Bright Cyan"
  200.          Index           =   11
  201.       End
  202.       Begin Menu menuColor 
  203.          Caption         =   "Bright Red"
  204.          Index           =   12
  205.       End
  206.       Begin Menu menuColor 
  207.          Caption         =   "Bright Purple"
  208.          Index           =   13
  209.       End
  210.       Begin Menu menuColor 
  211.          Caption         =   "Bright Yellow"
  212.          Index           =   14
  213.       End
  214.       Begin Menu menuColor 
  215.          Caption         =   "Bright White"
  216.          Index           =   15
  217.       End
  218.    End
  219.    Begin Menu menuBar 
  220.       Caption         =   "Exit"
  221.       Index           =   1
  222.    End
  223. Option Explicit
  224.     Dim Distance As Integer
  225.     Dim Color As Integer
  226.     Dim Pict As Integer
  227.     Dim Msg As String
  228. Sub DrawFrameOn (TopLeftControl As Control, BottomRightControl As Control, Style As String, FrameOffset As Integer, Color As Integer)
  229.     ' This program has Option Explicit set in the General Declarations
  230.     ' section so every variable has to be explicitly declared before it
  231.     ' is referenced.
  232.     '
  233.     Dim SaveDrawWidth, SaveFillStyle, SaveScaleMode
  234.     Dim Offset, TWIPS As Integer
  235.     Dim xx, yy As Integer
  236.     Dim x1, y1, x2, y2 As Integer
  237.     Dim FrameLeft, FrameTop, FrameWidth, FrameHeight
  238.     ' Save the FORM's properties so you can restore them when leaving the
  239.     ' sub-routine.
  240.     '
  241.     SaveDrawWidth = DrawWidth
  242.     SaveFillStyle = FillStyle
  243.     SaveScaleMode = ScaleMode
  244.     DrawWidth = 1
  245.     FillStyle = 1
  246.     ScaleMode = 1
  247.     ' Since the Windows scale default is twips and I haven't changed it, you
  248.     ' have to find out the number of twips per pixel there are on your
  249.     ' particular monitor.
  250.     '
  251.     TWIPS = screen.TwipsPerPixelX
  252.     Offset = FrameOffset * TWIPS
  253.     ' Just as each control has its Left, Top, Width, and Height; you must
  254.     ' find out those dimensions for the Frame.
  255.     FrameLeft = TopLeftControl.Left
  256.     FrameTop = TopLeftControl.Top
  257.     FrameWidth = BottomRightControl.Left + BottomRightControl.Width
  258.     FrameHeight = BottomRightControl.Top + BottomRightControl.Height
  259.     ' Draw a colored box the same size as the largest Frame. The controls
  260.     ' won't be affected as they are drawn on top of Lines and every Frame
  261.     ' of smaller size also draws its color, so the end effect is color
  262.     ' between Frames. This means you must draw the Frames in order from
  263.     ' the largest to the smallest.
  264.     '
  265.     ' Also, when you want to find the right-most position occupied by a
  266.     ' control where you are given its left-most position and its width,
  267.     ' you must add the left postion and the width and subtract one.
  268.     '     right-most position = (Control.Left + Control.Width) - 1
  269.     ' For example: Your command button's Left property is 3 and its width
  270.     ' is 5, so it occupies positions 3, 4, 5, 6, 7. To find its right
  271.     ' most position, you add its Left, 3, and Width, 5, and subtract 1.
  272.     '     7 = 3 + 5 - 1
  273.     '
  274.     ' In "x2 =" and "y2 =" below we substract the number of twips in each
  275.     ' pixel so that the Frames right and bottom lines will each be the same
  276.     ' distance away from the control as the Frames top and left lines. The
  277.     ' OFFSET is the number of pixels away from the control the Frame is.
  278.     '
  279.     'Top-left to Bottom-Right box in Color
  280.     x1 = FrameLeft - Offset
  281.     y1 = FrameTop - Offset
  282.     x2 = FrameWidth + Offset - TWIPS
  283.     y2 = FrameHeight + Offset - TWIPS
  284.     Line (x1, y1)-(x2, y2), QBColor(Color), BF
  285.     ' This determines if the left & top lines are white and the right &
  286.     ' bottom lines are dark gray (for the "Raised" look) or the left & top
  287.     ' lines are dark gray and the right & bottom lines are white (for the
  288.     ' "Inset" look).  Since this routine only tests the first character of
  289.     ' the parameter changed to upper case, you could just put in an r or an
  290.     ' i in either upper or lower case. But putting in the whole word makes
  291.     ' the program read easier.
  292.     '
  293.     ' Try substituting black, 0, for dark gray for a sharper look.
  294.     '
  295.     If UCase$(Left$(Style, 1)) = "R" Then
  296.         xx = 15  ' Bright White
  297.         yy = 8   ' Dark Gray
  298.     Else
  299.         xx = 8
  300.         yy = 15
  301.     End If
  302.     ' The last line drawn covers up any lines below it. So the Frames left
  303.     ' and top lines are drawn first and the Frames right and bottom lines
  304.     ' are drawn last.
  305.     '
  306.     ' Bottom-left to Top-left line
  307.     x1 = FrameLeft - Offset
  308.     y1 = FrameHeight + Offset - TWIPS
  309.     x2 = FrameLeft - Offset
  310.     y2 = FrameTop - Offset - TWIPS
  311.     Line (x1, y1)-(x2, y2), QBColor(xx)
  312.     ' Top-left to Top-Right line
  313.     x1 = FrameLeft - Offset
  314.     y1 = FrameTop - Offset
  315.     x2 = FrameWidth + Offset
  316.     y2 = FrameTop - Offset
  317.     Line (x1, y1)-(x2, y2), QBColor(xx)
  318.     ' Top-Right to Bottom-Right line
  319.     x1 = FrameWidth + Offset - TWIPS
  320.     y1 = FrameTop - Offset
  321.     x2 = FrameWidth + Offset - TWIPS
  322.     y2 = FrameHeight + Offset
  323.     Line (x1, y1)-(x2, y2), QBColor(yy)
  324.     ' Bottom-Right to Bottom-Left line
  325.     x1 = FrameWidth + Offset - TWIPS
  326.     y1 = FrameHeight + Offset - TWIPS
  327.     x2 = FrameLeft - Offset - TWIPS
  328.     y2 = FrameHeight + Offset - TWIPS
  329.     Line (x1, y1)-(x2, y2), QBColor(yy)
  330.     ' Restore the FORM's original values
  331.     DrawWidth = SaveDrawWidth
  332.     FillStyle = SaveFillStyle
  333.     ScaleMode = SaveScaleMode
  334. End Sub
  335. Sub Form_Load ()
  336.     Show
  337.     Color = 7
  338.     Label1.Caption = "Sub DrawFrameOn  (TopLeftControl As Control,  BottomRightControl As Control,  Style As String,  FrameOffset As Integer,  Color As Integer)"
  339.     Label2.Caption = "Click the squares"
  340.     Text1.Text = ""
  341. End Sub
  342. Sub menuBar_Click (Index As Integer)
  343.     Select Case Index
  344.         Case 1
  345.             End
  346.     End Select
  347. End Sub
  348. Sub menuColor_Click (Index As Integer)
  349.     Dim i
  350.     For i = 0 To 15
  351.         menuColor(i).Checked = False
  352.     Next i
  353.     Color = Index
  354.     menuColor(Index).Checked = True
  355.     Select Case Pict
  356.         Case 1
  357.             Picture1_Click
  358.         Case 2
  359.             Picture2_Click
  360.         Case 3
  361.             Picture3_Click
  362.         Case 4
  363.             Picture4_Click
  364.         Case 5
  365.             Picture5_Click
  366.         Case 6
  367.             Picture6_Click
  368.     End Select
  369. End Sub
  370. Sub Picture1_Click ()
  371.     Dim LF
  372.     LF = Chr$(13) & Chr$(10)
  373.     Form1.BackColor = QBColor(7)
  374.     DrawFrameOn Picture1, Picture7, "Inset", 10, 7
  375.     Pict = 1
  376.     Msg = "DrawFrameOn Picture1, Picture7, "
  377.     Msg = Msg & Chr$(34) & "Inset"
  378.     Msg = Msg & Chr$(34) & ", 10, 7"
  379.     Text1.Text = Msg
  380. End Sub
  381. Sub Picture2_Click ()
  382.     Dim LF
  383.     LF = Chr$(13) & Chr$(10)
  384.     Form1.BackColor = QBColor(7)
  385.     DrawFrameOn Picture1, Picture7, "Raised", 10, 7
  386.     Pict = 2
  387.     Msg = "DrawFrameOn Picture1, Picture7, "
  388.     Msg = Msg & Chr$(34) & "Raised"
  389.     Msg = Msg & Chr$(34) & ", 10, 7"
  390.     Text1.Text = Msg
  391. End Sub
  392. Sub Picture3_Click ()
  393.     Dim LF
  394.     LF = Chr$(13) & Chr$(10)
  395.     Form1.BackColor = QBColor(7)
  396.     DrawFrameOn Picture1, Picture7, "Inset", 10, Color
  397.     DrawFrameOn Picture1, Picture7, "Raised", 5, 7
  398.     Pict = 3
  399.     Msg = "DrawFrameOn Picture1, Picture7, "
  400.     Msg = Msg & Chr$(34) & "Inset"
  401.     Msg = Msg & Chr$(34) & ", 10," & Str$(Color) & LF
  402.     Msg = Msg & "DrawFrameOn Picture1, Picture7, "
  403.     Msg = Msg & Chr$(34) & "Raised"
  404.     Msg = Msg & Chr$(34) & ", 5, 7"
  405.     Text1.Text = Msg
  406. End Sub
  407. Sub Picture4_Click ()
  408.     Dim LF
  409.     LF = Chr$(13) & Chr$(10)
  410.     Form1.BackColor = QBColor(7)
  411.     DrawFrameOn Picture1, Picture7, "Raised", 10, Color
  412.     DrawFrameOn Picture1, Picture7, "Inset", 5, 7
  413.     Pict = 4
  414.     Msg = "DrawFrameOn Picture1, Picture7, "
  415.     Msg = Msg & Chr$(34) & "Raised"
  416.     Msg = Msg & Chr$(34) & ", 10," & Str$(Color) & LF
  417.     Msg = Msg & "DrawFrameOn Picture1, Picture7, "
  418.     Msg = Msg & Chr$(34) & "Inset"
  419.     Msg = Msg & Chr$(34) & ", 5, 7"
  420.     Text1.Text = Msg
  421. End Sub
  422. Sub Picture5_Click ()
  423.     Dim LF
  424.     LF = Chr$(13) & Chr$(10)
  425.     Form1.BackColor = QBColor(7)
  426.     DrawFrameOn Picture1, Picture7, "Inset", 10, Color
  427.     DrawFrameOn Picture1, Picture7, "Inset", 5, 7
  428.     Pict = 5
  429.     Msg = "DrawFrameOn Picture1, Picture7, "
  430.     Msg = Msg & Chr$(34) & "Inset"
  431.     Msg = Msg & Chr$(34) & ", 10," & Str$(Color) & LF
  432.     Msg = Msg & "DrawFrameOn Picture1, Picture7, "
  433.     Msg = Msg & Chr$(34) & "Inset"
  434.     Msg = Msg & Chr$(34) & ", 5, 7"
  435.     Text1.Text = Msg
  436. End Sub
  437. Sub Picture6_Click ()
  438.     Dim LF
  439.     LF = Chr$(13) & Chr$(10)
  440.     Form1.BackColor = QBColor(7)
  441.     DrawFrameOn Picture1, Picture7, "Raised", 10, Color
  442.     DrawFrameOn Picture1, Picture7, "Raised", 5, 7
  443.     Pict = 6
  444.     Msg = "DrawFrameOn Picture1, Picture7, "
  445.     Msg = Msg & Chr$(34) & "Raised"
  446.     Msg = Msg & Chr$(34) & ", 10," & Str$(Color) & LF
  447.     Msg = Msg & "DrawFrameOn Picture1, Picture7, "
  448.     Msg = Msg & Chr$(34) & "Raised"
  449.     Msg = Msg & Chr$(34) & ", 5, 7"
  450.     Text1.Text = Msg
  451. End Sub
  452. Sub Picture7_Click ()
  453.     Form1.BackColor = QBColor(7)
  454.     Text1.Text = ""
  455. End Sub
  456.