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. Focus in RichTextBox

Focus in RichTextBox

Scheduled Pinned Locked Moved Visual Basic
question
2 Posts 2 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 have a dynamically created RichTextBox that is created in the forms "OnLoad" event. For some reason it will not set the focus of the cursor inside the Text area. Once the program is running and I use the same code again it creates a new one and automatically sets the cursor inside it. What is wrong? Dim rtbTextArea As New RichTextBox Dim newTab As New TabPage Dim newTime As Date = Now.ToString 'Set newtime to system time and date Dim strNewTime As String = newTime 'convert newTime to string TabControl1.TabPages.Add(newTab) 'Add new Tab Page to tab control TabControl1.SelectedTab = newTab With newTab .Text = strNewTime 'Set Tab Page text to System date and Time .Controls.Add(rtbTextArea) 'Add the rich text Box to the new tab control With rtbTextArea .Dock = DockStyle.Fill 'Set Rich Text box area to fill tab page .ContextMenuStrip = ContextMenuStrip1 .AcceptsTab = True .Focus() End With AddHandler rtbTextArea.SelectionChanged, AddressOf SelFontChk 'Assign SelctionChange Event Handler End With Thanks in advance Thanks, Taen Karth

    S 1 Reply Last reply
    0
    • T Taen_Karth

      I have a dynamically created RichTextBox that is created in the forms "OnLoad" event. For some reason it will not set the focus of the cursor inside the Text area. Once the program is running and I use the same code again it creates a new one and automatically sets the cursor inside it. What is wrong? Dim rtbTextArea As New RichTextBox Dim newTab As New TabPage Dim newTime As Date = Now.ToString 'Set newtime to system time and date Dim strNewTime As String = newTime 'convert newTime to string TabControl1.TabPages.Add(newTab) 'Add new Tab Page to tab control TabControl1.SelectedTab = newTab With newTab .Text = strNewTime 'Set Tab Page text to System date and Time .Controls.Add(rtbTextArea) 'Add the rich text Box to the new tab control With rtbTextArea .Dock = DockStyle.Fill 'Set Rich Text box area to fill tab page .ContextMenuStrip = ContextMenuStrip1 .AcceptsTab = True .Focus() End With AddHandler rtbTextArea.SelectionChanged, AddressOf SelFontChk 'Assign SelctionChange Event Handler End With Thanks in advance Thanks, Taen Karth

      S Offline
      S Offline
      Steve Pullan
      wrote on last edited by
      #2

      You can't SetFocus to a control until the form is displayed (i.e. active). If you want the control to have the focus when the form is initially displayed, set the control's TabIndex property to 0 (zero). ...Steve

      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