Ich habe bereits den Code, wie bisher auch, nochmal verändert. Ich habe nun ein Problem und zwar, irgendwie funktioniert das Wörterbuch (das aus einer Textdatei besteht) nicht.
Spoiler anzeigen
Quellcode
- Imports System.IO
- Imports System.Drawing.Text
- Imports Microsoft.Win32
- Imports System.Runtime.InteropServices
- Imports System.Text.RegularExpressions
- Imports System.Diagnostics
- <DebuggerDisplay("{GetDebuggerDisplay(),nq}")>
- Public Class TmEditor
- Inherits Form
- ' Private Felder
- Private fontSizes As New List(Of Integer) From {8, 10, 11, 12, 14, 16, 18, 20}
- Private selectedColor As Color = Color.Black
- Private autoSaveEnabled As Boolean = False
- Private lastFilePath As String = ""
- Private WithEvents AutoSaveTimer As New Timer()
- Private WithEvents HighlightTimer As New Timer()
- Private Const IconPath As String = "Resources\texteditor.ico"
- Private lastTextBeforeSave As String
- Private Wörterbuch As New Dictionary(Of String, String)()
- ' Importieren der SHChangeNotify-Funktion aus der Shell32.dll
- <DllImport("Shell32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
- Private Shared Function SHChangeNotify(ByVal wEventId As Integer, ByVal uFlags As Integer, ByVal dwItem1 As IntPtr, ByVal dwItem2 As IntPtr) As Boolean
- End Function
- Public Sub New()
- InitializeComponent()
- AddHandler TxtEditor.KeyDown, AddressOf TxtEditor_KeyDown
- End Sub
- ' Methode zum Lesen der Wörter aus einer Wörterbuchdatei
- Private Sub LeseWörterbuchAusDatei(wörterbuchDateiPfad As String)
- If File.Exists(wörterbuchDateiPfad) Then
- Dim wörter As String() = File.ReadAllLines(wörterbuchDateiPfad)
- For Each wort In wörter
- If Not Wörterbuch.ContainsKey(wort.ToLower()) Then
- Wörterbuch.Add(wort.ToLower(), Nothing)
- End If
- Next
- Else
- MessageBox.Show("Die Wörterbuchdatei wurde nicht gefunden.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End If
- End Sub
- ' Methode zum Überprüfen der Rechtschreibung
- Private Sub ÜberprüfeRechtschreibung()
- Dim text As String = TxtEditor.Text
- Dim wörter As String() = text.Split({" "c, vbLf, vbCr, vbTab, ".", ",", ";", ":", "!", "?"}, StringSplitOptions.RemoveEmptyEntries)
- For Each wort In wörter
- If Not Wörterbuch.ContainsKey(wort.ToLower()) Then
- Dim startIndex As Integer = TxtEditor.Find(wort, RichTextBoxFinds.WholeWord)
- While startIndex >= 0
- TxtEditor.Select(startIndex, wort.Length)
- TxtEditor.SelectionBackColor = Color.Yellow ' Markiere das Wort
- startIndex = TxtEditor.Find(wort, startIndex + wort.Length, RichTextBoxFinds.WholeWord)
- End While
- End If
- Next
- TxtEditor.DeselectAll()
- End Sub
- ' Methode zum Markieren von Hyperlinks
- Private Sub MarkiereHyperlinks()
- Dim regex As New Regex("\b(?:https?://|www\.)\S+\b", RegexOptions.IgnoreCase)
- Dim matches As MatchCollection = regex.Matches(TxtEditor.Text)
- For Each match As Match In matches
- TxtEditor.Select(match.Index, match.Length)
- TxtEditor.SelectionColor = Color.Blue
- TxtEditor.SelectionFont = New Font(TxtEditor.SelectionFont, FontStyle.Underline)
- TxtEditor.Select(TxtEditor.TextLength, 0)
- Next
- TxtEditor.DeselectAll()
- End Sub
- ' Ereignishandler für Link-Klicks
- Private Sub TxtEditor_LinkClicked(sender As Object, e As LinkClickedEventArgs) Handles TxtEditor.LinkClicked
- Process.Start(e.LinkText)
- End Sub
- ' Ereignishandler verknüpfen
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- ' Schriftgrößen zur Dropdown-Liste hinzufügen
- For Each fontSize As Integer In fontSizes
- cmbFontSize.Items.Add(fontSize)
- Next
- ' Installierte Schriftarten in ComboBox laden
- Dim installedFonts As New InstalledFontCollection()
- For Each font As FontFamily In installedFonts.Families
- cmbFontFamily.Items.Add(font.Name)
- Next
- ' Ereignishandler verknüpfen
- AddHandler cmbFontSize.SelectedIndexChanged, AddressOf CmbFontSize_SelectedIndexChanged
- AddHandler cmbFontFamily.SelectedIndexChanged, AddressOf CmbFontFamily_SelectedIndexChanged
- AddHandler btnBlack.Click, AddressOf ColorButton_Click
- AddHandler btnRed.Click, AddressOf ColorButton_Click
- AddHandler btnBlue.Click, AddressOf ColorButton_Click
- AddHandler btnGreen.Click, AddressOf ColorButton_Click
- AddHandler btnBold.Click, AddressOf BtnBold_Click
- AddHandler btnItalic.Click, AddressOf BtnItalic_Click
- AddHandler btnUnderline.Click, AddressOf BtnUnderline_Click
- AddHandler Me.FormClosing, AddressOf TmEditor_FormClosing
- AddHandler AutoSaveTimer.Tick, AddressOf AutoSaveTimer_Tick
- AddHandler HighlightTimer.Tick, AddressOf HighlightTimer_Tick
- AddHandler TxtEditor.KeyDown, AddressOf TxtEditor_KeyDown ' KeyDown-Ereignishandler hinzufügen
- ' Ereignishandler für Textänderungen und Link-Klicks
- AddHandler TxtEditor.TextChanged, AddressOf TxtEditor_TextChanged
- AddHandler TxtEditor.LinkClicked, AddressOf TxtEditor_LinkClicked
- ' Schriftgröße und Schriftart standardmäßig auswählen
- cmbFontSize.SelectedIndex = 3 ' Standardgröße: 12
- cmbFontFamily.SelectedItem = "Arial" ' Standardschriftart: Arial
- ' Eigenschaften setzen
- With TxtEditor
- .Multiline = True
- .AllowDrop = True
- ' Standard-Schriftgröße und Schriftart festlegen
- .Font = New Font(cmbFontFamily.SelectedItem.ToString(), CInt(cmbFontSize.SelectedItem), FontStyle.Regular)
- End With
- ' RichTextBox dem Formular hinzufügen
- Me.Controls.Add(TxtEditor)
- ' Gespeicherte Einstellungen laden
- LoadSettings()
- ' Highlight Timer konfigurieren
- HighlightTimer.Interval = 5000 ' 5 Sekunden
- ' Prüfe, ob beim Start des Programms eine Datei als Argument übergeben wurde
- If My.Application.CommandLineArgs.Count > 0 Then
- ' Wenn ja, rufe LoadFileToRichTextBox mit dem Pfad der übergebenen Datei auf
- Dim filePath As String = My.Application.CommandLineArgs(0)
- LoadFileToRichTextBox(filePath)
- End If
- SetProgramIcon()
- ' Wörterbuch aus Datei laden
- Dim wörterbuchDateiPfad As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "de_DE.txt")
- ' Debug-Ausgabe des Pfads zur Laufzeit
- MessageBox.Show("Verwendeter Pfad zur Wörterbuchdatei: " & wörterbuchDateiPfad, "Debug-Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
- If File.Exists(wörterbuchDateiPfad) Then
- LeseWörterbuchAusDatei(wörterbuchDateiPfad)
- Else
- MessageBox.Show("Die Wörterbuchdatei wurde nicht gefunden. Bitte überprüfen Sie den Pfad.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End If
- End Sub
- ' Ereignishandler für Textänderungen
- Private Sub TxtEditor_TextChanged(sender As Object, e As EventArgs) Handles TxtEditor.TextChanged
- MarkiereHyperlinks()
- End Sub
- ' Methode zum Setzen des Programmicons
- Private Sub SetProgramIcon()
- Dim iconPath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\texteditor.ico")
- Try
- If File.Exists(iconPath) Then
- Me.Icon = New Icon(iconPath)
- End If
- Catch ex As Exception
- MessageBox.Show("Fehler beim Laden des Programmicons: " & ex.ToString(), "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- ' Dateiformat registrieren
- Private Sub RegisterFileAssociation()
- Dim progId As String = "tmEditor.File"
- Dim appName As String = "TM Editor"
- Dim fileExtension As String = ".tmEditor"
- Try
- ' Registrieren des Dateityps
- Using key As RegistryKey = Registry.ClassesRoot.CreateSubKey(fileExtension)
- key.SetValue("", progId)
- End Using
- Using key As RegistryKey = Registry.ClassesRoot.CreateSubKey(progId)
- key.SetValue("", appName)
- Using iconKey As RegistryKey = key.CreateSubKey("DefaultIcon")
- iconKey.SetValue("", IconPath)
- End Using
- Using shellKey As RegistryKey = key.CreateSubKey("shell\open\command")
- shellKey.SetValue("", """" & Application.ExecutablePath & """ ""%1""")
- End Using
- End Using
- ' Aktualisieren des Windows Explorers
- SHChangeNotify(&H8000000, &H0, IntPtr.Zero, IntPtr.Zero)
- ' Benachrichtigung anzeigen
- ToolStripLabel1.Text = "Dateizuordnung aktualisiert."
- Catch ex As Exception
- MessageBox.Show("Fehler beim Aktualisieren der Dateizuordnung: " & ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ToolStripLabel1.Text = "Fehler beim Aktualisieren der Dateizuordnung."
- End Try
- End Sub
- Private Sub TmEditor_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
- ' Timer deaktivieren
- AutoSaveTimer.Stop()
- HighlightTimer.Stop()
- ' Speichern von Einstellungen und Daten
- SaveSettings()
- ' Anwendung beenden
- Application.Exit()
- End Sub
- Private Sub AutoSaveTimer_Tick(sender As Object, e As EventArgs) Handles AutoSaveTimer.Tick
- If autoSaveEnabled AndAlso TxtEditor.Rtf <> lastTextBeforeSave Then
- SaveTextToFile(lastFilePath)
- lastTextBeforeSave = TxtEditor.Rtf
- End If
- End Sub
- Private Sub HighlightTimer_Tick(sender As Object, e As EventArgs) Handles HighlightTimer.Tick
- RemoveHighlightColor(RichTextBoxFinds.None)
- End Sub
- Private Sub LoadSettings()
- ' Zuletzt ausgewählte Schriftgröße laden
- If My.Settings.FontSize >= 0 AndAlso My.Settings.FontSize < fontSizes.Count Then
- cmbFontSize.SelectedIndex = My.Settings.FontSize
- End If
- ' Zuletzt ausgewählte Schriftart laden
- If cmbFontFamily.Items.Count > 0 AndAlso Not String.IsNullOrEmpty(My.Settings.SelectedFont) AndAlso cmbFontFamily.Items.Contains(My.Settings.SelectedFont) Then
- cmbFontFamily.SelectedItem = My.Settings.SelectedFont
- End If
- ' Zuletzt ausgewählte Farbe laden
- selectedColor = My.Settings.SelectedColor
- ' Zuletzt geöffneten Pfad laden
- lastFilePath = My.Settings.LastFilePath
- End Sub
- Private Sub SaveSettings()
- ' Zuletzt ausgewählte Schriftgröße speichern
- My.Settings.FontSize = cmbFontSize.SelectedIndex
- ' Zuletzt ausgewählte Schriftart speichern, falls vorhanden
- If cmbFontFamily.SelectedItem IsNot Nothing Then
- My.Settings.SelectedFont = cmbFontFamily.SelectedItem.ToString()
- End If
- ' Zuletzt ausgewählte Farbe speichern
- My.Settings.SelectedColor = selectedColor
- ' Zuletzt geöffneten Pfad speichern
- My.Settings.LastFilePath = lastFilePath
- ' Einstellungen speichern
- My.Settings.Save()
- End Sub
- Private Sub CmbFontSize_SelectedIndexChanged(sender As Object, e As EventArgs)
- ' Schriftgröße ändern
- If cmbFontSize.SelectedIndex >= 0 AndAlso cmbFontSize.SelectedIndex < fontSizes.Count Then
- Dim newSize As Integer = fontSizes(cmbFontSize.SelectedIndex)
- TxtEditor.SelectionFont = New Font(TxtEditor.SelectionFont.FontFamily, newSize, TxtEditor.SelectionFont.Style)
- End If
- End Sub
- Private Sub CmbFontFamily_SelectedIndexChanged(sender As Object, e As EventArgs)
- ' Schriftart ändern
- If cmbFontFamily.SelectedItem IsNot Nothing Then
- Dim newFont As String = cmbFontFamily.SelectedItem.ToString()
- TxtEditor.SelectionFont = New Font(newFont, TxtEditor.SelectionFont.Size, TxtEditor.SelectionFont.Style)
- End If
- End Sub
- Private Sub ColorButton_Click(sender As Object, e As EventArgs)
- ' Schriftfarbe ändern
- Dim btn As Button = DirectCast(sender, Button)
- Select Case btn.Name
- Case "btnBlack"
- selectedColor = Color.Black
- Case "btnRed"
- selectedColor = Color.Red
- Case "btnBlue"
- selectedColor = Color.Blue
- Case "btnGreen"
- selectedColor = Color.Green
- End Select
- TxtEditor.SelectionColor = selectedColor
- End Sub
- Private Sub BtnBold_Click(sender As Object, e As EventArgs)
- ' Fettstil ändern
- If TxtEditor.SelectionFont IsNot Nothing Then
- Dim currentFont As Font = TxtEditor.SelectionFont
- Dim newFontStyle As FontStyle = If(currentFont.Bold, currentFont.Style Xor FontStyle.Bold, currentFont.Style Or FontStyle.Bold)
- TxtEditor.SelectionFont = New Font(currentFont.FontFamily, currentFont.Size, newFontStyle)
- End If
- End Sub
- Private Sub BtnItalic_Click(sender As Object, e As EventArgs)
- ' Kursivstil ändern
- If TxtEditor.SelectionFont IsNot Nothing Then
- Dim currentFont As Font = TxtEditor.SelectionFont
- Dim newFontStyle As FontStyle = If(currentFont.Italic, currentFont.Style Xor FontStyle.Italic, currentFont.Style Or FontStyle.Italic)
- TxtEditor.SelectionFont = New Font(currentFont.FontFamily, currentFont.Size, newFontStyle)
- End If
- End Sub
- Private Sub BtnUnderline_Click(sender As Object, e As EventArgs)
- ' Unterstrichenstil ändern
- If TxtEditor.SelectionFont IsNot Nothing Then
- Dim currentFont As Font = TxtEditor.SelectionFont
- Dim newFontStyle As FontStyle = If(currentFont.Underline, currentFont.Style Xor FontStyle.Underline, currentFont.Style Or FontStyle.Underline)
- TxtEditor.SelectionFont = New Font(currentFont.FontFamily, currentFont.Size, newFontStyle)
- End If
- End Sub
- Private Sub RemoveHighlightColor(richTextBoxFinds As RichTextBoxFinds)
- ' Alle markierten Textstellen ohne Hervorhebungsfarbe zurücksetzen
- Dim startPosition As Integer = 0
- While True
- Dim indexOfStart As Integer = TxtEditor.Find("^[A-Za-z0-9äöüÄÖÜß]+$", startPosition, richTextBoxFinds)
- If indexOfStart < 0 Then Exit While
- TxtEditor.SelectionStart = indexOfStart
- TxtEditor.SelectionLength = 0
- TxtEditor.SelectionColor = Color.Black
- startPosition = indexOfStart + 1
- End While
- End Sub
- Private Sub SpeichernToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SpeichernToolStripMenuItem1.Click
- Dim saveDialog As New SaveFileDialog With {
- .Filter = "RTF-Dateien (*.rtf)|*.rtf|Textdateien (*.txt)|*.txt|tmEditor Dateien (*.tmEditor)|*.tmEditor"
- }
- If saveDialog.ShowDialog() = DialogResult.OK Then
- lastFilePath = saveDialog.FileName
- SaveTextToFile(lastFilePath)
- Me.Text = Path.GetFileName(lastFilePath) & " - tmEditor"
- ToolStripLabel1.Text = "Dokument wurde gespeichert."
- Else
- ToolStripLabel1.Text = "Speichern abgebrochen."
- End If
- End Sub
- Private Sub ÖffnenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ÖffnenToolStripMenuItem1.Click
- Dim openFileDialog As New OpenFileDialog With {
- .Filter = "RTF-Dateien (*.rtf)|*.rtf|Textdateien (*.txt)|*.txt|tmEditor Dateien (*.tmEditor)|*.tmEditor"
- }
- If openFileDialog.ShowDialog() = DialogResult.OK Then
- lastFilePath = openFileDialog.FileName
- Try
- If openFileDialog.FileName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) Then
- TxtEditor.LoadFile(openFileDialog.FileName, RichTextBoxStreamType.PlainText)
- ElseIf openFileDialog.FileName.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase) Then
- TxtEditor.LoadFile(openFileDialog.FileName)
- ElseIf openFileDialog.FileName.EndsWith(".tmEditor", StringComparison.OrdinalIgnoreCase) Then
- TxtEditor.LoadFile(openFileDialog.FileName)
- Else
- ToolStripLabel1.Text = "Das Dateiformat wird nicht unterstützt."
- Exit Sub
- End If
- Me.Text = Path.GetFileName(lastFilePath) & " - tmEditor"
- ToolStripLabel1.Text = "Dokument wurde geöffnet."
- ' Rechtschreibprüfung durchführen
- ÜberprüfeRechtschreibung()
- Catch ex As Exception
- ToolStripLabel1.Text = "Fehler beim Öffnen der Datei: " & ex.Message
- End Try
- Else
- ToolStripLabel1.Text = "Öffnen abgebrochen."
- End If
- End Sub
- Private Sub BildAusDateiToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BildAusDateiToolStripMenuItem.Click
- Dim openFileDialog As New OpenFileDialog With {
- .Filter = "Bilddateien|*.bmp;*.jpg;*.jpeg;*.gif;*.png",
- .Title = "Bild auswählen"
- }
- If openFileDialog.ShowDialog() = DialogResult.OK Then
- Dim imagePath As String = openFileDialog.FileName
- InsertImage(imagePath)
- ' Status-Text anzeigen
- ToolStripLabel1.Text = "Bild wurde eingefügt."
- End If
- End Sub
- Private Sub InsertImage(imagePath As String)
- Try
- Dim originalImage As Image = Image.FromFile(imagePath)
- Dim scaleFactor As Single = 0.5 ' Skalierungsfaktor (0.5 bedeutet 50% der Originalgröße)
- Dim scaledWidth As Integer = CInt(originalImage.Width * scaleFactor)
- Dim scaledHeight As Integer = CInt(originalImage.Height * scaleFactor)
- Dim scaledImage As Image = originalImage.GetThumbnailImage(scaledWidth, scaledHeight, Nothing, IntPtr.Zero)
- Clipboard.SetDataObject(scaledImage)
- ' Bild einfügen
- TxtEditor.Paste(DataFormats.GetFormat(DataFormats.Bitmap))
- ' Markierten Text löschen und neuen Zeilenumbruch einfügen
- TxtEditor.SelectedText = ""
- TxtEditor.SelectedRtf = "{\rtf1\par}"
- Catch ex As Exception
- MessageBox.Show("Fehler beim Einfügen des Bildes: " & ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- Private Sub SaveTextToFile(filePath As String)
- If Not String.IsNullOrEmpty(filePath) Then
- Try
- If filePath.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) Then
- ' Speichern als TXT-Datei
- TxtEditor.SaveFile(filePath, RichTextBoxStreamType.PlainText)
- ElseIf filePath.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase) Then
- ' Speichern als RTF-Datei
- TxtEditor.SaveFile(filePath)
- ElseIf filePath.EndsWith(".tmEditor", StringComparison.OrdinalIgnoreCase) Then
- ' Speichern als TM Editor-Datei
- TxtEditor.SaveFile(filePath)
- Else
- MessageBox.Show("Das Dateiformat wird nicht unterstützt.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ' Status-Text anzeigen
- ToolStripLabel1.Text = "Speichern fehlgeschlagen: Nicht unterstütztes Dateiformat."
- Exit Sub
- End If
- ' Status-Text anzeigen
- ToolStripLabel1.Text = "Dokument wurde gespeichert."
- Catch ex As Exception
- MessageBox.Show("Fehler beim Speichern der Datei: " & ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ' Status-Text anzeigen
- ToolStripLabel1.Text = "Speichern fehlgeschlagen."
- End Try
- Else
- SpeichernToolStripMenuItem_Click(Nothing, Nothing)
- End If
- End Sub
- Private Sub NewDocument()
- TxtEditor.Clear()
- End Sub
- Private Sub NeuToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NeuToolStripMenuItem1.Click
- ' Neues Dokument erstellen
- NewDocument()
- ' Status-Text anzeigen
- ToolStripLabel1.Text = "Neues Dokument wurde erstellt."
- End Sub
- Private Sub TbZoomIn_Click(sender As Object, e As EventArgs) Handles tbZoomIn.Click
- If TxtEditor.ZoomFactor = 63 Then
- Exit Sub
- Else
- TxtEditor.ZoomFactor = TxtEditor.ZoomFactor + 1
- End If
- End Sub
- Private Sub TbZoomOut_Click(sender As Object, e As EventArgs) Handles tbZoomOut.Click
- If TxtEditor.ZoomFactor = 1 Then
- Exit Sub
- Else
- TxtEditor.ZoomFactor = TxtEditor.ZoomFactor - 1
- End If
- End Sub
- ' Ereignishandler für Tastatureingaben hinzufügen
- Private Sub TxtEditor_KeyDown(sender As Object, e As KeyEventArgs) Handles TxtEditor.KeyDown
- If e.Control Then
- If e.KeyCode = Keys.Oemplus Then
- TbZoomIn_Click(Nothing, Nothing)
- ElseIf e.KeyCode = Keys.OemMinus Then
- TbZoomOut_Click(Nothing, Nothing)
- End If
- End If
- lblCharacterCount.Text = "Zeichenanzahl: " & TxtEditor.TextLength.ToString()
- If e.KeyCode = Keys.F7 Then
- ' F7 zum Überprüfen der Rechtschreibung
- ÜberprüfeRechtschreibung()
- e.SuppressKeyPress = True
- End If
- End Sub
- Private Sub BtnJustify_Click(sender As Object, e As EventArgs) Handles btnJustify.Click
- TxtEditor.SelectionAlignment = HorizontalAlignment.Left
- End Sub
- Private Sub BtnCenterAlign_Click(sender As Object, e As EventArgs) Handles btnCenterAlign.Click
- TxtEditor.SelectionAlignment = HorizontalAlignment.Center
- End Sub
- Private Sub BtnRightAlign_Click(sender As Object, e As EventArgs) Handles btnRightAlign.Click
- TxtEditor.SelectionAlignment = HorizontalAlignment.Right
- End Sub
- Private Sub Suchen_Click(sender As Object, e As EventArgs) Handles Suchen.Click
- If Not String.IsNullOrEmpty(txtSearch.Text) Then
- Dim searchStart As Integer = TxtEditor.SelectionStart + TxtEditor.SelectionLength
- Dim index As Integer = TxtEditor.Find(txtSearch.Text, searchStart, RichTextBoxFinds.None)
- If index <> -1 Then
- ' Text gefunden
- TxtEditor.Select(index, txtSearch.Text.Length)
- TxtEditor.ScrollToCaret()
- TxtEditor.Focus()
- txtSearch.Text = ""
- Else
- MessageBox.Show("Text nicht gefunden.", "Suchen", MessageBoxButtons.OK, MessageBoxIcon.Information)
- End If
- End If
- End Sub
- Private Sub TxtSearch_KeyDown(sender As Object, e As KeyEventArgs) Handles txtSearch.KeyDown
- If e.KeyCode = Keys.Enter Then
- Suchen.PerformClick()
- End If
- End Sub
- Private Sub LoadFileToRichTextBox(filePath As String)
- ' Dateiinhalt in die RichTextBox laden
- If File.Exists(filePath) Then
- Dim fileContent As String = File.ReadAllText(filePath)
- TxtEditor.Rtf = fileContent ' Annahme: Die Datei enthält RTF-formatierten Text
- End If
- End Sub
- Private Function GetDebuggerDisplay() As String
- Return ToString()
- End Function
- Private Sub BeendenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BeendenToolStripMenuItem.Click
- Application.Exit()
- End Sub
- End Class
Wie man mich kontaktieren kann:
thiemo-melhorn.de
thiemo-melhorn.de
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Thiemo1991“ ()