showing image on label.
-
Hello All, I have a situation here where in i have to concatenate an icon to the label text based on some information. As we have already set the image property i cannot go ahead with the image align property as it will align the image attached to the image property. I am trying here to add an icon or image to the end of the text. Thanks in Advance Bharath s Ron
-
Hello All, I have a situation here where in i have to concatenate an icon to the label text based on some information. As we have already set the image property i cannot go ahead with the image align property as it will align the image attached to the image property. I am trying here to add an icon or image to the end of the text. Thanks in Advance Bharath s Ron
class Program
{
static void Main(string[] args)
{
using (var f = new Form())
{
var lbl = new Label();
lbl.Text = "Hello world";
lbl.Image = f.Icon.ToBitmap();
lbl.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
f.Controls.Add(lbl);
f.ShowDialog();
}
}
}Ron.bharath wrote:
i cannot go ahead with the image align property as it will align the image attached to the image property.
That's what you asked; put the image in the label, on the right side of the text. If you want something else, you'd have to specify 'what' you want a bit more clearly. You could add a PictureBox on the right next to the label (concatenating controls, not data), but that would be less efficient.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Hello All, I have a situation here where in i have to concatenate an icon to the label text based on some information. As we have already set the image property i cannot go ahead with the image align property as it will align the image attached to the image property. I am trying here to add an icon or image to the end of the text. Thanks in Advance Bharath s Ron
At design-time you have several choices ... if your Label, and whatever graphic element object, is going to remain the same size at run-time no matter how its containing Control, or Form, is re-sized, and if your Label content, and the graphic content object, is not going to change: 1. you can position the Icon, or PictureBox, over the end of the Label Text. 2. you could create a custom UserControl combining a Label and a graphic element object, and design it to look "right." If you are talking about creating text, and a graphic element, at run-time, or having text, or graphic, that changes at run-time, the problems of alignment become significant. You can, in fact, insert a graphic object into the Controls Collection of a Label (or other Win Forms Control); you can't do that at design-time unless you modify the Designer.cs file yourself, which is not something recommended to do. Once you have a graphic element "inside" a Label's DisplayRectangle, you may have the same problems of alignment/positioning you would have at design-time. An alternative you could consider would be using a RichTextBox instead of a Label, where the insertion of graphic elements ... while not simple ... is more straightforward in that they can be placed in the "flow" of the text layout, and, in a RichTextBox calculation of the co-ordinates of the current end of the text content is much easier. What have you tried so far ? And, is what you need to do to be done at run-time with changing content for both Label Text, and the related graphic element ?
“I'm an artist: it's self evident that word implies looking for something all the time without ever finding it in full. It is the opposite of saying : 'I know all about it. I've already found it.' As far as I'm concerned, the word means: 'I am looking. I am hunting for it. I am deeply involved.'” Vincent Van Gogh
-
class Program
{
static void Main(string[] args)
{
using (var f = new Form())
{
var lbl = new Label();
lbl.Text = "Hello world";
lbl.Image = f.Icon.ToBitmap();
lbl.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
f.Controls.Add(lbl);
f.ShowDialog();
}
}
}Ron.bharath wrote:
i cannot go ahead with the image align property as it will align the image attached to the image property.
That's what you asked; put the image in the label, on the right side of the text. If you want something else, you'd have to specify 'what' you want a bit more clearly. You could add a PictureBox on the right next to the label (concatenating controls, not data), but that would be less efficient.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
Upvoted. Good answer: I had assumed the OP found that using the Image property of the Label, and ContentAlignment, didn't meet his needs, which may not be the case, here.
“I'm an artist: it's self evident that word implies looking for something all the time without ever finding it in full. It is the opposite of saying : 'I know all about it. I've already found it.' As far as I'm concerned, the word means: 'I am looking. I am hunting for it. I am deeply involved.'” Vincent Van Gogh
-
At design-time you have several choices ... if your Label, and whatever graphic element object, is going to remain the same size at run-time no matter how its containing Control, or Form, is re-sized, and if your Label content, and the graphic content object, is not going to change: 1. you can position the Icon, or PictureBox, over the end of the Label Text. 2. you could create a custom UserControl combining a Label and a graphic element object, and design it to look "right." If you are talking about creating text, and a graphic element, at run-time, or having text, or graphic, that changes at run-time, the problems of alignment become significant. You can, in fact, insert a graphic object into the Controls Collection of a Label (or other Win Forms Control); you can't do that at design-time unless you modify the Designer.cs file yourself, which is not something recommended to do. Once you have a graphic element "inside" a Label's DisplayRectangle, you may have the same problems of alignment/positioning you would have at design-time. An alternative you could consider would be using a RichTextBox instead of a Label, where the insertion of graphic elements ... while not simple ... is more straightforward in that they can be placed in the "flow" of the text layout, and, in a RichTextBox calculation of the co-ordinates of the current end of the text content is much easier. What have you tried so far ? And, is what you need to do to be done at run-time with changing content for both Label Text, and the related graphic element ?
“I'm an artist: it's self evident that word implies looking for something all the time without ever finding it in full. It is the opposite of saying : 'I know all about it. I've already found it.' As far as I'm concerned, the word means: 'I am looking. I am hunting for it. I am deeply involved.'” Vincent Van Gogh
The text and the image changes at runtime. I have tried drawing the image using graphics but i could not figure out how to repaint the image with another or erase only the image on the label.