home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch15 / qdraw / qdraw.dob (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-20  |  14.6 KB  |  453 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Begin VB.UserDocument QDrawDoc 
  4.    AutoRedraw      =   -1  'True
  5.    BackColor       =   &H00FFFFFF&
  6.    ClientHeight    =   3630
  7.    ClientLeft      =   1740
  8.    ClientTop       =   2595
  9.    ClientWidth     =   3870
  10.    BeginProperty Font 
  11.       Name            =   "MS Sans Serif"
  12.       Size            =   12
  13.       Charset         =   0
  14.       Weight          =   400
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H000000FF&
  20.    HScrollSmallChange=   15
  21.    PaletteMode     =   2  'Custom
  22.    ScaleHeight     =   3630
  23.    ScaleWidth      =   3870
  24.    VScrollSmallChange=   15
  25.    Begin VB.PictureBox Picture1 
  26.       AutoRedraw      =   -1  'True
  27.       BeginProperty Font 
  28.          Name            =   "MS Sans Serif"
  29.          Size            =   8.25
  30.          Charset         =   0
  31.          Weight          =   400
  32.          Underline       =   0   'False
  33.          Italic          =   0   'False
  34.          Strikethrough   =   0   'False
  35.       EndProperty
  36.       Height          =   2535
  37.       Left            =   225
  38.       ScaleHeight     =   2475
  39.       ScaleWidth      =   1515
  40.       TabIndex        =   0
  41.       Top             =   735
  42.       Visible         =   0   'False
  43.       Width           =   1575
  44.    End
  45.    Begin MSComDlg.CommonDialog CommonDialog1 
  46.       Left            =   315
  47.       Top             =   165
  48.       _ExtentX        =   847
  49.       _ExtentY        =   847
  50.       _Version        =   327680
  51.       FontSize        =   1.17491e-38
  52.    End
  53.    Begin VB.Label Label1 
  54.       Appearance      =   0  'Flat
  55.       AutoSize        =   -1  'True
  56.       BackColor       =   &H80000005&
  57.       BackStyle       =   0  'Transparent
  58.       ForeColor       =   &H80000008&
  59.       Height          =   300
  60.       Left            =   930
  61.       TabIndex        =   1
  62.       Top             =   210
  63.       Visible         =   0   'False
  64.       Width           =   60
  65.    End
  66.    Begin VB.Menu FileMenu 
  67.       Caption         =   "File"
  68.       NegotiatePosition=   3  'Right
  69.       Begin VB.Menu FileNew 
  70.          Caption         =   "New"
  71.          NegotiatePosition=   3  'Right
  72.       End
  73.       Begin VB.Menu FileOpen 
  74.          Caption         =   "Open"
  75.          NegotiatePosition=   3  'Right
  76.       End
  77.       Begin VB.Menu FileSave 
  78.          Caption         =   "Save"
  79.          NegotiatePosition=   3  'Right
  80.       End
  81.       Begin VB.Menu FileSaveAs 
  82.          Caption         =   "Save As"
  83.          NegotiatePosition=   3  'Right
  84.       End
  85.       Begin VB.Menu FileExit 
  86.          Caption         =   "Exit"
  87.          NegotiatePosition=   3  'Right
  88.       End
  89.    End
  90.    Begin VB.Menu EditMenu 
  91.       Caption         =   "Edit"
  92.       NegotiatePosition=   3  'Right
  93.       Begin VB.Menu EditCopy 
  94.          Caption         =   "Copy"
  95.          NegotiatePosition=   3  'Right
  96.       End
  97.       Begin VB.Menu EditCut 
  98.          Caption         =   "Cut"
  99.          NegotiatePosition=   3  'Right
  100.       End
  101.       Begin VB.Menu EditPaste 
  102.          Caption         =   "Paste"
  103.          NegotiatePosition=   3  'Right
  104.       End
  105.       Begin VB.Menu EditClear 
  106.          Caption         =   "Clear"
  107.          NegotiatePosition=   3  'Right
  108.       End
  109.    End
  110.    Begin VB.Menu ShapeMenu 
  111.       Caption         =   "Shape"
  112.       NegotiatePosition=   3  'Right
  113.       Begin VB.Menu DrawLine 
  114.          Caption         =   "Line"
  115.          NegotiatePosition=   3  'Right
  116.       End
  117.       Begin VB.Menu DrawCircle 
  118.          Caption         =   "Circle"
  119.          NegotiatePosition=   3  'Right
  120.       End
  121.       Begin VB.Menu DrawBox 
  122.          Caption         =   "Box"
  123.          NegotiatePosition=   3  'Right
  124.       End
  125.       Begin VB.Menu DrawText 
  126.          Caption         =   "Text"
  127.          NegotiatePosition=   3  'Right
  128.       End
  129.    End
  130.    Begin VB.Menu WidthMenu 
  131.       Caption         =   "Width"
  132.       NegotiatePosition=   3  'Right
  133.       Begin VB.Menu width1 
  134.          Caption         =   "1 pixel"
  135.          NegotiatePosition=   3  'Right
  136.       End
  137.       Begin VB.Menu Width2 
  138.          Caption         =   "2 pixels"
  139.          NegotiatePosition=   3  'Right
  140.       End
  141.       Begin VB.Menu Width3 
  142.          Caption         =   "3 pixels"
  143.          NegotiatePosition=   3  'Right
  144.       End
  145.    End
  146.    Begin VB.Menu StyleMenu 
  147.       Caption         =   "DrawStyle"
  148.       NegotiatePosition=   3  'Right
  149.       Begin VB.Menu StyleSolid 
  150.          Caption         =   "Solid"
  151.          NegotiatePosition=   3  'Right
  152.       End
  153.       Begin VB.Menu StyleDash 
  154.          Caption         =   "Dash"
  155.          NegotiatePosition=   3  'Right
  156.       End
  157.       Begin VB.Menu StyleDot 
  158.          Caption         =   "Dot"
  159.          NegotiatePosition=   3  'Right
  160.       End
  161.       Begin VB.Menu menuSeparator 
  162.          Caption         =   "-"
  163.          NegotiatePosition=   3  'Right
  164.       End
  165.       Begin VB.Menu StyleFilled 
  166.          Caption         =   "Solid Shape"
  167.          NegotiatePosition=   3  'Right
  168.       End
  169.    End
  170.    Begin VB.Menu ColorMenu 
  171.       Caption         =   "Colors"
  172.       NegotiatePosition=   3  'Right
  173.       Begin VB.Menu ColorPage 
  174.          Caption         =   "Page Color"
  175.          NegotiatePosition=   3  'Right
  176.       End
  177.       Begin VB.Menu ColorPen 
  178.          Caption         =   "Pen Color"
  179.          NegotiatePosition=   3  'Right
  180.       End
  181.       Begin VB.Menu ColorFill 
  182.          Caption         =   "Fill Color"
  183.          NegotiatePosition=   3  'Right
  184.       End
  185.    End
  186. Attribute VB_Name = "QDrawDoc"
  187. Attribute VB_GlobalNameSpace = False
  188. Attribute VB_Creatable = True
  189. Attribute VB_PredeclaredId = False
  190. Attribute VB_Exposed = True
  191. Option Explicit
  192. Dim Shape As String
  193. Dim XStart, YStart, XPrevious, YPrevious As Single
  194. Dim CopyBMP, PasteBMP, CutBMP, PrintText As Integer
  195. Dim PDrawWidth, PDrawStyle, PFillStyle As Integer
  196. Dim CopyWidth, CopyHeight As Integer
  197. Dim XLabel, YLabel As Integer
  198. Dim OpenFile As String
  199. Private Sub UserDocument_Initialize()
  200.     Call Form_Load
  201. End Sub
  202. Private Sub UnCheckStyles()
  203.     StyleSolid.Checked = False
  204.     StyleDash.Checked = False
  205.     StyleDot.Checked = False
  206. End Sub
  207. Private Sub ColorFill_Click()
  208.     CommonDialog1.Color = UserDocument.FillColor
  209.     CommonDialog1.Flags = cdlCCRGBInit
  210.     CommonDialog1.ShowColor
  211.     UserDocument.FillColor = CommonDialog1.Color
  212. End Sub
  213. Private Sub ColorPage_Click()
  214.     CommonDialog1.Color = UserDocument.BackColor
  215.     CommonDialog1.Flags = cdlCCRGBInit
  216.     CommonDialog1.ShowColor
  217.     UserDocument.BackColor = CommonDialog1.Color
  218. End Sub
  219. Private Sub ColorPen_Click()
  220.     CommonDialog1.Color = UserDocument.ForeColor
  221.     CommonDialog1.Flags = cdlCCRGBInit
  222.     CommonDialog1.ShowColor
  223.     UserDocument.ForeColor = CommonDialog1.Color
  224. End Sub
  225. Private Sub DrawBox_Click()
  226.     Shape = "BOX"
  227. End Sub
  228. Private Sub DrawCircle_Click()
  229.     Shape = "CIRCLE"
  230. End Sub
  231. Private Sub DrawLine_Click()
  232.     Shape = "LINE"
  233. End Sub
  234. Private Sub DrawText_Click()
  235. Dim DrawString As String
  236.     DrawString = InputBox("Enter string")
  237.     Label1.Caption = DrawString
  238.     Label1.ForeColor = UserDocument.ForeColor
  239.     PrintText = True
  240. End Sub
  241. Private Sub EditClear_Click()
  242.     UserDocument.Cls
  243. End Sub
  244. Private Sub EditCopy_Click()
  245.     CopyBMP = True
  246. End Sub
  247. Private Sub EditCut_Click()
  248.     CutBMP = True
  249. End Sub
  250. Private Sub EditPaste_Click()
  251.     PasteBMP = True
  252. End Sub
  253. Private Sub FileExit_Click()
  254. '[AXDW] The following line was commented out by the ActiveX Document Migration Wizard.
  255. '    End
  256. End Sub
  257. Private Sub FileNew_Click()
  258.     UserDocument.Picture = LoadPicture()
  259.     OpenFile = ""
  260. End Sub
  261. Private Sub FileOpen_Click()
  262.     CommonDialog1.Filter = "Images|*.bmp;*.gif;*.jpg"
  263.     CommonDialog1.DefaultExt = "BMP"
  264.     CommonDialog1.ShowOpen
  265.     If CommonDialog1.filename = "" Then Exit Sub
  266.     UserDocument.Picture = LoadPicture(CommonDialog1.filename)
  267.     OpenFile = CommonDialog1.filename
  268.     Picture1.Picture = UserDocument.Picture
  269. End Sub
  270. Private Sub FileSave_Click()
  271.     If OpenFile <> "" Then
  272.         SavePicture Image, OpenFile
  273.     End If
  274. End Sub
  275. Private Sub FileSaveAs_Click()
  276.     CommonDialog1.Filter = "Images|*.bmp"
  277.     CommonDialog1.DefaultExt = "BMP"
  278.     CommonDialog1.ShowSave
  279.     If CommonDialog1.filename = "" Then Exit Sub
  280.     SavePicture UserDocument.Image, CommonDialog1.filename
  281.     OpenFile = CommonDialog1.filename
  282. End Sub
  283. Private Sub Form_Load()
  284.     CopyBMP = False
  285.     PasteBMP = False
  286.     PrintText = False
  287. End Sub
  288. Private Sub UserDocument_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  289.     If Button = 2 Then Shape = ""
  290.     If Button = 1 Then
  291.         XStart = X
  292.         YStart = Y
  293.         XPrevious = XStart
  294.         YPrevious = YStart
  295.         UserDocument.AutoRedraw = False
  296.     End If
  297.     If CopyBMP Or CutBMP Then
  298.         PDrawWidth = UserDocument.DrawWidth
  299.         PDrawStyle = UserDocument.DrawStyle
  300.         PFillStyle = UserDocument.FillStyle
  301.         UserDocument.DrawWidth = 1
  302.         UserDocument.DrawStyle = 0
  303.         UserDocument.FillStyle = 1
  304.     End If
  305.     If PasteBMP Then
  306.         UserDocument.PaintPicture Picture1.Image, X, Y, CopyWidth, CopyHeight, 0, 0, CopyWidth, CopyHeight, &HCC0020
  307.         XPrevious = X
  308.         YPrevious = Y
  309.         Exit Sub
  310.     End If
  311. If PrintText Then
  312.     Label1.Visible = True
  313.     Label1.Left = X
  314.     Label1.Top = Y
  315.     Exit Sub
  316. End If
  317. End Sub
  318. Private Sub UserDocument_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  319.     If Button <> 1 Then Exit Sub
  320.     If CopyBMP Or CutBMP Then
  321.         UserDocument.Line (XStart, YStart)-(XPrevious, YPrevious), , B
  322.         UserDocument.Refresh
  323.         UserDocument.Line (XStart, YStart)-(X, Y), , B
  324.         XPrevious = X
  325.         YPrevious = Y
  326.         Exit Sub
  327.     End If
  328.     If PasteBMP Then
  329.         UserDocument.PaintPicture Picture1.Image, XPrevious, YPrevious, CopyWidth, CopyHeight, 0, 0, CopyWidth, CopyHeight, &H660046
  330.         UserDocument.Refresh
  331.         UserDocument.PaintPicture Picture1.Image, X, Y, CopyWidth, CopyHeight, 0, 0, CopyWidth, CopyHeight, &HCC0020
  332.         Exit Sub
  333.     End If
  334. If PrintText Then
  335.     Label1.Left = X
  336.     Label1.Top = Y
  337.     Exit Sub
  338. End If
  339.     Select Case Shape
  340.         Case "LINE":
  341.             'userdocument.Line (XStart, YStart)-(XPrevious, YPrevious)
  342.             UserDocument.Refresh
  343.             UserDocument.Line (XStart, YStart)-(X, Y)
  344.         Case "CIRCLE":
  345.             'userdocument.Circle (XStart, YStart), Sqr((XPrevious - XStart) ^ 2 + (YPrevious - YStart) ^ 2)
  346.             UserDocument.Refresh
  347.             UserDocument.Circle (XStart, YStart), Sqr((X - XStart) ^ 2 + (Y - YStart) ^ 2)
  348.         Case "BOX":
  349.             'userdocument.Line (XStart, YStart)-(XPrevious, YPrevious), , B
  350.             UserDocument.Refresh
  351.             UserDocument.Line (XStart, YStart)-(X, Y), , B
  352.     End Select
  353.         
  354. End Sub
  355. Private Sub UserDocument_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  356. Dim X1, Y1
  357.     If CopyBMP Then
  358.         UserDocument.Line (XStart, YStart)-(XPrevious, YPrevious), , B
  359.         UserDocument.Refresh
  360.         If X > XStart Then X1 = XStart Else X1 = X
  361.         If Y > YStart Then Y1 = YStart Else Y1 = Y
  362.         Picture1.PaintPicture UserDocument.Image, 0, 0, Abs(X - XStart), Abs(Y - YStart), X1, Y1, Abs(X - XStart), Abs(Y - YStart), &HCC0020
  363.         CopyBMP = False
  364.         UserDocument.DrawWidth = PDrawWidth
  365.         UserDocument.DrawStyle = PDrawStyle
  366.         UserDocument.FillStyle = PFillStyle
  367.         CopyWidth = Abs(X - XStart)
  368.         CopyHeight = Abs(Y - YStart)
  369.         Exit Sub
  370.     End If
  371.     If CutBMP Then
  372.         UserDocument.AutoRedraw = True
  373.         CopyWidth = XStart - X
  374.         CopyHeight = YStart - Y
  375.         If X > XStart Then X1 = XStart Else X1 = X
  376.         If Y > YStart Then Y1 = YStart Else Y1 = Y
  377.         Picture1.PaintPicture UserDocument.Image, 0, 0, Abs(X - XStart), Abs(Y - YStart), X1, Y1, Abs(X - XStart), Abs(Y - YStart), &HCC0020
  378.         UserDocument.Line (X, Y)-Step(CopyWidth, CopyHeight), UserDocument.BackColor, BF
  379.         CutBMP = False
  380.         UserDocument.DrawWidth = PDrawWidth
  381.         UserDocument.DrawStyle = PDrawStyle
  382.         UserDocument.FillStyle = PFillStyle
  383.         CopyWidth = Abs(X - XStart)
  384.         CopyHeight = Abs(Y - YStart)
  385.        
  386.         Exit Sub
  387.     End If
  388.     If PasteBMP Then
  389.         UserDocument.AutoRedraw = True
  390.         UserDocument.PaintPicture Picture1.Image, X, Y, CopyWidth, CopyHeight, 0, 0, CopyWidth, CopyHeight, &HCC0020
  391.         PasteBMP = False
  392.         Exit Sub
  393.     End If
  394.     If PrintText Then
  395.         UserDocument.AutoRedraw = True
  396.         UserDocument.CurrentX = X
  397.         UserDocument.CurrentY = Y
  398.         UserDocument.Print Label1.Caption
  399.         Label1.Visible = False
  400.         PrintText = False
  401.         Exit Sub
  402.     End If
  403.     'userdocument.DrawMode = 13
  404.     UserDocument.Refresh
  405.     UserDocument.AutoRedraw = True
  406.     Select Case Shape
  407.         Case "LINE":
  408.             UserDocument.Line (XStart, YStart)-(X, Y)
  409.         Case "CIRCLE":
  410.             UserDocument.Circle (XStart, YStart), Sqr((X - XStart) ^ 2 + (Y - YStart) ^ 2)
  411.         Case "BOX":
  412.             UserDocument.Line (XStart, YStart)-(X, Y), , B
  413.     End Select
  414. End Sub
  415. Private Sub UserDocument_Resize()
  416. '[AXDW] The following statement is invalid in a User Document:'Width'
  417.     Picture1.Width = UserDocument.Width
  418. '[AXDW] The following statement is invalid in a User Document:'Height'
  419.     Picture1.Height = UserDocument.Height
  420. End Sub
  421. Private Sub StyleDash_Click()
  422.     UnCheckStyles
  423.     StyleDash.Checked = True
  424.     UserDocument.DrawStyle = 1
  425. End Sub
  426. Private Sub StyleDot_Click()
  427.     UnCheckStyles
  428.     StyleDot.Checked = True
  429.     UserDocument.DrawStyle = 2
  430. End Sub
  431. Private Sub StyleFilled_Click()
  432.     StyleFilled.Checked = Not StyleFilled.Checked
  433.     If StyleFilled.Checked Then
  434.         UserDocument.FillStyle = 0
  435.     Else
  436.         UserDocument.FillStyle = 1
  437.     End If
  438. End Sub
  439. Private Sub StyleSolid_Click()
  440.     UnCheckStyles
  441.     StyleSolid.Checked = True
  442.     UserDocument.DrawStyle = 0
  443. End Sub
  444. Private Sub width1_Click()
  445.     UserDocument.DrawWidth = 1
  446. End Sub
  447. Private Sub Width2_Click()
  448.     UserDocument.DrawWidth = 2
  449. End Sub
  450. Private Sub Width3_Click()
  451.     UserDocument.DrawWidth = 3
  452. End Sub
  453.