home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch06 / qdraw / qdraw.frm (.txt) next >
Encoding:
Visual Basic Form  |  1996-03-03  |  12.6 KB  |  422 lines

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