Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. RichTextBox FontStyles

RichTextBox FontStyles

Scheduled Pinned Locked Moved Visual Basic
helpquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Taen_Karth
    wrote on last edited by
    #1

    I am trying to apply different FontStyles to text within a RichtextBox control that was dynamically created. For some reason I do not get the .Selection??? anything Methods on a dynamically created control. All I have been able to successfully do is all or nothing. Here is the code I have been working with: Try If tsbBold.Checked = False Then tsbBold.Checked = True For Each ctl As Control In TabControl1.SelectedTab.Controls If TypeOf ctl Is RichTextBox Then Dim selBold As New Font(ctl.Font, FontStyle.Bold) ctl.Font = selBold End If Next ElseIf tsbBold.Checked = True Then tsbBold.Checked = False For Each ctl As Control In TabControl1.SelectedTab.Controls If TypeOf ctl Is RichTextBox Then Dim selNotBold As New Font(ctl.Font, FontStyle.Regular) ctl.Font = selNotBold End If Next End If Catch ex As Exception MessageBox.Show(MsgBoxStyle.Exclamation, "An error has occured. Please try your selection again") End Try Any suggestions? Thanks, Taen Karth

    T 1 Reply Last reply
    0
    • T Taen_Karth

      I am trying to apply different FontStyles to text within a RichtextBox control that was dynamically created. For some reason I do not get the .Selection??? anything Methods on a dynamically created control. All I have been able to successfully do is all or nothing. Here is the code I have been working with: Try If tsbBold.Checked = False Then tsbBold.Checked = True For Each ctl As Control In TabControl1.SelectedTab.Controls If TypeOf ctl Is RichTextBox Then Dim selBold As New Font(ctl.Font, FontStyle.Bold) ctl.Font = selBold End If Next ElseIf tsbBold.Checked = True Then tsbBold.Checked = False For Each ctl As Control In TabControl1.SelectedTab.Controls If TypeOf ctl Is RichTextBox Then Dim selNotBold As New Font(ctl.Font, FontStyle.Regular) ctl.Font = selNotBold End If Next End If Catch ex As Exception MessageBox.Show(MsgBoxStyle.Exclamation, "An error has occured. Please try your selection again") End Try Any suggestions? Thanks, Taen Karth

      T Offline
      T Offline
      Taen_Karth
      wrote on last edited by
      #2

      Nevermind I figured out a way to work around it by using the following code. Try If tsbBold.Checked = False Then tsbBold.Checked = True For Each ctl As Control In TabControl1.SelectedTab.Controls If TypeOf ctl Is RichTextBox Then Dim rtb As RichTextBox rtb = ctl Dim selBold As New Font(rtb.Font, FontStyle.Bold) rtb.SelectionFont = selBold End If Next ElseIf tsbBold.Checked = True Then tsbBold.Checked = False For Each ctl As Control In TabControl1.SelectedTab.Controls If TypeOf ctl Is RichTextBox Then Dim rtb As RichTextBox rtb = ctl Dim selNotBold As New Font(rtb.Font, FontStyle.Regular) rtb.SelectionFont = selNotBold End If Next End If Catch ex As Exception MessageBox.Show(MsgBoxStyle.Exclamation, "An error has occured. Please try your selection again") End Try If there is a better or easier way please let me know. Thanks, Taen Karth

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups