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.
Re: Label inside a Textbox or RichTextBox
TextBoxes are not containers. Therefore a Label cannot be contained inside of it.
Re: Label inside a Textbox or RichTextBox
You can insert pictures in richtextboxes.
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:
Private myLabel As Label = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Dynamically create a label and add it to richtextbox1
myLabel = New Label
With myLabel
.Text = "This is a label"
.Size = New Size(80, 25)
.Location = New Point(71, 92)
.Name = "Label1"
.BackColor = Color.Red
End With
RichTextBox1.Controls.Add(myLabel)
End Sub
Private Sub RichTextBox1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles RichTextBox1.KeyDown
Dim g As Graphics = RichTextBox1.CreateGraphics
Dim size As Drawing.SizeF = g.MeasureString(RichTextBox1.Text, RichTextBox1.Font, CType(RichTextBox1.Size, Drawing.SizeF))
If e.KeyCode = Keys.Enter Then
myLabel.Location = New Point(0, size.ToPointF.Y)
Else
myLabel.Location = New Point(size.ToPointF.X, size.ToPointF.Y)
End If
End Sub
Re: Label inside a Textbox or RichTextBox
Hello everyone,
Thanks so muchhh [:)]