954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Add a a text line in a specified point: tooltip, labels or textbox?

I need to add a text line in a specified point of a windows form. In this form I draw something and I would like to describe the draw exactly where it is pointed.

Is there a way to add a tooltip in a specified point of a Form?

For example something like:

Point pt = new Point (490,567);
ToolTip tt = new ToolTip();
pt.ToolTip=tt;


Other ways I've tried:

1- Label class, but when I add the control with Controls.Add(label) the system restart execution of the draw, I don't know why.
2- TextBox class, but execution become quite slow when the program add the textbox.

If you have some suggestions also for these 2 other ways it will be so appreciated :)

thanks

samp4ever
Newbie Poster
7 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

Try it this way:

private void button1_Click(object sender, EventArgs e)
        {
            Label l = new Label();
            l.Location = new Point(100, 100);
            l.Text = "This is a text";
            this.Controls.Add(l);
        }
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

Thanks, I've tried this solution and I think is the best one but as I said it has a strange behavior.

I have to draw some shapes and when the shape is drawn I have to put a comment in the point where it starts. The strange behavior of labels is that when the comment is added, the program restart execution of the drawing.. anyone knows why does it happen?

Thanks

samp4ever
Newbie Poster
7 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

where are you writing the code of adding text to the label?

abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
 

While you are busy drawing some shapes, why not use that opportunity to also draw some strings?
http://msdn.microsoft.com/en-us/library/76c5db29.aspx

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 
where are you writing the code of adding text to the label?

I've put the code during the drawing..but the label wait for the drawing then put the label and restart execution..While you are busy drawing some shapes, why not use that opportunity to also draw some strings?
http://msdn.microsoft.com/en-us/library/76c5db29.aspx

That's a great solution thanks ;)

samp4ever
Newbie Poster
7 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

Two snips with examples what you can do when drawing a string, without using label, textbox etc.
http://www.daniweb.com/software-development/csharp/code/231400
http://www.daniweb.com/software-development/csharp/code/227743

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: