Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo,

wie kann ich in Visual Basic bei einer Richtextbox den vom Benutzer ausgewählten Text formatieren (z.B. kursiv schreiben)?

Habe zwar Anleitungen im Internet gefunden allerdings funktionieren diese nicht. Da Microsoft.Interop.Word.Font nicht in System.Drawing umgewandelt werden könnte.

Hi,

das stichwort heißt SelectionFont.

In deinem Kursivbutton sieht das wie folgt aus:


Dim font as System.Drawing.Font = Richtextboxvariablenname.SelectionFont

Richtextboxvariablenname.SelectionFont = new System.Drawing.Font(font.FontFamily, font.Size,font.Style ^ FontStyle.Italic, GraphicsUnit.Point)

Ich weiß jetzt auf die schnelle nicht wie der Xor Operator in VB.net geht.

Must du mal googlen und ^ gegebenenfalls dahingehend ändern.

lg

Gateway

PS:

Kleiner Warnhinweis.

Wenn der selektierte Text verschiedenene Schritarten, Größen oder Styles hat, dann liefert SelectionFont Null oder in deinem Fall Nothing zurück. Also würd ich mich hier noch um ein entsprechendes Handling kümmern.

Bearbeitet von Gateway_man

Echt genial vielen Dank :-)) in VB.net kann man direkt Xor schreiben :-)

Hallo

da ich mich damit unter VB.NET auch schon rumgeschlagen habe geb ich dir noch einen Tipp dazu.

Ich bin wie folgt vorgegangen:

1. Markierung merken


        Dim intBeginSel As Integer = Me.rtf_Text.SelectionStart

        Dim intAnzahlSel As Integer = Me.rtf_Text.SelectionLength

        Dim intEndeSel As Integer = intBeginSel + Me.rtf_Text.SelectionLength

2. FontStyle ermitteln

        '

        Dim FirstFont As System.Drawing.Font = Me.rtf_Text.SelectionFont

        Dim currentFont As System.Drawing.Font = Me.rtf_Text.SelectionFont

        Dim newFontStyle As System.Drawing.FontStyle

3. Buchstabe für Buchstabe Neu Formatieren (Beispiel hier "Bold")

        While intZaehler <= intEndeSel - 1

            Me.rtf_Text.Select(intZaehler, 1)

            currentFont = Me.rtf_Text.SelectionFont

            If FirstFont.Bold = True Then

                newFontStyle = currentFont.Style - Drawing.FontStyle.Bold

            Else

                If currentFont.Bold = False Then

                    newFontStyle = currentFont.Style + Drawing.FontStyle.Bold

                End If


            End If

            Me.rtf_Text.SelectionFont = New Drawing.Font(currentFont.FontFamily,  currentFont.Size, newFontStyle)

            intZaehler += 1

        End While

Gruß Hans-Jörg

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.