home *** CD-ROM | disk | FTP | other *** search
/ Discovering Windows 98 / WinExpert9.iso / features / VisualBasic / Vb09 / frmDoodler.frm < prev    next >
Text File  |  1998-08-04  |  8KB  |  284 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmDoodler 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Doodler"
  6.    ClientHeight    =   4725
  7.    ClientLeft      =   150
  8.    ClientTop       =   720
  9.    ClientWidth     =   7725
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   4725
  14.    ScaleWidth      =   7725
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin MSComDlg.CommonDialog dlgFileOps 
  17.       Left            =   5160
  18.       Top             =   0
  19.       _ExtentX        =   847
  20.       _ExtentY        =   847
  21.       _Version        =   327680
  22.    End
  23.    Begin VB.PictureBox picDrawingArea 
  24.       AutoRedraw      =   -1  'True
  25.       BackColor       =   &H00FFFFFF&
  26.       Height          =   4215
  27.       Left            =   2160
  28.       ScaleHeight     =   4155
  29.       ScaleWidth      =   5355
  30.       TabIndex        =   5
  31.       Top             =   360
  32.       Width           =   5415
  33.    End
  34.    Begin VB.ListBox lstColours 
  35.       Height          =   1230
  36.       Left            =   120
  37.       TabIndex        =   4
  38.       Top             =   3360
  39.       Width           =   1935
  40.    End
  41.    Begin VB.CheckBox chkContinuousDrawing 
  42.       Caption         =   "Continuous Drawing"
  43.       Height          =   255
  44.       Left            =   120
  45.       TabIndex        =   2
  46.       Top             =   2760
  47.       Width           =   1935
  48.    End
  49.    Begin VB.CommandButton cmdClear 
  50.       Caption         =   "Clear"
  51.       Height          =   375
  52.       Left            =   120
  53.       TabIndex        =   1
  54.       Top             =   2280
  55.       Width           =   1935
  56.    End
  57.    Begin VB.Frame fraShape 
  58.       Caption         =   "Shape"
  59.       Height          =   2055
  60.       Left            =   120
  61.       TabIndex        =   0
  62.       Top             =   120
  63.       Width           =   1935
  64.       Begin VB.OptionButton optShape 
  65.          Caption         =   "Vertical Line"
  66.          Height          =   255
  67.          Index           =   3
  68.          Left            =   240
  69.          TabIndex        =   10
  70.          Top             =   1560
  71.          Width           =   1455
  72.       End
  73.       Begin VB.OptionButton optShape 
  74.          Caption         =   "Horizontal Line"
  75.          Height          =   255
  76.          Index           =   2
  77.          Left            =   240
  78.          TabIndex        =   9
  79.          Top             =   1200
  80.          Width           =   1455
  81.       End
  82.       Begin VB.OptionButton optShape 
  83.          Caption         =   "Square"
  84.          Height          =   255
  85.          Index           =   1
  86.          Left            =   240
  87.          TabIndex        =   8
  88.          Top             =   840
  89.          Width           =   1455
  90.       End
  91.       Begin VB.OptionButton optShape 
  92.          Caption         =   "Circle"
  93.          Height          =   255
  94.          Index           =   0
  95.          Left            =   240
  96.          TabIndex        =   7
  97.          Top             =   480
  98.          Width           =   1455
  99.       End
  100.    End
  101.    Begin VB.Label Label2 
  102.       Caption         =   "Drawing Area"
  103.       Height          =   255
  104.       Left            =   2160
  105.       TabIndex        =   6
  106.       Top             =   120
  107.       Width           =   1935
  108.    End
  109.    Begin VB.Label Label1 
  110.       Caption         =   "Colour"
  111.       Height          =   255
  112.       Left            =   120
  113.       TabIndex        =   3
  114.       Top             =   3120
  115.       Width           =   1935
  116.    End
  117.    Begin VB.Menu mnuFile 
  118.       Caption         =   "&File"
  119.       Begin VB.Menu mnuFileOpen 
  120.          Caption         =   "&Open..."
  121.       End
  122.       Begin VB.Menu mnuFileSaveAs 
  123.          Caption         =   "Save &As..."
  124.       End
  125.       Begin VB.Menu mnuFileExit 
  126.          Caption         =   "E&xit"
  127.       End
  128.    End
  129. End
  130. Attribute VB_Name = "frmDoodler"
  131. Attribute VB_GlobalNameSpace = False
  132. Attribute VB_Creatable = False
  133. Attribute VB_PredeclaredId = True
  134. Attribute VB_Exposed = False
  135. Option Explicit
  136. Private mlngChosenShape As Long
  137.  
  138. Private Sub cmdClear_Click()
  139.     picDrawingArea.Cls
  140.     Set picDrawingArea.Picture = Nothing
  141. End Sub
  142.  
  143. Private Sub Form_Load()
  144.  
  145.     With lstColours
  146.         .AddItem "Black"
  147.         .ItemData(.NewIndex) = RGB(0, 0, 0)
  148.         .AddItem "Red"
  149.         .ItemData(.NewIndex) = RGB(255, 0, 0)
  150.         .AddItem "Green"
  151.         .ItemData(.NewIndex) = RGB(0, 255, 0)
  152.         .AddItem "Blue"
  153.         .ItemData(.NewIndex) = RGB(0, 0, 255)
  154.         .AddItem "Yellow"
  155.         .ItemData(.NewIndex) = RGB(255, 255, 0)
  156.         .AddItem "Cyan"
  157.         .ItemData(.NewIndex) = RGB(0, 255, 255)
  158.         .AddItem "Magenta"
  159.         .ItemData(.NewIndex) = RGB(255, 0, 255)
  160.         .AddItem "White"
  161.         .ItemData(.NewIndex) = RGB(255, 255, 255)
  162.  
  163.         .ListIndex = 0
  164.     End With
  165.     
  166.     optShape(0).Value = True
  167.  
  168. End Sub
  169.  
  170. Private Sub mnuFileExit_Click()
  171.     Unload Me
  172. End Sub
  173.  
  174. Private Sub mnuFileOpen_Click()
  175.     Call mDoOpen
  176. End Sub
  177.  
  178. Private Sub mnuFileSaveAs_Click()
  179.     Call mDoSaveAs
  180. End Sub
  181.  
  182. Private Sub optShape_Click(Index As Integer)
  183.     mlngChosenShape = Index
  184. End Sub
  185.  
  186. Private Sub picDrawingArea_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  187.     
  188.     Call mDrawShape(X, Y)
  189.     
  190. End Sub
  191.  
  192. Private Sub picDrawingArea_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  193.     
  194.     If Button = vbLeftButton And chkContinuousDrawing = vbChecked Then
  195.         Call mDrawShape(X, Y)
  196.     End If
  197.  
  198. End Sub
  199.  
  200. Private Sub mDrawShape(X As Single, Y As Single)
  201.  
  202.     Dim lngColour As Long
  203.         
  204.     lngColour = lstColours.ItemData(lstColours.ListIndex)
  205.     
  206.     Select Case optShape(mlngChosenShape).Caption
  207.        Case "Circle"
  208.            picDrawingArea.Circle (X, Y), 300, lngColour
  209.        Case "Square"
  210.            picDrawingArea.Line (X - 300, Y - 300)-(X + 300, Y + 300), lngColour, B
  211.        Case "Horizontal Line"
  212.            picDrawingArea.Line (X - 300, Y)-(X + 300, Y), lngColour
  213.        Case "Vertical Line"
  214.            picDrawingArea.Line (X, Y - 300)-(X, Y + 300), lngColour
  215.        Case Else
  216.            MsgBox "Encountered unexpected shape """ & optShape(mlngChosenShape).Caption & """", vbExclamation, "Warning"
  217.     End Select
  218.  
  219. End Sub
  220.  
  221. Private Sub mDoOpen()
  222.  
  223.     Dim strFileName As String
  224.     
  225. TryAgain:
  226.     With dlgFileOps
  227.         .Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
  228.         .Filter = "All Files (*.*)|*.*|Bitmaps (*.bmp)|*.bmp|CompuServe GIF (*.gif)|*.gif|JPEG (*.jpg)|*.jpg|Icons (*.ico)|*.ico|Windows Metafiles (*.wmf)|*.wmf|Run Length Encoded (*.rle)|*.rle|Enhanced Metafiles (*.emf)|*.emf"
  229.         .ShowOpen
  230.         strFileName = .filename
  231.     End With
  232.     
  233.     If strFileName <> "" Then
  234.         On Error GoTo TellUser
  235.         picDrawingArea.Picture = LoadPicture(strFileName)
  236.     End If
  237.  
  238.     Exit Sub
  239.     
  240. TellUser:
  241.     Dim lngResult As Long
  242.     lngResult = MsgBox("Unable to open the file specified." & vbCrLf & _
  243.                        "Reason - " & Err.Description & vbCrLf & _
  244.                        "Do you want to try another file?", vbExclamation + _
  245.                        vbYesNo, "Open Failed")
  246.                         
  247.     If lngResult = vbYes Then
  248.         Resume TryAgain
  249.     End If
  250.     
  251. End Sub
  252.  
  253.  
  254. Private Sub mDoSaveAs()
  255.  
  256.     Dim strFileName As String
  257.     
  258. TryAgain:
  259.     strFileName = InputBox("Please enter a name for this image:", "Save As")
  260.     If strFileName <> "" Then
  261.         If UCase(Right(strFileName, 4)) <> ".BMP" Then
  262.             strFileName = strFileName & ".bmp"
  263.         End If
  264.         On Error GoTo TellUser
  265.         SavePicture picDrawingArea.Image, strFileName
  266.     End If
  267.  
  268.     Exit Sub
  269.     
  270. TellUser:
  271.     Dim lngResult As Long
  272.     lngResult = MsgBox("Unable to write the file specified." & vbCrLf & _
  273.                        "Reason - " & Err.Description & vbCrLf & _
  274.                        "Do you want to try another filename?", vbExclamation + _
  275.                        vbYesNo, "Save Failed")
  276.                         
  277.     If lngResult = vbYes Then
  278.         Resume TryAgain
  279.     End If
  280.  
  281. End Sub
  282.  
  283.  
  284.