|
-
Nov 14th, 2006, 06:04 AM
#1
Thread Starter
Fanatic Member
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! 
-
Nov 14th, 2006, 02:41 PM
#2
Frenzied Member
Re: Label inside a Textbox or RichTextBox
TextBoxes are not containers. Therefore a Label cannot be contained inside of it.
~Peter

-
Nov 14th, 2006, 03:53 PM
#3
Re: Label inside a Textbox or RichTextBox
You can insert pictures in richtextboxes.
-
Nov 14th, 2006, 04:46 PM
#4
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
-
Nov 21st, 2006, 09:42 PM
#5
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|