Guest User

Untitled

a guest
Jun 8th, 2011
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 75.92 KB | None | 0 0
  1. Imports DevComponents.DotNetBar
  2. Imports DevComponents.DotNetBar.Controls
  3. Imports NHunspell
  4. Imports System.Net
  5. Imports System.Windows.Forms
  6. Imports System.Text.RegularExpressions
  7. Imports System.ComponentModel
  8. Imports System.Drawing
  9. Imports System.Text
  10. Imports System.Runtime.InteropServices
  11. Public Class frmMain
  12. Inherits DevComponents.DotNetBar.Office2007Form
  13.  
  14. #Region "Declarations"
  15. Dim notes As Integer = 0
  16. Private Declare Function LockWindowUpdate Lib "user32" (ByVal hWnd As Integer) As Integer
  17.  
  18. Dim lineNum As Int32
  19. Public Word As String
  20. Public contentRectangle As Rectangle
  21.  
  22. <DllImport("USER32.dll")> _
  23. Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Int32
  24. End Function
  25. Private Const WM_USER As Integer = &H400
  26. Private Const EM_FORMATRANGE As Integer = WM_USER + 57
  27. <StructLayout(LayoutKind.Sequential)> _
  28. Private Structure RECT
  29. Public Left As Integer
  30. Public Top As Integer
  31. Public Right As Integer
  32. Public Bottom As Integer
  33. End Structure
  34. <StructLayout(LayoutKind.Sequential)> _
  35. Private Structure CHARRANGE
  36. Public cpMin As Integer
  37. Public cpMax As Integer
  38. End Structure
  39. <StructLayout(LayoutKind.Sequential)> _
  40. Private Structure FORMATRANGE
  41. Public hdc As IntPtr
  42. Public hdcTarget As IntPtr
  43. Public rc As RECT
  44. Public rcPage As RECT
  45. Public chrg As CHARRANGE
  46. End Structure
  47. Private Const inch As Double = 14.4
  48. Public ScintillaMode As Boolean
  49. #End Region
  50.  
  51. #Region "Handle Form Events"
  52. #Region "Handle Various hotkeys"
  53. Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  54. If My.Computer.Keyboard.CtrlKeyDown Then
  55. Try
  56. 'These are basically all the hotkey for 1-9.
  57. If e.KeyCode = Keys.D1 Then
  58. tcMain.SelectedTabIndex = 0
  59. ElseIf e.KeyCode = Keys.D2 Then
  60. tcMain.SelectedTabIndex = 1
  61. ElseIf e.KeyCode = Keys.D3 Then
  62. tcMain.SelectedTabIndex = 2
  63. ElseIf e.KeyCode = Keys.D4 Then
  64. tcMain.SelectedTabIndex = 3
  65. ElseIf e.KeyCode = Keys.D5 Then
  66. tcMain.SelectedTabIndex = 4
  67. ElseIf e.KeyCode = Keys.D6 Then
  68. tcMain.SelectedTabIndex = 5
  69. ElseIf e.KeyCode = Keys.D7 Then
  70. tcMain.SelectedTabIndex = 6
  71. ElseIf e.KeyCode = Keys.D8 Then
  72. tcMain.SelectedTabIndex = 7
  73. ElseIf e.KeyCode = Keys.D9 Then
  74. tcMain.SelectedTabIndex = tcMain.Tabs.Count - 1
  75. 'CTRL + PageDown
  76. ElseIf e.KeyCode = Keys.PageDown Then
  77. tcMain.SelectedTabIndex -= 1
  78. ElseIf e.KeyCode = Keys.PageUp Then
  79. tcMain.SelectedTabIndex += 1
  80. End If
  81. Catch
  82. End Try
  83. End If
  84. 'CTRL + Plus
  85. If e.KeyCode = 187 Then
  86. If My.Computer.Keyboard.CtrlKeyDown = True Then btnZoomin.RaiseClick()
  87. End If
  88. 'CTRL + Minus
  89. If e.KeyCode = 189 Then
  90. If My.Computer.Keyboard.CtrlKeyDown = True Then btnZoomOut.RaiseClick()
  91. End If
  92. 'CTRL + Zero
  93. If e.KeyCode = 48 Then
  94. If My.Computer.Keyboard.CtrlKeyDown = True Then btnResetzoom.RaiseClick()
  95. End If
  96. 'Handle CTRL + Shift + > (font larger)
  97. If e.KeyCode = 190 Then
  98. If My.Computer.Keyboard.CtrlKeyDown = True AndAlso My.Computer.Keyboard.ShiftKeyDown = True Then
  99. Try
  100. e.SuppressKeyPress = True
  101. cbxTextSize.SelectedIndex += 1
  102. Catch
  103. End Try
  104. End If
  105. 'Handle CTRL + Shift + < (font smaller)
  106. ElseIf e.KeyCode = 188 Then
  107. If My.Computer.Keyboard.CtrlKeyDown = True AndAlso My.Computer.Keyboard.ShiftKeyDown = True Then
  108. Try
  109. e.SuppressKeyPress = True
  110. cbxTextSize.SelectedIndex -= 1
  111. Catch
  112. End Try
  113. End If
  114. End If
  115. End Sub
  116. #End Region
  117.  
  118. Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  119. 'Make sure TopMost is set to false, as SaveFileDialog won't show otherwise.
  120. Me.TopMost = False
  121.  
  122. 'For Each Tab
  123. For Each tb In tcMain.Tabs
  124. 'If it's a normal RichTextBox
  125. If TypeOf (tb.AttachedControl.Controls.Item(0)) Is RTB Then
  126. 'If the document has been modified since last save
  127. If CType(tb.AttachedControl.Controls.Item(0), RTB).DocumentModified = True AndAlso CType(tb.AttachedControl.Controls.Item(0), RTB).Text <> Nothing Then
  128. 'Show the save prompt
  129. Dim dr As DialogResult = DevComponents.DotNetBar.MessageBoxEx.Show("The document: " & tb.Text & " has not been saved. Do you want to save it before closing?", "Question", MessageBoxButtons.YesNoCancel)
  130. 'If yes then
  131. If dr = Windows.Forms.DialogResult.Yes Then
  132. 'If we've allready saved
  133. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath <> Nothing Then
  134. Dim sp As String = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath
  135. Dim strExt = System.IO.Path.GetExtension(sp)
  136. strExt = strExt.ToUpper()
  137.  
  138. If strExt = ".RTF" Then
  139. 'If we last saved as a rtf then save as a rtf
  140. CType(tb.AttachedControl.Controls.Item(0), RTB).SaveDocument(sp)
  141. Else
  142. 'Otherwise save as txt
  143. Dim saved As New IO.StreamWriter(sp)
  144. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  145. saved.Flush()
  146. saved.Close()
  147. End If
  148. Else
  149. 'We haven't allready saved, so show the save dialog and perform the same procedure.
  150. Dim sfd As New SaveFileDialog
  151. sfd.Title = "Select a file to save as..."
  152. sfd.Filter = "Rich Text Format (*.rtf)|*.rtf|Text File (*.txt)|*.txt|All Files|"
  153. If sfd.ShowDialog = DialogResult.OK Then
  154. Dim strExt = System.IO.Path.GetExtension(sfd.FileName)
  155. strExt = strExt.ToUpper()
  156. If strExt = ".RTF" Then
  157. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SaveDocument(sfd.FileName)
  158. Else
  159. Dim saved As New IO.StreamWriter(sfd.FileName)
  160. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  161. saved.Flush()
  162. saved.Close()
  163. End If
  164. Else
  165. 'User pressed cancel on the SaveFileDialog... so cancel close
  166. e.Cancel = True
  167. Exit Sub
  168. End If
  169. End If
  170. ElseIf dr = Windows.Forms.DialogResult.Cancel Then
  171. 'User pressed cancel... so cancel close
  172. e.Cancel = True
  173. Exit Sub
  174. End If
  175. End If
  176. Else
  177. 'Perform exactly the same procedure for the Scintilla based textbox, but slightly different code.
  178. If CType(tb.AttachedControl.Controls.Item(0), ScintillaEX).DocumentModified = True AndAlso CType(tb.AttachedControl.Controls.Item(0), ScintillaEX).Text <> Nothing Then
  179. Dim dr As DialogResult = DevComponents.DotNetBar.MessageBoxEx.Show("The document: " & tb.Text & " has not been saved. Do you want to save it before closing?", "Question", MessageBoxButtons.YesNoCancel)
  180. If dr = Windows.Forms.DialogResult.Yes Then
  181. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).SavePath <> Nothing Then
  182. Dim sp As String = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).SavePath
  183. Dim strExt = System.IO.Path.GetExtension(sp)
  184. strExt = strExt.ToUpper()
  185. Dim saved As New IO.StreamWriter(sp)
  186. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  187. saved.Flush()
  188. saved.Close()
  189. Else
  190. Dim sfd As New SaveFileDialog
  191. sfd.Title = "Select a file to save as..."
  192. sfd.Filter = "Text File (*.txt)|*.txt|All Files|"
  193. If sfd.ShowDialog = DialogResult.OK Then
  194. Dim strExt = System.IO.Path.GetExtension(sfd.FileName)
  195. strExt = strExt.ToUpper()
  196. Dim saved As New IO.StreamWriter(sfd.FileName)
  197. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Text)
  198. saved.Flush()
  199. saved.Close()
  200. Else
  201. e.Cancel = True
  202. Exit Sub
  203. End If
  204. End If
  205.  
  206. ElseIf dr = Windows.Forms.DialogResult.Cancel Then
  207. e.Cancel = True
  208. Exit Sub
  209. End If
  210. End If
  211. End If
  212. Next
  213. End Sub
  214.  
  215. Private Sub tmrDelayedLoader_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrDelayedLoader.Tick
  216. 'Load fonts into combobox...
  217. For Each itm In System.Drawing.FontFamily.Families
  218. Dim citm As New DevComponents.Editors.ComboItem
  219. If My.Settings.LoadFontStyles = True Then
  220. citm.FontName = itm.Name
  221. End If
  222. citm.Text = itm.Name
  223. cbxFonts.Items.Add(citm)
  224. Next
  225. tmrDelayedLoader.Stop()
  226. If ScintillaMode = False Then
  227. 'Load fonts assuming we're not in the scintilla textbox
  228. For Each itm As DevComponents.Editors.ComboItem In cbxFonts.Items
  229. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionFont.Name = itm.Text Then
  230. cbxFonts.SelectedItem = itm
  231. End If
  232. Next
  233. Else
  234. 'The user is damn fast...
  235. End If
  236. End Sub
  237.  
  238. Private Sub frmMain_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
  239. 'Make sure the main bar's width is correct (bar has no anchor property for some retarded reason I have yet to find out...
  240. barMain.Width = Me.Width
  241. End Sub
  242.  
  243. Private Sub frmMain_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd
  244. 'Same as previous
  245. barMain.Size = New Size(Me.Width, barMain.Height)
  246. End Sub
  247.  
  248. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  249.  
  250. 'Check whether to enable Windows Aero
  251. Me.EnableGlass = My.Settings.EnableAeroGlass
  252. 'Create a new document (normal)
  253. btnNew.RaiseClick()
  254.  
  255. 'Load recent items
  256. btnRecent.SubItems.Clear()
  257. btnRecent.SubItems.Add(btnClearRecent)
  258. For Each itm In My.Settings.RecentDocuments
  259. If itm <> "None..." Then
  260. Dim bitm As New bitm_recent
  261. bitm.Text = itm
  262. btnRecent.SubItems.Add(bitm)
  263. End If
  264. Next
  265.  
  266. 'Load the style for the program & the tabcontrol
  267. styleMain.ManagerStyle = My.Settings.StyleName
  268. styleMain.ManagerColorTint = My.Settings.StyleColorTint
  269. For Each itm In My.Settings.TabControlSettings
  270. If itm.ToLower.Contains("default") = False Then
  271. Dim value As String = itm.Substring(itm.LastIndexOf(" - ")).Replace(" - ", "")
  272. If itm.ToLower.StartsWith("main style for tabcontrol") Then
  273. If value = "square" Then
  274. tcMain.Style = eTabStripStyle.Office2007Document
  275. ElseIf value = "rounded" Then
  276. tcMain.Style = eTabStripStyle.Office2007Document
  277. ElseIf value = "plain" Then
  278. tcMain.Style = eTabStripStyle.SimulatedTheme
  279. End If
  280. ElseIf itm.ToLower.StartsWith("tab bar color 1") Then
  281. tcMain.ColorScheme.TabBackground = Color.FromName(value)
  282. ElseIf itm.ToLower.StartsWith("tab bar color 2") Then
  283. tcMain.ColorScheme.TabBackground2 = Color.FromName(value)
  284. ElseIf itm.ToLower.StartsWith("tab bar color gradient") Then
  285. tcMain.ColorScheme.TabBackgroundGradientAngle = value
  286. ElseIf itm.ToLower.StartsWith("tab item background 1") Then
  287. tcMain.ColorScheme.TabItemBackground = Color.FromName(value)
  288. ElseIf itm.ToLower.StartsWith("tab item background 2") Then
  289. tcMain.ColorScheme.TabItemBackground2 = Color.FromName(value)
  290. ElseIf itm.ToLower.StartsWith("tab item background gradient") Then
  291. tcMain.ColorScheme.TabItemBackgroundGradientAngle = value
  292. ElseIf itm.ToLower.StartsWith("selected border color") Then
  293. tcMain.ColorScheme.TabItemSelectedBorder = Color.FromName(value)
  294. ElseIf itm.ToLower.StartsWith("selected tab item background 1") Then
  295. tcMain.ColorScheme.TabItemSelectedBackground = Color.FromName(value)
  296. ElseIf itm.ToLower.StartsWith("selected tab item background 2") Then
  297. tcMain.ColorScheme.TabItemSelectedBackground2 = Color.FromName(value)
  298. ElseIf itm.ToLower.StartsWith("selected tab item background gradient") Then
  299. tcMain.ColorScheme.TabItemSelectedBackgroundGradientAngle = value
  300. ElseIf itm.ToLower.StartsWith("tab orientation") Then
  301. If value = "top" Then
  302. tcMain.TabAlignment = eTabStripAlignment.Top
  303. ElseIf value = "bottom" Then
  304. tcMain.TabAlignment = eTabStripAlignment.Bottom
  305. ElseIf value = "left" Then
  306. tcMain.TabAlignment = eTabStripAlignment.Left
  307. ElseIf value = "right" Then
  308. tcMain.TabAlignment = eTabStripAlignment.Right
  309. End If
  310. Else
  311. '????
  312. 'Proffit
  313. End If
  314. End If
  315. Next
  316.  
  317. End Sub
  318. #End Region
  319. #Region "File Menu"
  320. Private Sub btnCloseDocument_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCloseDocument.Click
  321. 'If the tab count is 1 then cancel...
  322. If tcMain.Tabs.Count = 1 Then
  323. Exit Sub
  324. End If
  325. 'Perform the same prcedure of
  326. If TypeOf (tcMain.SelectedTab.AttachedControl.Controls.Item(0)) Is RTB Then
  327. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).DocumentModified = True AndAlso CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text <> Nothing Then
  328. Dim dr As DialogResult = DevComponents.DotNetBar.MessageBoxEx.Show("The selected document has not been saved. Do you want to save it before closing?", "Question", MessageBoxButtons.YesNoCancel)
  329. If dr = Windows.Forms.DialogResult.Yes Then
  330. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath <> Nothing Then
  331. Dim sp As String = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath
  332. Dim strExt = System.IO.Path.GetExtension(sp)
  333. strExt = strExt.ToUpper()
  334. If strExt = ".RTF" Then
  335. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SaveDocument(sp)
  336. Else
  337. Dim saved As New IO.StreamWriter(sp)
  338. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  339. saved.Flush()
  340. saved.Close()
  341. End If
  342. Else
  343. Dim sfd As New SaveFileDialog
  344. sfd.Title = "Select a file to save as..."
  345. sfd.Filter = "Rich Text Format (*.rtf)|*.rtf|Text File (*.txt)|*.txt|All Files|"
  346. If sfd.ShowDialog = DialogResult.OK Then
  347. Dim strExt = System.IO.Path.GetExtension(sfd.FileName)
  348. strExt = strExt.ToUpper()
  349. If strExt = ".RTF" Then
  350. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SaveDocument(sfd.FileName)
  351. Else
  352. Dim saved As New IO.StreamWriter(sfd.FileName)
  353. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  354. saved.Flush()
  355. saved.Close()
  356. End If
  357. Else
  358. Exit Sub
  359. End If
  360. End If
  361. ElseIf dr = Windows.Forms.DialogResult.Cancel Then
  362. Exit Sub
  363. End If
  364. End If
  365. Else
  366. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).DocumentModified = True AndAlso CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Text <> Nothing Then
  367. Dim dr As DialogResult = DevComponents.DotNetBar.MessageBoxEx.Show("The selected document has not been saved. Do you want to save it before closing?", "Question", MessageBoxButtons.YesNoCancel)
  368. If dr = Windows.Forms.DialogResult.Yes Then
  369. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).SavePath <> Nothing Then
  370. Dim sp As String = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).SavePath
  371. Dim strExt = System.IO.Path.GetExtension(sp)
  372. strExt = strExt.ToUpper()
  373. Dim saved As New IO.StreamWriter(sp)
  374. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  375. saved.Flush()
  376. saved.Close()
  377. Else
  378. Dim sfd As New SaveFileDialog
  379. sfd.Title = "Select a file to save as..."
  380. sfd.Filter = "Text File (*.txt)|*.txt|All Files|"
  381. If sfd.ShowDialog = DialogResult.OK Then
  382. Dim strExt = System.IO.Path.GetExtension(sfd.FileName)
  383. strExt = strExt.ToUpper()
  384. Dim saved As New IO.StreamWriter(sfd.FileName)
  385. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Text)
  386. saved.Flush()
  387. saved.Close()
  388. End If
  389. End If
  390. ElseIf dr = Windows.Forms.DialogResult.Cancel Then
  391. Exit Sub
  392. End If
  393. End If
  394. End If
  395. tcMain.Tabs.Remove(tcMain.SelectedTab)
  396. End Sub
  397. Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  398. Me.Close()
  399. End Sub
  400.  
  401. Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click
  402. frmAbout.ShowDialog()
  403. End Sub
  404.  
  405. Dim asked As Boolean
  406. Private Sub ButtonItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
  407. If asked = False Then
  408. If notes > 50 Then
  409. If DevComponents.DotNetBar.MessageBoxEx.Show("Stuff could get laggy if you have more than 50 notes. Continue? (you'll only need to answer once)", "Question", MessageBoxButtons.YesNo) <> DialogResult.Yes Then
  410. Exit Sub
  411. Else
  412. asked = True
  413. End If
  414. End If
  415. End If
  416. notes += 1
  417.  
  418. Dim tb As DevComponents.DotNetBar.TabItem = tcMain.CreateTab("")
  419. tb.Text = "New note - " & notes.ToString
  420. Dim myrtb As New RTB
  421. myrtb.Dock = DockStyle.Fill
  422. myrtb.Font = New Font(myrtb.Font.Name, 12)
  423. myrtb.DocumentModified = False
  424. tb.AttachedControl.Controls.Add(myrtb)
  425. tcMain.SelectedTab = tb
  426. myrtb.Select()
  427. End Sub
  428.  
  429. Private Sub ButtonItem4_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearRecent.Click
  430. My.Settings.RecentDocuments.Clear()
  431. End Sub
  432.  
  433. Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
  434. Dim ofd As New OpenFileDialog
  435. ofd.Filter = "Rich Text Format (*.rtf)|*.rtf|Text File (*.txt)|*.txt|All Files|"
  436. ofd.Title = "Select file to open..."
  437. If ofd.ShowDialog() = DialogResult.OK Then
  438. Dim tb As DevComponents.DotNetBar.TabItem = tcMain.CreateTab("")
  439. tb.Text = ofd.SafeFileName
  440. Dim myrtb As New RTB
  441. myrtb.Dock = DockStyle.Fill
  442. myrtb.Font = New Font(myrtb.Font.Name, 12)
  443. Try
  444. myrtb.LoadFile(ofd.FileName)
  445. Catch
  446. Dim loadf As New IO.StreamReader(ofd.FileName)
  447. myrtb.Text = loadf.ReadToEnd
  448. loadf.Close()
  449. End Try
  450.  
  451. myrtb.SavePath = ofd.FileName
  452. myrtb.DocumentModified = False
  453. tb.AttachedControl.Controls.Add(myrtb)
  454. tcMain.SelectedTab = tb
  455. myrtb.Select()
  456. End If
  457.  
  458. End Sub
  459.  
  460. Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  461. If TypeOf (tcMain.SelectedTab.AttachedControl.Controls.Item(0)) Is RTB Then
  462. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath <> Nothing Then
  463. Dim strExt = System.IO.Path.GetExtension(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath)
  464. strExt = strExt.ToUpper()
  465. If strExt = ".RTF" Then
  466. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SaveDocument(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath)
  467. Else
  468. Dim saved As New IO.StreamWriter(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath)
  469. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  470. saved.Flush()
  471. saved.Close()
  472. End If
  473. Dim found As Boolean = False
  474. For Each itm In My.Settings.RecentDocuments
  475. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath = itm Then
  476. found = True
  477. End If
  478. Next
  479. If found = False Then
  480. My.Settings.RecentDocuments.Add(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath)
  481. My.Settings.Save()
  482. End If
  483. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).DocumentModified = False
  484. Else
  485. Dim sfd As New SaveFileDialog
  486. sfd.Title = "Select a file to save as..."
  487. sfd.Filter = "Rich Text Format (*.rtf)|*.rtf|Text File (*.txt)|*.txt|All Files|"
  488. If sfd.ShowDialog = DialogResult.OK Then
  489. Dim strExt = System.IO.Path.GetExtension(sfd.FileName)
  490. strExt = strExt.ToUpper()
  491. If strExt = ".RTF" Then
  492. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SaveDocument(sfd.FileName)
  493. Else
  494. Dim saved As New IO.StreamWriter(sfd.FileName)
  495. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  496. saved.Flush()
  497. saved.Close()
  498. End If
  499. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).DocumentModified = False
  500. Dim found As Boolean = False
  501. For Each itm In My.Settings.RecentDocuments
  502. If sfd.FileName = itm Then
  503. found = True
  504. End If
  505. Next
  506. If found = False Then
  507. My.Settings.RecentDocuments.Add(sfd.FileName)
  508. My.Settings.Save()
  509. End If
  510. End If
  511. End If
  512. Else
  513. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).SavePath <> Nothing Then
  514. Dim saved As New IO.StreamWriter(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).SavePath)
  515. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Text)
  516. saved.Flush()
  517. saved.Close()
  518. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).DocumentModified = False
  519. Dim found As Boolean = False
  520. For Each itm In My.Settings.RecentDocuments
  521. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).SavePath = itm Then
  522. found = True
  523. End If
  524. Next
  525. If found = False Then
  526. My.Settings.RecentDocuments.Add(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).SavePath)
  527. My.Settings.Save()
  528. End If
  529. Else
  530. Dim sfd As New SaveFileDialog
  531. sfd.Title = "Select a file to save as..."
  532. sfd.Filter = "Text File (*.txt)|*.txt|All Files|"
  533. If sfd.ShowDialog = DialogResult.OK Then
  534. Dim strExt = System.IO.Path.GetExtension(sfd.FileName)
  535. strExt = strExt.ToUpper()
  536. Dim saved As New IO.StreamWriter(sfd.FileName)
  537. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Text)
  538. saved.Flush()
  539. saved.Close()
  540. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).DocumentModified = False
  541. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).SavePath = sfd.FileName
  542. Dim found As Boolean = False
  543. For Each itm In My.Settings.RecentDocuments
  544. If sfd.FileName = itm Then
  545. found = True
  546. End If
  547. Next
  548. If found = False Then
  549. My.Settings.RecentDocuments.Add(sfd.FileName)
  550. My.Settings.Save()
  551. End If
  552. End If
  553. End If
  554. End If
  555. btnRecent.SubItems.Clear()
  556. btnRecent.SubItems.Add(btnClearRecent)
  557. For Each itm In My.Settings.RecentDocuments
  558. If itm <> "None..." Then
  559. Dim bitm As New bitm_recent
  560. bitm.Text = itm
  561. btnRecent.SubItems.Add(bitm)
  562. End If
  563. Next
  564. End Sub
  565. Private Sub btnSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveAs.Click
  566. If TypeOf (tcMain.SelectedTab.AttachedControl.Controls.Item(0)) Is RTB Then
  567. Dim sfd As New SaveFileDialog
  568. sfd.Title = "Select a file to save as..."
  569. sfd.Filter = "Rich Text Format (*.rtf)|*.rtf|Text File (*.txt)|*.txt|All Files|"
  570. If sfd.ShowDialog = DialogResult.OK Then
  571. Dim strExt = System.IO.Path.GetExtension(sfd.FileName)
  572. strExt = strExt.ToUpper()
  573. If strExt = ".RTF" Then
  574. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SaveDocument(sfd.FileName)
  575. Else
  576. Dim saved As New IO.StreamWriter(sfd.FileName)
  577. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  578. saved.Flush()
  579. saved.Close()
  580. End If
  581. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).DocumentModified = False
  582. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath = sfd.FileName
  583. Dim found As Boolean = False
  584. For Each itm In My.Settings.RecentDocuments
  585. If sfd.FileName = itm Then
  586. found = True
  587. End If
  588. Next
  589. If found = False Then
  590. My.Settings.RecentDocuments.Add(sfd.FileName)
  591. My.Settings.Save()
  592. End If
  593. End If
  594. btnRecent.SubItems.Clear()
  595. btnRecent.SubItems.Add(btnClearRecent)
  596.  
  597. For Each itm In My.Settings.RecentDocuments
  598. If itm <> "None..." Then
  599. Dim bitm As New bitm_recent
  600. bitm.Text = itm
  601. btnRecent.SubItems.Add(bitm)
  602. End If
  603. Next
  604. Else
  605.  
  606. Dim sfd As New SaveFileDialog
  607. sfd.Title = "Select a file to save as..."
  608. sfd.Filter = "Text File (*.txt)|*.txt|All Files|"
  609. If sfd.ShowDialog = DialogResult.OK Then
  610. Dim strExt = System.IO.Path.GetExtension(sfd.FileName)
  611. strExt = strExt.ToUpper()
  612. Dim saved As New IO.StreamWriter(sfd.FileName)
  613. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Text)
  614. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).DocumentModified = False
  615. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).SavePath = sfd.FileName
  616. saved.Flush()
  617. saved.Close()
  618. Dim found As Boolean = False
  619. For Each itm In My.Settings.RecentDocuments
  620. If sfd.FileName = itm Then
  621. found = True
  622. End If
  623. Next
  624. If found = False Then
  625. My.Settings.RecentDocuments.Add(sfd.FileName)
  626. My.Settings.Save()
  627. End If
  628. End If
  629. btnRecent.SubItems.Clear()
  630. btnRecent.SubItems.Add(btnClearRecent)
  631.  
  632. For Each itm In My.Settings.RecentDocuments
  633. If itm <> "None..." Then
  634. Dim bitm As New bitm_recent
  635. bitm.Text = itm
  636. btnRecent.SubItems.Add(bitm)
  637. End If
  638. Next
  639. End If
  640.  
  641. End Sub
  642. #End Region
  643. #Region "Edit Menu"
  644.  
  645. Private Sub btnGoTo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoTo.Click
  646. If ScintillaMode Then
  647. Dim ib As String = Microsoft.VisualBasic.Interaction.InputBox("Please enter line number...", "Enter Line Number...", 0)
  648. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).GoTo.Line(ib)
  649. Else
  650. Try
  651. Dim ib As String = Microsoft.VisualBasic.Interaction.InputBox("Please enter line number...", "Enter Line Number...", 0)
  652. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  653. Dim LineInfo As Integer = Convert.ToInt32(ib)
  654. Dim index As Integer = 0
  655. Dim total As Integer = 0
  656. For Each lineStr As String In .Lines
  657. If index = LineInfo Then
  658. Exit For
  659. End If
  660. total += lineStr.Length
  661. index += 1
  662. Next
  663. .SelectionStart = total
  664. .Focus()
  665. .ScrollToCaret()
  666. End With
  667. Catch
  668. 'User cancelled or nothing in textbox, either way we ignore it and dont annoy user about it
  669. End Try
  670. End If
  671. End Sub
  672.  
  673. Private Sub btnUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUndo.Click
  674. If ScintillaMode = True Then
  675. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).UndoRedo.CanUndo = True Then
  676. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).UndoRedo.Undo()
  677. End If
  678. ElseIf CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).CanUndo = True Then
  679. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Undo()
  680. End If
  681. End Sub
  682.  
  683. Private Sub btnRedo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRedo.Click
  684. If ScintillaMode = True Then
  685. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).UndoRedo.Redo()
  686. Else
  687. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Redo()
  688. End If
  689. End Sub
  690.  
  691. Private Sub btnSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectAll.Click
  692. If ScintillaMode = True Then
  693. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Selection.SelectAll()
  694. Else
  695. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectAll()
  696. End If
  697. End Sub
  698. Private Sub btnCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCut.Click
  699. If ScintillaMode = True Then
  700. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Clipboard.Cut()
  701. Else
  702. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Cut()
  703. End If
  704. End Sub
  705.  
  706. Private Sub btnPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaste.Click
  707. If ScintillaMode = True Then
  708. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Clipboard.Paste()
  709. Else
  710. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Paste()
  711. End If
  712. End Sub
  713.  
  714. Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
  715. If ScintillaMode = True Then
  716. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Clipboard.Copy()
  717.  
  718. Else
  719. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Copy()
  720. End If
  721. End Sub
  722.  
  723. Private Sub btnReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplace.Click
  724. If ScintillaMode = True Then
  725. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).FindReplace.ShowReplace()
  726.  
  727. Else
  728. frmFindReplace.Show()
  729. frmFindReplace.tcMain.SelectedTab = frmFindReplace.tbReplace
  730. End If
  731. End Sub
  732.  
  733. Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
  734. If ScintillaMode = True Then
  735. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).FindReplace.ShowFind()
  736. Else
  737. frmFindReplace.Show()
  738. frmFindReplace.tcMain.SelectedTab = frmFindReplace.tbfind
  739. End If
  740. End Sub
  741. #End Region
  742. #Region "Insert Menu"
  743. Private Sub btnClipart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClipart.Click
  744. frmClipArt.Show()
  745. End Sub
  746. Private Sub ButtonItem1_Click_4(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertSymbol.Click
  747. frmInsertSymbol.Show()
  748. End Sub
  749.  
  750. Private Sub btnImageFromFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImageFromFile.Click
  751. Dim ofd As New OpenFileDialog
  752. ofd.Title = "Select image to add..."
  753. ofd.Filter = "Image Files|*.bmp;*.jpg;*.png;*.gif"
  754. If ofd.ShowDialog = DialogResult.OK Then
  755. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).InsertImage(ofd.FileName)
  756. End If
  757. End Sub
  758.  
  759. Private Sub btnWordArt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWordArt.Click
  760. frmWordArt.ShowDialog()
  761. End Sub
  762.  
  763. Private Sub tmrPasteImage_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrPasteImage.Tick
  764. tmrPasteImage.Stop()
  765. Me.BringToFront()
  766. Me.BringToFront()
  767. Me.BringToFront()
  768. Me.BringToFront()
  769. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Focus()
  770. SendKeys.Send("^v")
  771. End Sub
  772.  
  773. Private Sub ButtonItem1_Click_5(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertTime.Click
  774. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text &= Date.Now.ToString
  775. End Sub
  776. #End Region
  777. #Region "Tools Menu"
  778. Private Sub btnDocumentViewer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDocumentViewer.Click
  779. frmDocumentViewer.Show()
  780. End Sub
  781.  
  782. Private Sub btnLoadWebCode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadWebCode.Click
  783. Try
  784. Dim ib As String = Interaction.InputBox("Please enter the URL of the website", "Website URL", "http://www.google.co.uk")
  785. Dim wc As New WebClient
  786. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text = wc.DownloadString(ib)
  787. Catch ex As Exception
  788. MessageBoxEx.Show("An error occured: " & ex.Message, "Error")
  789. End Try
  790.  
  791. End Sub
  792. Private Sub btnOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOptions.Click
  793. frmOptions.ShowDialog()
  794. End Sub
  795. Private Sub btnDocumentToImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDocumentToImage.Click
  796. Dim sfd As New SaveFileDialog
  797. sfd.Filter = "JPEG Images|*.jpg"
  798. sfd.Title = "Save as..."
  799. If sfd.ShowDialog = DialogResult.OK Then
  800. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  801. Dim wid As Integer = .Width
  802. Dim hgt As Integer = .Height
  803. Dim bm As New Bitmap(wid, hgt)
  804. .DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
  805. RtbToBitmap(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB), contentRectangle, sfd.FileName)
  806. End With
  807. End If
  808. End Sub
  809.  
  810. Private Sub RtbToBitmap(ByVal rtb As RichTextBox, ByVal rectangle As Rectangle, ByVal fileName As String)
  811. Dim bmp As New Bitmap(rectangle.Width, rectangle.Height)
  812. Using gr As Graphics = Graphics.FromImage(bmp)
  813. Dim hDC As IntPtr = gr.GetHdc()
  814. Dim fmtRange As FORMATRANGE
  815. Dim rect As RECT
  816. Dim fromAPI As Integer
  817. rect.Top = 0
  818. rect.Left = 0
  819. rect.Bottom = CInt(Math.Truncate(bmp.Height + (bmp.Height * (bmp.HorizontalResolution / 100)) * inch))
  820. rect.Right = CInt(Math.Truncate(bmp.Width + (bmp.Width * (bmp.VerticalResolution / 100)) * inch))
  821. fmtRange.chrg.cpMin = 0
  822. fmtRange.chrg.cpMax = -1
  823. fmtRange.hdc = hDC
  824. fmtRange.hdcTarget = hDC
  825. fmtRange.rc = rect
  826. fmtRange.rcPage = rect
  827. Dim wParam As Integer = 1
  828. Dim lParam As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange))
  829. Marshal.StructureToPtr(fmtRange, lParam, False)
  830. fromAPI = SendMessage(rtb.Handle, EM_FORMATRANGE, wParam, lParam)
  831. Marshal.FreeCoTaskMem(lParam)
  832. fromAPI = SendMessage(rtb.Handle, EM_FORMATRANGE, wParam, New IntPtr(0))
  833. gr.ReleaseHdc(hDC)
  834. End Using
  835. bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg)
  836. bmp.Dispose()
  837. End Sub
  838. #End Region
  839. #Region "View Menu"
  840. 'Syntax Highlghting
  841. Dim PrevStyle As Color
  842. 'Zooming
  843. Private Sub btnZoomin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZoomin.Click
  844. On Error Resume Next
  845. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).ZoomFactor += 0.5
  846. End Sub
  847.  
  848. Private Sub btnResetzoom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetzoom.Click
  849. On Error Resume Next
  850. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).ZoomFactor = 1
  851. End Sub
  852.  
  853. Private Sub btnZoomOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZoomOut.Click
  854. On Error Resume Next
  855. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).ZoomFactor -= 0.5
  856. End Sub
  857. 'End of Zooming
  858. 'Topmost or not...
  859. Private Sub btnTopMost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTopMost.Click
  860. Me.TopMost = btnTopMost.Checked
  861. End Sub
  862. #End Region
  863. #Region "Handle tab changing & closing"
  864.  
  865. Private Sub tcMain_SelectedTabChanged(ByVal sender As Object, ByVal e As DevComponents.DotNetBar.TabStripTabChangedEventArgs) Handles tcMain.SelectedTabChanged
  866. Dim x = e.NewTab.AttachedControl.Controls.Item(0)
  867. If TypeOf x Is RTB Then
  868. ScintillaMode = False
  869. btnZoom.Visible = True
  870. btnWordWrap.Visible = True
  871. btnInsert.Visible = True
  872. btnLeftAlign.Visible = True
  873. btnAlignCenter.Visible = True
  874. btnRightAlign.Visible = True
  875. btnJustifyAlign.Visible = True
  876. btnBold.Visible = True
  877. btnItalic.Visible = True
  878. btnUnderined.Visible = True
  879. btnStrikeOut.Visible = True
  880. btnUpperLowerCase.Visible = True
  881. btnBulletedList.Visible = True
  882. btnNumberedList.Visible = True
  883. btnIncreaseIndent.Visible = True
  884. btnDecreaseIndent.Visible = True
  885. btnSuperScript.Visible = True
  886. btnSubscript.Visible = True
  887. btnSpellCheck.Visible = True
  888. cbxFonts.Visible = True
  889. cbxTextSize.Visible = True
  890. btnDivider1.Visible = True
  891. btnDivider2.Visible = True
  892. btnDivider3.Visible = True
  893. btnDivider4.Visible = True
  894. btnDocumentToImage.Visible = True
  895. btnBrowserTest.Visible = False
  896. btnSyntaxHighlighting.Visible = False
  897. Else
  898. btnBrowserTest.Visible = True
  899. ScintillaMode = True
  900. btnZoom.Visible = False
  901. btnWordWrap.Visible = False
  902. btnInsert.Visible = False
  903. btnLeftAlign.Visible = False
  904. btnAlignCenter.Visible = False
  905. btnRightAlign.Visible = False
  906. btnJustifyAlign.Visible = False
  907. btnBold.Visible = False
  908. btnItalic.Visible = False
  909. btnUnderined.Visible = False
  910. btnStrikeOut.Visible = False
  911. btnUpperLowerCase.Visible = False
  912. btnBulletedList.Visible = False
  913. btnNumberedList.Visible = False
  914. btnIncreaseIndent.Visible = False
  915. btnDecreaseIndent.Visible = False
  916. btnSuperScript.Visible = False
  917. btnSubscript.Visible = False
  918. btnSpellCheck.Visible = False
  919. cbxFonts.Visible = False
  920. cbxTextSize.Visible = False
  921. btnDivider1.Visible = False
  922. btnDivider2.Visible = False
  923. btnDivider3.Visible = False
  924. btnDivider4.Visible = False
  925. btnDocumentToImage.Visible = False
  926. btnBrowserTest.Visible = True
  927. btnSyntaxHighlighting.Visible = True
  928. End If
  929. Try
  930. e.NewTab.AttachedControl.Controls.Item(0).Focus()
  931. tmrUpdateSize.Start()
  932. Catch
  933. 'Some retarded exception.
  934. End Try
  935.  
  936. End Sub
  937.  
  938. Private Sub tcMain_TabItemClose(ByVal sender As Object, ByVal e As DevComponents.DotNetBar.TabStripActionEventArgs) Handles tcMain.TabItemClose
  939. If tcMain.Tabs.Count = 1 Then
  940. Exit Sub
  941. End If
  942. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).DocumentModified = True AndAlso CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text <> Nothing Then
  943. Dim dr As DialogResult = DevComponents.DotNetBar.MessageBoxEx.Show("The selected document has not been saved. Do you want to save it before closing?", "Question", MessageBoxButtons.YesNoCancel)
  944. If dr = Windows.Forms.DialogResult.Yes Then
  945. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath <> Nothing Then
  946. Dim sp As String = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SavePath
  947. Dim strExt = System.IO.Path.GetExtension(sp)
  948. strExt = strExt.ToUpper()
  949. If strExt = ".RTF" Then
  950. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SaveDocument(sp)
  951. Else
  952. Dim saved As New IO.StreamWriter(sp)
  953. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  954. saved.Flush()
  955. saved.Close()
  956. End If
  957. Else
  958. Dim sfd As New SaveFileDialog
  959. sfd.Title = "Select a file to save as..."
  960. sfd.Filter = "Rich Text Format (*.rtf)|*.rtf|Text File (*.txt)|*.txt|All Files|"
  961. If sfd.ShowDialog = DialogResult.OK Then
  962. Dim strExt = System.IO.Path.GetExtension(sfd.FileName)
  963. strExt = strExt.ToUpper()
  964. If strExt = ".RTF" Then
  965. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SaveDocument(sfd.FileName)
  966. Else
  967. Dim saved As New IO.StreamWriter(sfd.FileName)
  968. saved.Write(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text)
  969. saved.Flush()
  970. saved.Close()
  971. End If
  972. Else
  973. Exit Sub
  974. End If
  975. End If
  976.  
  977. ElseIf dr = Windows.Forms.DialogResult.Cancel Then
  978. Exit Sub
  979. End If
  980. End If
  981.  
  982.  
  983. tcMain.Tabs.Remove(tcMain.SelectedTab)
  984. End Sub
  985.  
  986. #End Region
  987. #Region "Handle text Superscript & Subscript"
  988. Dim oldfont As Font
  989. Private Sub btnSuperScript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuperScript.Click
  990. Try
  991. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  992. If .SelectionCharOffset = 8 Then
  993. .SelectionCharOffset = 0
  994. .SelectionFont = oldfont
  995. btnSubscript.Enabled = True
  996. Else
  997. btnSubscript.Enabled = False
  998. .SelectionCharOffset = 8
  999. oldfont = .SelectionFont
  1000. .SelectionFont = New Font(.SelectionFont.Name, 8)
  1001. End If
  1002. End With
  1003. Catch
  1004. End Try
  1005. End Sub
  1006.  
  1007. Private Sub btnSubscript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubscript.Click
  1008. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1009. If .SelectionCharOffset = -8 Then
  1010. .SelectionCharOffset = 0
  1011. .SelectionFont = oldfont
  1012. btnSuperScript.Enabled = True
  1013. Else
  1014. btnSuperScript.Enabled = False
  1015.  
  1016. .SelectionCharOffset = -8
  1017. oldfont = .SelectionFont
  1018. .SelectionFont = New Font(.SelectionFont.Name, 8)
  1019. End If
  1020. End With
  1021. End Sub
  1022. #End Region
  1023. #Region "Handle text size"
  1024. Private Sub cbxTextSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbxTextSize.SelectedIndexChanged
  1025. On Error Resume Next
  1026. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1027. Dim sz As Single = cbxTextSize.SelectedItem.ToString
  1028. .SelectionFont = New Font(.SelectionFont.Name, sz, .SelectionFont.Style)
  1029. End With
  1030. End Sub
  1031.  
  1032. Private Sub cbxFonts_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbxFonts.SelectedIndexChanged
  1033. On Error Resume Next
  1034. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1035. .SelectionFont = New Font(cbxFonts.SelectedItem.ToString, .SelectionFont.Size, .SelectionFont.Style)
  1036. End With
  1037. End Sub
  1038. #End Region
  1039. #Region "Handle text alignment"
  1040. Private Sub btnLeftAlign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeftAlign.Click
  1041. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1042. .SelectionAlignment = ExtendedRichTextBox.RichTextAlign.Left
  1043. End With
  1044. btnAlignCenter.Checked = False
  1045. btnRightAlign.Checked = False
  1046. btnJustifyAlign.Checked = False
  1047. End Sub
  1048.  
  1049. Private Sub btnAlignCenter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAlignCenter.Click
  1050. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1051. .SelectionAlignment = ExtendedRichTextBox.RichTextAlign.Center
  1052.  
  1053. End With
  1054. btnRightAlign.Checked = False
  1055. btnLeftAlign.Checked = False
  1056. btnJustifyAlign.Checked = False
  1057. End Sub
  1058. Private Sub btnRightAlign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRightAlign.Click
  1059. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1060. .SelectionAlignment = ExtendedRichTextBox.RichTextAlign.Right
  1061. End With
  1062. btnAlignCenter.Checked = False
  1063. btnLeftAlign.Checked = False
  1064. btnJustifyAlign.Checked = False
  1065. End Sub
  1066.  
  1067. Private Sub btnJustifyAlign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnJustifyAlign.Click
  1068. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1069. .SelectionAlignment = ExtendedRichTextBox.RichTextAlign.Justify
  1070. End With
  1071. btnAlignCenter.Checked = False
  1072. btnLeftAlign.Checked = False
  1073. btnRightAlign.Checked = False
  1074.  
  1075. End Sub
  1076. #End Region
  1077. #Region "Handle Text Bold, Underlined, Italic, Strikeout"
  1078. Private Sub btnBold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBold.Click
  1079. On Error Resume Next
  1080. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1081. Dim ExistingFont As Font = .SelectionFont
  1082. Dim NewFontStyle As New FontStyle
  1083. With ExistingFont
  1084. NewFontStyle = -((Not .Bold) * FontStyle.Bold)
  1085. NewFontStyle += -(.Italic * FontStyle.Italic)
  1086. NewFontStyle += -(.Underline * FontStyle.Underline)
  1087. NewFontStyle += -(.Strikeout * FontStyle.Strikeout)
  1088. End With
  1089. .SelectionFont = New Font(ExistingFont, NewFontStyle)
  1090. End With
  1091.  
  1092. End Sub
  1093.  
  1094. Private Sub btnItalic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItalic.Click
  1095. On Error Resume Next
  1096. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1097. Dim ExistingFont As Font = .SelectionFont
  1098. Dim NewFontStyle As New FontStyle
  1099. With ExistingFont
  1100. NewFontStyle = -((Not .Italic) * FontStyle.Italic)
  1101. NewFontStyle += -(.Underline * FontStyle.Underline)
  1102. NewFontStyle += -(.Bold * FontStyle.Bold)
  1103. NewFontStyle += -(.Strikeout * FontStyle.Strikeout)
  1104. End With
  1105. .SelectionFont = New Font(ExistingFont, NewFontStyle)
  1106. End With
  1107.  
  1108. End Sub
  1109.  
  1110. Private Sub btnUnderined_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnderined.Click
  1111. On Error Resume Next
  1112. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1113. Dim ExistingFont As Font = .SelectionFont
  1114. Dim NewFontStyle As New FontStyle
  1115. With ExistingFont
  1116. NewFontStyle = -((Not .Underline) * FontStyle.Underline)
  1117. NewFontStyle += -(.Italic * FontStyle.Italic)
  1118. NewFontStyle += -(.Bold * FontStyle.Bold)
  1119. NewFontStyle += -(.Strikeout * FontStyle.Strikeout)
  1120. End With
  1121. .SelectionFont = New Font(ExistingFont, NewFontStyle)
  1122. End With
  1123.  
  1124. End Sub
  1125.  
  1126. Private Sub ButtonItem4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStrikeOut.Click
  1127. On Error Resume Next
  1128. With CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB)
  1129. Dim ExistingFont As Font = .SelectionFont
  1130. Dim NewFontStyle As New FontStyle
  1131. With ExistingFont
  1132. NewFontStyle = -((Not .Strikeout) * FontStyle.Strikeout)
  1133. NewFontStyle += -(.Underline * FontStyle.Underline)
  1134. NewFontStyle += -(.Bold * FontStyle.Bold)
  1135. NewFontStyle += -(.Italic * FontStyle.Italic)
  1136. End With
  1137. .SelectionFont = New Font(ExistingFont, NewFontStyle)
  1138. End With
  1139. End Sub
  1140. #End Region
  1141. #Region "Handle Text Increase & Decrease Indent"
  1142. Private Sub ButtonItem1_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIncreaseIndent.Click
  1143. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionIndent += 30
  1144. End Sub
  1145.  
  1146. Private Sub btnDecreaseIndent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecreaseIndent.Click
  1147. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionIndent -= 30
  1148. End Sub
  1149.  
  1150.  
  1151. #End Region
  1152. #Region "Handle text Case Changing"
  1153. Private Sub ButtonItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpperCase.Click
  1154. On Error Resume Next
  1155. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText.ToUpper
  1156. End Sub
  1157.  
  1158. Private Sub btnLowerCase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLowerCase.Click
  1159. On Error Resume Next
  1160. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText.ToLower
  1161. End Sub
  1162. Private Sub btnToggleCase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToggleCase.Click
  1163. On Error Resume Next
  1164. Dim invertedtext As String = Nothing
  1165. Dim sttext As String = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText
  1166. For Each cr In CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText
  1167. Dim str As String = cr.ToString
  1168. If str.ToLower = str Then
  1169. str = str.ToUpper
  1170. Else
  1171. str = str.ToLower
  1172. End If
  1173. invertedtext &= str
  1174. Next
  1175. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText = invertedtext
  1176. End Sub
  1177.  
  1178. Private Sub btnSentenceCase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSentenceCase.Click
  1179. On Error Resume Next
  1180. Dim SentenceCaseText As String = Nothing
  1181. Dim CapNextString As Boolean = False
  1182. Dim sttext As String = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText
  1183. For Each cr In CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText
  1184. Dim str As String = cr.ToString
  1185. If CapNextString = True Then
  1186. If str <> " " Then
  1187. str = str.ToUpper
  1188. CapNextString = False
  1189. End If
  1190. Else
  1191. str = str.ToLower
  1192. End If
  1193. If str = "." Then
  1194. CapNextString = True
  1195. End If
  1196. SentenceCaseText &= str
  1197. Next
  1198. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText = SentenceCaseText
  1199. End Sub
  1200.  
  1201. Private Sub btnCapitalEachWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapitalEachWord.Click
  1202. On Error Resume Next
  1203. Dim EachWordCapped As String = Nothing
  1204. Dim CapNextString As Boolean = False
  1205. Dim FirsstLetter As Boolean = True
  1206. Dim sttext As String = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText
  1207. For Each cr In CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText
  1208. Dim str As String = cr.ToString
  1209. If sttext = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text Then
  1210. If FirsstLetter = True Then
  1211. FirsstLetter = False
  1212. str = str.ToUpper
  1213. End If
  1214. End If
  1215. If CapNextString = True Then
  1216. str = str.ToUpper
  1217. CapNextString = False
  1218. Else
  1219. str = str.ToLower
  1220. End If
  1221. If str = " " Then
  1222. CapNextString = True
  1223. End If
  1224. EachWordCapped &= str
  1225. Next
  1226. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText = EachWordCapped
  1227. End Sub
  1228. #End Region
  1229. #Region "Handle Other Text Toolbar commands: Bulleted List, Spell Check, Indent"
  1230.  
  1231. Private Sub btnWordCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWordCount.Click
  1232. If ScintillaMode Then
  1233. Dim collection As MatchCollection = Regex.Matches(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Text, "\S+")
  1234. Dim wordcount = "Words: " & collection.Count.ToString
  1235. Dim charsnospaces As String = "Charactors (no spaces): " & CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Text.Replace(" ", "").Length
  1236. DevComponents.DotNetBar.MessageBoxEx.Show(wordcount & Environment.NewLine & "Charactors: " & CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Text.Length & Environment.NewLine & charsnospaces)
  1237. Else
  1238.  
  1239. Dim collection As MatchCollection = Regex.Matches(CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text, "\S+")
  1240. Dim wordcount = "Words: " & collection.Count.ToString
  1241. Dim charsnospaces As String = "Charactors (no spaces): " & CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text.Replace(" ", "").Length
  1242. DevComponents.DotNetBar.MessageBoxEx.Show(wordcount & Environment.NewLine & "Charactors: " & CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).Text.Length & Environment.NewLine & charsnospaces)
  1243. End If
  1244.  
  1245. End Sub
  1246. #Region "Bulleted Lists"
  1247. Private Sub btnBulletedList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBulletedList.Click
  1248. For Each ctrl In gcBullets.SubItems
  1249. If TypeOf ctrl Is ButtonItem Then
  1250. ctrl.Checked = False
  1251. End If
  1252. Next
  1253. btnNumberedList.Checked = False
  1254. btnNoBullets.Checked = False
  1255. If btnBulletedList.Checked = True Then
  1256. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionBullet = True
  1257. Else
  1258. btnNoBullets.Checked = True
  1259. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionBullet = False
  1260. End If
  1261. End Sub
  1262.  
  1263. Private Sub btnNumberedList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumberedList.Click
  1264. For Each ctrl In gcBullets.SubItems
  1265. If TypeOf ctrl Is ButtonItem Then
  1266. ctrl.Checked = False
  1267. End If
  1268. Next
  1269. btnBulletedList.Checked = False
  1270. If Me.btnNumberedList.Checked Then
  1271. Me.btnNumberedList.Checked = False
  1272. btnNoBullets.Checked = True
  1273. Dim pls As New ExtendedRichTextBox.ParaListStyle()
  1274. pls.Type = ExtendedRichTextBox.ParaListStyle.ListType.None
  1275. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionListType = pls
  1276. Else
  1277. Me.btnNumberedList.Checked = True
  1278. Dim pls As New ExtendedRichTextBox.ParaListStyle()
  1279. pls.Type = ExtendedRichTextBox.ParaListStyle.ListType.Numbers
  1280. pls.Style = ExtendedRichTextBox.ParaListStyle.ListStyle.NumberAndPeriod
  1281. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionListType = pls
  1282. End If
  1283. End Sub
  1284.  
  1285. Private Sub btnNoBullets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNoBullets.Click
  1286. For Each ctrl In gcBullets.SubItems
  1287. If TypeOf ctrl Is ButtonItem Then
  1288. ctrl.Checked = False
  1289. End If
  1290. Next
  1291.  
  1292. btnBulletedList.Checked = False
  1293. Me.btnNoBullets.Checked = True
  1294. btnNumberedList.Checked = False
  1295.  
  1296. Dim pls As New ExtendedRichTextBox.ParaListStyle()
  1297. pls.Type = ExtendedRichTextBox.ParaListStyle.ListType.None
  1298. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionListType = pls
  1299. End Sub
  1300. Private Sub btnLettersUCaseDots_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLettersUCaseDots.Click
  1301. For Each ctrl In gcBullets.SubItems
  1302. If TypeOf ctrl Is ButtonItem Then
  1303. ctrl.Checked = False
  1304. End If
  1305. Next
  1306.  
  1307. btnBulletedList.Checked = False
  1308. Me.btnLettersUCaseDots.Checked = True
  1309. btnNumberedList.Checked = True
  1310.  
  1311. Dim pls As New ExtendedRichTextBox.ParaListStyle()
  1312. pls.Type = ExtendedRichTextBox.ParaListStyle.ListType.CapitalLetters
  1313. pls.Style = ExtendedRichTextBox.ParaListStyle.ListStyle.NumberAndPeriod
  1314. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionListType = pls
  1315. End Sub
  1316. Private Sub btnLCaseBrackets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLCaseBrackets.Click
  1317. For Each ctrl In gcBullets.SubItems
  1318. If TypeOf ctrl Is ButtonItem Then
  1319. ctrl.Checked = False
  1320. End If
  1321. Next
  1322.  
  1323. btnBulletedList.Checked = False
  1324. btnLCaseBrackets.Checked = True
  1325. btnNumberedList.Checked = True
  1326.  
  1327. Dim pls As New ExtendedRichTextBox.ParaListStyle()
  1328. pls.Type = ExtendedRichTextBox.ParaListStyle.ListType.SmallLetters
  1329. pls.Style = ExtendedRichTextBox.ParaListStyle.ListStyle.NumberInPar
  1330. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionListType = pls
  1331.  
  1332. End Sub
  1333. Private Sub btnNumberalsDots_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumberalsDots.Click
  1334. For Each ctrl In gcBullets.SubItems
  1335. If TypeOf ctrl Is ButtonItem Then
  1336. ctrl.Checked = False
  1337. End If
  1338. Next
  1339.  
  1340. btnBulletedList.Checked = False
  1341. btnNumberalsDots.Checked = True
  1342. btnNumberedList.Checked = True
  1343.  
  1344. Dim pls As New ExtendedRichTextBox.ParaListStyle()
  1345. pls.Type = ExtendedRichTextBox.ParaListStyle.ListType.CapitalRoman
  1346. pls.Style = ExtendedRichTextBox.ParaListStyle.ListStyle.NumberAndPeriod
  1347. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionListType = pls
  1348.  
  1349. End Sub
  1350. Private Sub btnNumberedDots_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumberedDots.Click
  1351. For Each ctrl In gcBullets.SubItems
  1352. If TypeOf ctrl Is ButtonItem Then
  1353. ctrl.Checked = False
  1354. End If
  1355. Next
  1356.  
  1357. btnBulletedList.Checked = False
  1358. btnNumberedDots.Checked = True
  1359. btnNumberedList.Checked = True
  1360.  
  1361. Dim pls As New ExtendedRichTextBox.ParaListStyle()
  1362. pls.Type = ExtendedRichTextBox.ParaListStyle.ListType.Numbers
  1363. pls.Style = ExtendedRichTextBox.ParaListStyle.ListStyle.NumberAndPeriod
  1364. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionListType = pls
  1365.  
  1366. End Sub
  1367. Private Sub btnNumberedBrackets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumberedBrackets.Click
  1368. For Each ctrl In gcBullets.SubItems
  1369. If TypeOf ctrl Is ButtonItem Then
  1370. ctrl.Checked = False
  1371. End If
  1372. Next
  1373.  
  1374. btnBulletedList.Checked = False
  1375. btnNumberedBrackets.Checked = True
  1376. btnNumberedList.Checked = True
  1377.  
  1378. Dim pls As New ExtendedRichTextBox.ParaListStyle()
  1379. pls.Type = ExtendedRichTextBox.ParaListStyle.ListType.Numbers
  1380. pls.Style = ExtendedRichTextBox.ParaListStyle.ListStyle.NumberInPar
  1381. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionListType = pls
  1382. End Sub
  1383. Private Sub btnSmallNumeralsDots_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSmallNumeralsDots.Click
  1384. For Each ctrl In gcBullets.SubItems
  1385. If TypeOf ctrl Is ButtonItem Then
  1386. ctrl.Checked = False
  1387. End If
  1388. Next
  1389.  
  1390. btnBulletedList.Checked = False
  1391. btnSmallNumeralsDots.Checked = True
  1392. btnNumberedList.Checked = True
  1393.  
  1394. Dim pls As New ExtendedRichTextBox.ParaListStyle()
  1395. pls.Type = ExtendedRichTextBox.ParaListStyle.ListType.SmallRoman
  1396. pls.Style = ExtendedRichTextBox.ParaListStyle.ListStyle.NumberAndPeriod
  1397. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionListType = pls
  1398.  
  1399. End Sub
  1400.  
  1401. #End Region
  1402.  
  1403.  
  1404. Private Sub btnSpellCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSpellCheck.Click
  1405. frmSpellCheck.ShowDialog()
  1406. End Sub
  1407. #End Region
  1408. #Region "Update the statuses of the Toolbar when the selected text is changed in the RichTextBox"
  1409. Private Sub tmrUpdateSize_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrUpdateSize.Tick
  1410. tmrUpdateSize.Stop()
  1411. If ScintillaMode = False Then
  1412. Try
  1413. For Each itm As DevComponents.Editors.ComboItem In cbxTextSize.Items
  1414. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionFont.Size.ToString = itm.Text Then
  1415. cbxTextSize.SelectedItem = itm
  1416. End If
  1417. Next
  1418. Catch
  1419. 'Multiple font sizes selected
  1420. cbxTextSize.Text = ""
  1421. cbxTextSize.SelectedItem = Nothing
  1422. End Try
  1423. Try
  1424. For Each itm As DevComponents.Editors.ComboItem In cbxFonts.Items
  1425. If CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectionFont.Name = itm.Text Then
  1426. cbxFonts.SelectedItem = itm
  1427. End If
  1428. Next
  1429. Catch
  1430. 'Multiple fonts selected.
  1431. cbxFonts.Text = ""
  1432. cbxFonts.SelectedItem = Nothing
  1433. End Try
  1434. End If
  1435.  
  1436.  
  1437. End Sub
  1438. #End Region
  1439. #Region "Help Menu"
  1440. Private Sub btnHelpDoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHelpDoc.Click
  1441. System.Windows.Forms.Help.ShowHelp(Me, "NotepadXHelp.chm")
  1442. End Sub
  1443.  
  1444. Private Sub btnFeedback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFeedback.Click
  1445. frmFeedback.ShowDialog()
  1446. End Sub
  1447.  
  1448. Private Sub btnStyling_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStyling.Click
  1449. frmStyling.ShowDialog()
  1450. Me.BringToFront()
  1451. End Sub
  1452. #End Region
  1453. #Region "Handle Contextmenu"
  1454. Private Sub cmuMain_PopupClose(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmuMain.PopupClose
  1455. mnuSynonyms.SubItems.Clear()
  1456. End Sub
  1457.  
  1458. Private Sub btnLookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLookup.Click
  1459. frmLookup.Show()
  1460. frmLookup.Word = Me.Word
  1461. End Sub
  1462. #End Region
  1463.  
  1464. Private Sub btnWordWrap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWordWrap.Click
  1465. ' If btnWordWrap.Checked = True Then
  1466. ' CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).WordWrap = True
  1467. ' Else
  1468. ' CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).WordWrap = False
  1469. ' End If
  1470. End Sub
  1471.  
  1472.  
  1473.  
  1474. Private Sub btnNewScintillaDocument_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewScintillaDocument.Click
  1475. If asked = False Then
  1476. If notes > 50 Then
  1477. If DevComponents.DotNetBar.MessageBoxEx.Show("Stuff could get laggy if you have more than 50 documents. Continue? (you'll only need to answer once)", "Question", MessageBoxButtons.YesNo) <> DialogResult.Yes Then
  1478. Exit Sub
  1479. Else
  1480. asked = True
  1481. End If
  1482. End If
  1483. End If
  1484. notes += 1
  1485.  
  1486. Dim tb As DevComponents.DotNetBar.TabItem = tcMain.CreateTab("")
  1487. tb.Text = "New note - " & notes.ToString
  1488. Dim myrtb As New ScintillaEX
  1489. myrtb.Dock = DockStyle.Fill
  1490. ' myrtb.Font = New Font(myrtb.Font.Name, 12)
  1491. tb.AttachedControl.Controls.Add(myrtb)
  1492. tcMain.SelectedTab = tb
  1493. myrtb.Select()
  1494. End Sub
  1495.  
  1496. #Region "Syntax highlightging"
  1497. Private Sub ButtonItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAsm.Click
  1498. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).ConfigurationManager.Language = "asm"
  1499. End Sub
  1500.  
  1501. Private Sub btnXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXML.Click
  1502. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).ConfigurationManager.Language = "xml"
  1503.  
  1504. End Sub
  1505.  
  1506. Private Sub btnvbs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvbs.Click
  1507. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).ConfigurationManager.Language = "vbscript"
  1508. End Sub
  1509.  
  1510. Private Sub btnJs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnJs.Click
  1511. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).ConfigurationManager.Language = "js"
  1512. End Sub
  1513.  
  1514. Private Sub btnPython_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPython.Click
  1515. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).ConfigurationManager.Language = "phython"
  1516. End Sub
  1517.  
  1518. Private Sub btnHTM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHTM.Click
  1519. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).ConfigurationManager.Language = "html"
  1520. End Sub
  1521.  
  1522. Private Sub btnCS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCS.Click
  1523. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).ConfigurationManager.Language = "cs"
  1524.  
  1525. End Sub
  1526.  
  1527. Private Sub btnSQL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSQL.Click
  1528. CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).ConfigurationManager.Language = "mssql"
  1529. End Sub
  1530. #End Region
  1531.  
  1532. Private Sub btnBrowserTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowserTest.Click
  1533. Dim x As String = CType(tcMain.SelectedTab.AttachedControl.Controls.Item(0), ScintillaEX).Text
  1534. Dim therandom As New Random
  1535. Dim tempfile As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\temp\" & therandom.Next(1, 999999).ToString & ".html"
  1536. Dim savef As New IO.StreamWriter(tempfile)
  1537. savef.Write(x)
  1538. savef.Close()
  1539. Process.Start(tempfile)
  1540. End Sub
  1541.  
  1542. Private Sub ButtonItem3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
  1543.  
  1544. End Sub
  1545. End Class
  1546.  
  1547. #Region "Custom Controls"
  1548. Public Class bitm_recent
  1549. Inherits DevComponents.DotNetBar.ButtonItem
  1550.  
  1551. Private Sub bitm_recent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
  1552. Dim tb As DevComponents.DotNetBar.TabItem = frmMain.tcMain.CreateTab("")
  1553. tb.Text = Me.Text.Substring(Me.Text.LastIndexOf("\")).Replace("\", "")
  1554. Dim myrtb As New RTB
  1555. myrtb.Dock = DockStyle.Fill
  1556. myrtb.Font = New Font(myrtb.Font.Name, 12)
  1557. Try
  1558. myrtb.LoadFile(Me.Text)
  1559. Catch
  1560. Dim loadf As New IO.StreamReader(Me.Text)
  1561. myrtb.Text = loadf.ReadToEnd
  1562. loadf.Close()
  1563. End Try
  1564. myrtb.SavePath = Me.Text
  1565. myrtb.DocumentModified = False
  1566. tb.AttachedControl.Controls.Add(myrtb)
  1567. frmMain.tcMain.SelectedTab = tb
  1568. myrtb.Select()
  1569. End Sub
  1570. End Class
  1571. Public Class bitm_Synonym
  1572. Inherits DevComponents.DotNetBar.ButtonItem
  1573. Private Sub bitm_Synonym_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
  1574. CType(frmMain.tcMain.SelectedTab.AttachedControl.Controls.Item(0), RTB).SelectedText = Me.Text
  1575. End Sub
  1576. End Class
  1577. #End Region
Advertisement
Add Comment
Please, Sign In to add comment