home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / popup / popup.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-02-19  |  10.5 KB  |  388 lines

  1. VERSION 2.00
  2. Begin Form NotePad 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Popup Menu Custom Control Demo"
  5.    ClientHeight    =   5715
  6.    ClientLeft      =   945
  7.    ClientTop       =   1605
  8.    ClientWidth     =   9510
  9.    Height          =   6405
  10.    Left            =   885
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5715
  13.    ScaleWidth      =   9510
  14.    Top             =   975
  15.    Width           =   9630
  16.    Begin Frame Frame2 
  17.       BackColor       =   &H00C0C0C0&
  18.       Caption         =   "Position Popup"
  19.       Height          =   1815
  20.       Left            =   7680
  21.       TabIndex        =   7
  22.       Top             =   3240
  23.       Width           =   1695
  24.       Begin OptionButton Leftpos 
  25.          BackColor       =   &H00C0C0C0&
  26.          Caption         =   "Left"
  27.          Height          =   255
  28.          Left            =   120
  29.          TabIndex        =   10
  30.          Top             =   1440
  31.          Width           =   1455
  32.       End
  33.       Begin OptionButton Centrepos 
  34.          BackColor       =   &H00C0C0C0&
  35.          Caption         =   "Centre"
  36.          Height          =   255
  37.          Left            =   120
  38.          TabIndex        =   9
  39.          Top             =   960
  40.          Width           =   1455
  41.       End
  42.       Begin OptionButton Rightpos 
  43.          BackColor       =   &H00C0C0C0&
  44.          Caption         =   "Right"
  45.          Height          =   255
  46.          Left            =   120
  47.          TabIndex        =   8
  48.          Top             =   480
  49.          Width           =   1455
  50.       End
  51.    End
  52.    Begin Frame Frame1 
  53.       BackColor       =   &H00C0C0C0&
  54.       Caption         =   "Use Button"
  55.       Height          =   1455
  56.       Left            =   7680
  57.       TabIndex        =   4
  58.       Top             =   1680
  59.       Width           =   1695
  60.       Begin OptionButton Either 
  61.          BackColor       =   &H00C0C0C0&
  62.          Caption         =   "Either"
  63.          Height          =   255
  64.          Left            =   120
  65.          TabIndex        =   6
  66.          Top             =   360
  67.          Width           =   1455
  68.       End
  69.       Begin OptionButton Left 
  70.          BackColor       =   &H00C0C0C0&
  71.          Caption         =   "Left"
  72.          Height          =   255
  73.          Left            =   120
  74.          TabIndex        =   5
  75.          Top             =   960
  76.          Width           =   1455
  77.       End
  78.    End
  79.    Begin CommandButton Command3 
  80.       Caption         =   "Custom Popup "
  81.       Height          =   375
  82.       Left            =   7680
  83.       TabIndex        =   3
  84.       Top             =   1080
  85.       Width           =   1575
  86.    End
  87.    Begin CommandButton Command2 
  88.       Caption         =   "Popup Edit"
  89.       Height          =   375
  90.       Left            =   7680
  91.       TabIndex        =   2
  92.       Top             =   600
  93.       Width           =   1575
  94.    End
  95.    Begin CommonDialog CMDialog1 
  96.       Left            =   7560
  97.       Top             =   5160
  98.    End
  99.    Begin CommandButton Command1 
  100.       Caption         =   "Popup File"
  101.       Height          =   375
  102.       Left            =   7680
  103.       TabIndex        =   1
  104.       Top             =   120
  105.       Width           =   1575
  106.    End
  107.    Begin Popup Popup1 
  108.       Enabled         =   -1  'True
  109.       Left            =   8280
  110.       MenuAlignment   =   0  'Right
  111.       MenuCaption     =   ""
  112.       Top             =   5160
  113.       TrackingButton  =   0  'Left Button
  114.    End
  115.    Begin TextBox Document 
  116.       Height          =   5415
  117.       HideSelection   =   0   'False
  118.       Left            =   0
  119.       MultiLine       =   -1  'True
  120.       ScrollBars      =   3  'Both
  121.       TabIndex        =   0
  122.       Top             =   0
  123.       Width           =   7455
  124.    End
  125.    Begin Menu mnuFile 
  126.       Caption         =   "&File"
  127.       Begin Menu mnuFNew 
  128.          Caption         =   "&New"
  129.       End
  130.       Begin Menu mnuFOpen 
  131.          Caption         =   "&Open..."
  132.       End
  133.       Begin Menu mnuFSave 
  134.          Caption         =   "&Save"
  135.       End
  136.       Begin Menu mnuFSaveAs 
  137.          Caption         =   "Save &As..."
  138.       End
  139.       Begin Menu mnuFSep 
  140.          Caption         =   "-"
  141.       End
  142.       Begin Menu mnuFExit 
  143.          Caption         =   "E&xit"
  144.       End
  145.    End
  146.    Begin Menu mnuEdit 
  147.       Caption         =   "&Edit"
  148.       Begin Menu mnuECut 
  149.          Caption         =   "Cu&t"
  150.          Shortcut        =   ^X
  151.       End
  152.       Begin Menu mnuECopy 
  153.          Caption         =   "&Copy"
  154.          Shortcut        =   ^C
  155.       End
  156.       Begin Menu mnuEPaste 
  157.          Caption         =   "&Paste"
  158.          Shortcut        =   ^V
  159.       End
  160.       Begin Menu mnuEDelete 
  161.          Caption         =   "De&lete"
  162.          Shortcut        =   {DEL}
  163.       End
  164.       Begin Menu mnuESep1 
  165.          Caption         =   "-"
  166.       End
  167.       Begin Menu mnuESelectAll 
  168.          Caption         =   "Select &All"
  169.       End
  170.       Begin Menu mnuETime 
  171.          Caption         =   "Time/&Date"
  172.       End
  173.    End
  174. Sub Centrepos_Click ()
  175.  popup1.MenuAlignment = 1
  176. End Sub
  177. Sub Command1_Click ()
  178.    popup1.Clear
  179.    popup1.MenuCaption = "&File"
  180. End Sub
  181. Sub Command2_Click ()
  182.   popup1.Clear
  183.   popup1.MenuCaption = "&Edit"
  184. End Sub
  185. Sub Command3_Click ()
  186.   popup1.Clear
  187.   popup1.AddItem "&File"
  188.   popup1.AddItem Chr$(9) & "1" & Chr$(9) & "&New"
  189.   popup1.AddItem Chr$(9) & "2" & Chr$(9) & "&Open"
  190.   popup1.AddItem Chr$(9) & "3" & Chr$(9) & "&Save"
  191.   popup1.AddItem Chr$(9) & "4" & Chr$(9) & "Save &As"
  192.   popup1.AddItem Chr$(9) & "-"
  193.   popup1.AddItem Chr$(9) & "5" & Chr$(9) & "E&xit"
  194.   popup1.AddItem "&Edit"
  195.   popup1.AddItem Chr$(9) & "6" & Chr$(9) & "Cu&t"
  196.   popup1.AddItem Chr$(9) & "7" & Chr$(9) & "&Copy"
  197.   popup1.AddItem Chr$(9) & "8" & Chr$(9) & "&Paste"
  198.   popup1.AddItem Chr$(9) & "9" & Chr$(9) & "De&lete"
  199.   popup1.AddItem Chr$(9) & "-"
  200.   popup1.AddItem Chr$(9) & "10" & Chr$(9) & "Select &All"
  201.   popup1.AddItem Chr$(9) & "11" & Chr$(9) & "Time/&Date"
  202. End Sub
  203. Sub Document_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  204. If Button = 2 Then      ' activate when user clicks the right mousebutton
  205.   popup1.Activate = 1
  206.   Select Case popup1.MenuReturnID
  207.     Case 1
  208.       mnuFNew_Click
  209.     Case 2
  210.       mnuFOpen_Click
  211.     Case 3
  212.       mnuFSave_Click
  213.     Case 4
  214.       mnuFSaveAs_Click
  215.     Case 5
  216.       mnuFExit_Click
  217.     Case 6
  218.       mnuECut_Click
  219.     Case 7
  220.       mnuECopy_Click
  221.     Case 8
  222.       mnuEPaste_Click
  223.     Case 9
  224.       mnuEDelete_Click
  225.     Case 10
  226.       mnuESelectAll_Click
  227.     Case 11
  228.       mnuETime_Click
  229.   End Select
  230. End If
  231. End Sub
  232. Sub EditCopyProc ()
  233.     ClipBoard.SetText Document.SelText
  234. End Sub
  235. Sub EditCutProc ()
  236.     ClipBoard.SetText Document.SelText
  237.     Document.SelText = ""
  238. End Sub
  239. Sub EditPasteProc ()
  240.     Document.SelText = ClipBoard.GetText()
  241. End Sub
  242. Sub Either_Click ()
  243.   popup1.TrackingButton = 1
  244. End Sub
  245. Sub FileNew ()
  246.     Document.Text = ""
  247.     Document.SetFocus
  248. End Sub
  249. Sub FOpenProc ()
  250.     Dim RetVal
  251.     On Error Resume Next
  252.     Dim OpenFileName As String
  253.     CMDialog1.Filename = "*.txt"
  254.     CMDialog1.Action = 1
  255.     If Err <> 32755 Then 'user pressed cancel
  256.     OpenFileName = CMDialog1.Filename
  257.     OpenFile (OpenFileName)
  258.     End If
  259. End Sub
  260. Sub Form_Load ()
  261.   Either.Value = True
  262.   Rightpos.Value = True
  263.   Document.Text = "Click the right mousebutton to see the popup menu"
  264.   popup1.MenuCaption = "&File"
  265. End Sub
  266. Sub Form_Resize ()
  267.     If windowstate <> 1 And ScaleHeight <> 0 Then
  268.     Document.Visible = False
  269.     Document.Height = ScaleHeight
  270.     Document.Width = ScaleWidth * .8
  271.     Command1.Left = Document.Width + 100
  272.     Command2.Left = Document.Width + 100
  273.     Command3.Left = Document.Width + 100
  274.     Frame1.Left = Document.Width + 100
  275.     Frame2.Left = Document.Width + 100
  276.     Document.Visible = True
  277.     End If
  278. End Sub
  279. Function GetFileName ()
  280.     On Error Resume Next
  281.     CMDialog1.Filename = "File1.Txt"
  282.     CMDialog1.Action = 2
  283.     If Err <> 32755 Then      'User cancelled dialog
  284.     GetFileName = CMDialog1.Filename
  285.     Else
  286.     GetFileName = "File1.Txt"
  287.     End If
  288. End Function
  289. Sub Left_Click ()
  290.   popup1.TrackingButton = 0
  291. End Sub
  292. Sub Leftpos_Click ()
  293.    popup1.MenuAlignment = 2
  294. End Sub
  295. Sub mnuECopy_Click ()
  296.     EditCopyProc
  297. End Sub
  298. Sub mnuECut_Click ()
  299.     EditCutProc
  300. End Sub
  301. Sub mnuEDelete_Click ()
  302.   ' If cursor is not at the end of the notepad.
  303.   If Document.SelStart <> Len(Document.Text) Then
  304.     ' If nothing is selected, extend selection by one.
  305.     If Document.SelLength = 0 Then
  306.       Document.SelLength = 1
  307.       ' If cursor is on a blank line, extend selection by two.
  308.       If Asc(Document.SelText) = 13 Then
  309.     Document.SelLength = 2
  310.       End If
  311.     End If
  312.     ' Delete selected text.
  313.     Document.SelText = ""
  314.   End If
  315. End Sub
  316. Sub mnuEPaste_Click ()
  317.     EditPasteProc
  318. End Sub
  319. Sub mnuESelectAll_Click ()
  320.     Document.SelStart = 0
  321.     Document.SelLength = Len(Document.Text)
  322. End Sub
  323. Sub mnuETime_Click ()
  324.     Dim TimeStr As String, DateStr As String
  325.     Document.SelText = Now
  326. End Sub
  327. Sub mnuFExit_Click ()
  328.     Unload Me
  329. End Sub
  330. Sub mnuFNew_Click ()
  331.     FileNew
  332. End Sub
  333. Sub mnuFOpen_Click ()
  334.     FOpenProc
  335. End Sub
  336. Sub mnuFSave_Click ()
  337.     SaveFileAs "File1.Txt"
  338. End Sub
  339. Sub mnuFSaveAs_Click ()
  340.     Dim SaveFileName As String
  341.     SaveFileName = GetFileName()
  342.     If SaveFileName <> "" Then
  343.        SaveFileAs (SaveFileName)
  344.     End If
  345. End Sub
  346. Sub OpenFile (Filename)
  347.     Dim NL, TextIn, GetLine
  348.     Dim fIndex As Integer
  349.     NL = Chr$(13) + Chr$(10)
  350.     On Error Resume Next
  351.     ' open the selected file
  352.     Open Filename For Input As #1
  353.     If Err Then
  354.     MsgBox "Can't open file: " + Filename
  355.     Exit Sub
  356.     End If
  357.     ' change mousepointer to an hourglass
  358.     screen.MousePointer = 11
  359.     ' change form's caption and display new text
  360.     Document.Tag = fIndex
  361.     Document.Text = Input$(LOF(1), 1)
  362.     Close #1
  363.     ' reset mouse pointer
  364.     screen.MousePointer = 0
  365. End Sub
  366. Sub Rightpos_Click ()
  367.   popup1.MenuAlignment = 0
  368. End Sub
  369. Sub SaveFileAs (Filename)
  370. On Error Resume Next
  371.     Dim Contents As String
  372.     ' open the file
  373.     Open Filename For Output As #1
  374.     ' put contents of the notepad into a variable
  375.     Contents = Document.Text
  376.     ' display hourglass
  377.     screen.MousePointer = 11
  378.     ' write variable contents to saved file
  379.     Print #1, Contents
  380.     Close #1
  381.     ' reset the mousepointer
  382.     screen.MousePointer = 0
  383.     ' set the Notepad's caption
  384.     If Err Then
  385.     MsgBox Error, 48, App.Title
  386.     End If
  387. End Sub
  388.