Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
RTF Notepad 1.0 - Notepad.frm

Notepad.frm

Caricato da:
Scarica il programma completo

  1. Dim DaCercare As String
  2. Dim GiaCercato As Integer 'contiene la posizione del puntatore all'interno del file aperto, per continuare la ricerca
  3. Dim Nomefile As String 'contiene il percorso completo del file in uso (usato per il salvataggio normale)
  4. Dim UndoRedo As Boolean
  5. Dim RTF As Boolean 'specifica se sto lavorando con un documento RFT o no
  6. Dim Modified As Boolean 'se è true allora il file in uso è stato modificato dall'utente
  7. Dim UndoReg() As String  'contiene l'intero testo prima e dopo ogni digitazione
  8. Dim I As Integer
  9. Dim K As Integer
  10.  
  11. '====================EVENTI FORM====================
  12. Private Sub Form_Load()
  13. Modified = False
  14. 'carico e nascondo la clipboard
  15. Load frmClipboard
  16. frmClipboard.Visible = False
  17. 'imposto i filtri per la cdl
  18. cd1.Filter = "Files di testo (.txt)|*.txt|File Rich Text Format (.rtf)|*.rtf|Tutti i files |*.*|"
  19. 'avvio un nuovo file
  20. Nuovo
  21. End Sub
  22.  
  23. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  24. If Modified = True Then
  25.     If MsgBox("Continuando perderai il lavoro svolto. Vuoi Uscire?", vbYesNo, "Uscire?") = vbNo Then Cancel = True: Exit Sub
  26. End If
  27. End
  28. End Sub
  29.  
  30. Private Sub Form_Resize()
  31. 'qui c'era un bug... :-D
  32. 'adesso ridimensiona la richtextbox al ridimensionamento del form
  33. 'correzione effettuata da LordTzeentch
  34. frmMain.ScaleMode = 1 ' questo fa si ke il form abbia lo stesso metodo di scale dei controlli
  35. On Error Resume Next
  36. txtTesto.Left = 0
  37. txtTesto.Height = (frmMain.Height - txtTesto.Top) - 760
  38. txtTesto.Width = frmMain.Width - 100
  39. End Sub
  40.  
  41. Private Sub mnuAbout_Click()
  42. MsgBox "Notepad 1.0" & Chr(13) & "Creato per Pierotofy.it" & _
  43. Chr(13) & "Da ..::[BeaR]::.." & Chr(13) & Chr(13) & "P.S." & Chr(13) & _
  44. "Se c'è qualche bug non esitate a contattarmi ;-)"
  45. End Sub
  46.  
  47. '====================TOOLBAR====================
  48. Private Sub tool1_ButtonClick(ByVal Button As ComctlLib.Button)
  49. Select Case Button.Key
  50.     Case "nuovo"
  51.         Nuovo
  52.     Case "apri"
  53.         Apri
  54.     Case "salva"
  55.         Salva False
  56.     Case "print"
  57.         Printer.Print txtTesto.Text
  58.         Printer.EndDoc
  59.     Case "cut"
  60.         Taglia
  61.     Case "copy"
  62.         Copia
  63.     Case "paste"
  64.         Incolla
  65.     Case "undo"
  66.         mnuUndo_click
  67.     Case "redo"
  68.         mnuRedo_click
  69.     Case "textColor"
  70.         textColor
  71.         RFT = True
  72. End Select
  73. End Sub
  74. '$$$$$$$$$$$$$$$$$$$$   MENU    $$$$$$$$$$$$$$$$$$$$
  75.  
  76. '********************FILE********************
  77. Private Sub mnuEsci_Click()
  78. Esci
  79. End Sub
  80.  
  81. Private Sub mnuNew_Click()
  82. Nuovo
  83. End Sub
  84.  
  85. Private Sub mnuOpen_Click()
  86. Apri
  87. End Sub
  88.  
  89. Private Sub mnuSave_Click()
  90. Salva False
  91. End Sub
  92.  
  93. Private Sub mnuSaveAs_Click()
  94. Salva True
  95. End Sub
  96.  
  97. Private Sub mnuPrint_Click()
  98. Printer.Print txtTesto.Text
  99. Printer.EndDoc
  100. End Sub
  101.  
  102. '********************MODIFICA********************
  103. Private Sub mnuCopy_Click()
  104. Copia
  105. mnuClipboard.Enabled = True
  106. End Sub
  107.  
  108. Private Sub mnuPaste_Click()
  109. Incolla
  110. End Sub
  111.  
  112. Private Sub mnuCut_Click()
  113. Taglia
  114. End Sub
  115.  
  116. Private Sub mnuUndo_click()
  117. 'abilito il pulsante redo
  118. If I > 0 Then
  119.     UndoRedo = True
  120.     I = I - 1
  121.     mnuRedo.Enabled = True
  122.     tool1.Buttons(13).MixedState = False
  123.     txtTesto.Text = UndoReg(I) 'annulla la modifica fatta
  124.     Else
  125.     tool1.Buttons(12).MixedState = True
  126.     mnuUndo.Enabled = False
  127. End If
  128. End Sub
  129.  
  130. Private Sub mnuRedo_click()
  131. If I < 50 Then
  132.     I = I + 1
  133.     UndoRedo = True
  134.     txtTesto.Text = UndoReg(I)
  135. Else 'se non si possono + ripristinare modifiche, disabilito il pulsante redo
  136.     mnuRedo.Enabled = False
  137.     tool1.Buttons(13).MixedState = True
  138. End If
  139. End Sub
  140.  
  141. Private Sub mnuSelectAll_Click()
  142. txtTesto.SelStart = 0
  143. txtTesto.SelLength = Len(txtTesto)
  144. End Sub
  145.  
  146. Private Sub mnuFind_Click()
  147. Find False
  148. End Sub
  149.  
  150. Private Sub mnuFindAgain_click()
  151. Find True
  152. End Sub
  153.  
  154. Private Sub mnuCanc_Click()
  155. txtTesto.SelText = ""
  156. End Sub
  157.  
  158. '********************VISUALIZZA********************
  159. Private Sub mnuclipboard_click()
  160. frmClipboard.Visible = True
  161. End Sub
  162.  
  163. '********************HELP********************
  164.  
  165.  
  166. '====================SUB====================
  167.  
  168. Private Sub Nuovo()
  169. If Modified = True Then 'se il file è stato modificato chiede conferma prima di proseguire
  170.     If MsgBox("Attenzione! Nopn hai salvato." & Chr(13) & "Continuando perderai il lavoro svolto. Vuoi creare un Nuovo file?", vbYesNo, "Nuovo...") = vbNo Then Exit Sub
  171. End If
  172.  
  173. txtTesto.Text = ""
  174. Nomefile = ""
  175. Modified = False
  176. I = 0 'azzera il numero di modifiche annullabili
  177. ReDim UndoReg(0 To 50) 'svuota la cache delle modifiche annullabili
  178. 'blocco i pulsanti undo e redo
  179. tool1.Buttons(12).MixedState = True
  180. tool1.Buttons(13).MixedState = True
  181. mnuRedo.Enabled = False
  182. mnuUndo.Enabled = False
  183. End Sub
  184.  
  185. Private Sub Apri()
  186. Dim Percorso As String
  187. Dim Testo As String
  188. If Modified = True Then 'se il file è stato modificato chiede conferma prima di proseguire
  189.     If MsgBox("Attenzione! Non hai salvato." & Chr(13) & "Continuando perderai il lavoro svolto. Vuoi aprire un Nuovo file?", vbYesNo, "Apri...") = vbNo Then Exit Sub
  190. End If
  191.  
  192. cd1.DialogTitle = "Apri File..."
  193. cd1.ShowOpen
  194. Percorso = cd1.FileName
  195. If Percorso = "" Then Exit Sub
  196. txtTesto.Text = ""
  197. txtTesto.FileName = Percorso
  198.  
  199. If Right(Percorso, 4) = ".rtf" Then
  200.     RFT = True
  201. Else
  202.     RTF = False
  203. End If
  204.  
  205. Nomefile = Percorso
  206. Modified = False
  207. End Sub
  208.  
  209. Private Sub Salva(ConNome As Boolean)
  210. 'salva il file
  211. Dim Percorso As String
  212. If ConNome = True Then
  213.     cd1.DialogTitle = "Salva File..."
  214.     'in un nuovo file
  215.     cd1.ShowSave
  216.     Percorso = cd1.FileName
  217.     If Percorso = "" Then Exit Sub
  218. Else
  219.     'nello stesso
  220.     Percorso = Nomefile
  221.     'se è il primo file aperto...
  222.     If Percorso = "" Then
  223.         'richiama il salva con nome
  224.         Salva True
  225.         Exit Sub
  226.     End If
  227. End If
  228.  
  229. Percorso = (Left(Percorso, Len(Percorso) - 4)) + (LCase(Right(Percorso, 4)))
  230.    
  231. If Right(Percorso, 4) = ".rtf" Then
  232.     txtTesto.SaveFile (Percorso)
  233. Else
  234.     If RTF Then
  235.         If MsgBox("Salvando il file in formato testo si perderanno le modifiche della formattazione." & Chr(13) & "Salvare in formato RTF?", vbYesNo + vbCritical, "Attenzione!") = vbYes Then
  236.             Percorso = Left(Percorso, Len(Percorso - 3)) & ".rtf" 'modifico l'estensione
  237.             txtTesto.SaveFile (Percorso)
  238.         End If
  239.     Else
  240.          Open Percorso For Output As #1
  241.         Print #1, txtTesto.Text
  242.         Close #1
  243.     End If
  244. End If
  245. Nomefile = Percorso
  246. Modified = False
  247. End Sub
  248.  
  249. Private Sub Copia()
  250. If txtTesto.SelText <> "" Then
  251.     frmClipboard.lstApp.AddItem txtTesto.SelText
  252. End If
  253. Clipboard.Clear
  254. Clipboard.SetText txtTesto.SelText
  255. End Sub
  256.  
  257. Private Sub Incolla()
  258. Modified = True
  259. txtTesto.SelText = Clipboard.GetText
  260. End Sub
  261.  
  262. Private Sub Taglia()
  263. Modified = True
  264. Clipboard.Clear
  265. Clipboard.SetText txtTesto.SelText
  266. txtTesto.SelText = ""
  267. End Sub
  268.  
  269. Private Sub textColor()
  270. cd1.ShowColor
  271. txtTesto.SelColor = cd1.Color
  272. Modified = True
  273. End Sub
  274.  
  275. Private Sub Esci()
  276. If MsgBox("Vuoi uscire?", vbYesNo, "Uscita") = vbYes Then
  277.     End
  278. Else
  279.     Exit Sub
  280. End If
  281. End Sub
  282.  
  283. Private Sub txtTesto_Change()
  284. If UndoRedo = True Then UndoRedo = False: Exit Sub 'se l'evento è stato generato dalla sub undo, allora esco da qst sub
  285. Modified = True
  286. tool1.Buttons(12).MixedState = False 'abilita l'undo
  287. mnuUndo.Enabled = True
  288. If I < 50 Then
  289.     I = I + 1
  290.     UndoReg(I) = txtTesto.Text 'memorizza la modifica fatta
  291. Else
  292.     Dim K As Integer
  293.     Dim Temp As String
  294.     For K = 1 To I - 1 'sposta indietro di 1 posizione tutti i record
  295.         UndoReg(K) = UndoReg(K + 1)
  296.     Next K
  297.     UndoReg(I) = txtTesto.Text 'memorizza la modifica fatta
  298. End If
  299. End Sub
  300.  
  301. Private Sub txtTesto_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  302. If Button = 2 Then 'se è stato clikkato il destro
  303.     PopupMenu mnuEdit 'visualizza il menu modifica
  304. End If
  305. End Sub