Results 1 to 5 of 5

Thread: Label inside a Textbox or RichTextBox

  1. #1

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Label inside a Textbox or RichTextBox

    Hello everyone..
    Im trying to place labels inside a textbox(or richtextbox) dynamically whenever the user right clicks on a paticular place.I want to dynamically add the label where the user right clicks.And i want the label to move if he places the cursor behind the label and presses spacebar or even if he presses backspace.
    I hope somebody can understand what I mean.
    Please help me with this..
    Thanks so much



    Edit:I have tried....but the basic problem im facing is when i try to move the control dynamically by pressing space or backspace.
    After placing the label inside the textbox,the text gets hidden behind the label instead of pushing the label to the side.
    I want to know what logic can be used to automatically make the text typed to move the label.

    An example of this: Place a picture in Microsoft word...place the cursor before it and type,...you'll notice the picture moving forward as you type.If you press backspace,the picture moves backwards.
    Last edited by uniquegodwin; Nov 14th, 2006 at 06:13 AM.
    Godwin

    Help someone else with what someone helped you!

  2. #2
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Exclamation Re: Label inside a Textbox or RichTextBox

    TextBoxes are not containers. Therefore a Label cannot be contained inside of it.
    ~Peter


  3. #3
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: Label inside a Textbox or RichTextBox

    You can insert pictures in richtextboxes.
    VB 2005, Win Xp Pro sp2

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Label inside a Textbox or RichTextBox

    Hi, try this code.... You can work on it some more to get the effects you want. It's just to show you the principles....
    You'll need a form with a Richtextbox on it.
    VB Code:
    1. Private myLabel As Label = Nothing
    2.     Private Sub Form1_Load(ByVal sender As System.Object, _
    3.                 ByVal e As System.EventArgs) Handles MyBase.Load
    4.         'Dynamically create a label and add it to richtextbox1
    5.         myLabel = New Label
    6.         With myLabel
    7.             .Text = "This is a label"
    8.             .Size = New Size(80, 25)
    9.             .Location = New Point(71, 92)
    10.             .Name = "Label1"
    11.             .BackColor = Color.Red
    12.         End With
    13.         RichTextBox1.Controls.Add(myLabel)
    14.     End Sub
    15.  
    16.     Private Sub RichTextBox1_KeyDown(ByVal sender As Object, _
    17.                     ByVal e As System.Windows.Forms.KeyEventArgs) _
    18.                     Handles RichTextBox1.KeyDown
    19.         Dim g As Graphics = RichTextBox1.CreateGraphics
    20.         Dim size As Drawing.SizeF = g.MeasureString(RichTextBox1.Text, RichTextBox1.Font, CType(RichTextBox1.Size, Drawing.SizeF))
    21.         If e.KeyCode = Keys.Enter Then
    22.             myLabel.Location = New Point(0, size.ToPointF.Y)
    23.         Else
    24.             myLabel.Location = New Point(size.ToPointF.X, size.ToPointF.Y)
    25.         End If
    26.     End Sub

  5. #5

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Label inside a Textbox or RichTextBox

    Hello everyone,
    Thanks so muchhh []
    Godwin

    Help someone else with what someone helped you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width