Image in RadToolStripLabelElement

5 posts, 1 answers
  1. Haroon
    Haroon avatar
    38 posts
    Member since:
    Dec 2007

    Posted 18 Sep 2008 Link to this post

    Hi Telerik Team,
    Please do guide me if I can add an image along with Text in RadToolStripLabelElement? If yes then please guide how can I?
    What a want is to display an image followed by a label at toolstrip (ImageBeforeText )

    Regards,
    Haroon.
  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 19 Sep 2008 Link to this post

    Hi Haroon,

    Thank you for the question.

    You could add images to RadToolStripLabelElement by adding an ImagePrimitive to its children collection. Please, review the code-block below:
     
    private void Form1_Load(object sender, EventArgs e) 
        ImagePrimitive imagePrimitive = new ImagePrimitive(); 
        imagePrimitive.Image = Image.FromFile("c:\\asterisk.jpg"); 
     
        this.radToolStripLabelElement1.Children.Add(imagePrimitive); 

    Note that you have to choose an image with appropriate size.


    Best wishes,
    Martin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Haroon
    Haroon avatar
    38 posts
    Member since:
    Dec 2007

    Posted 21 Sep 2008 Link to this post

    Hi Martin Vasilev,
    Thank you for your quick reply I tried the code, it works fine. But the problem I observed is that the image always overlaps the text of the label. can you please help me in this regard.

    P.S. Please do accept my apologies for posting the question about RadToolStrip in RadTabStrip section, as I just noticed my mistake.

    Regards,
    Haroon.
  5. Answer
    Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 24 Sep 2008 Link to this post

    Hi Haroon,

    Thank you for getting back to me.

    If you want to have a control over the image-text relation you have to use ImageAndTextLayoutPanel. I have extended the previous example code to more complex solution that handle this:
     
    private void Form1_Load(object sender, EventArgs e) 
        ImageAndTextLayoutPanel imageAndTextLayoutPanel = new ImageAndTextLayoutPanel(); 
        imageAndTextLayoutPanel.TextImageRelation = TextImageRelation.ImageBeforeText; 
         
        ImagePrimitive imagePrimitive = new ImagePrimitive(); 
        imagePrimitive.SetValue(ImageAndTextLayoutPanel.IsImagePrimitiveProperty, true); 
        imagePrimitive.Image = Image.FromFile("c:\\asterisk.jpg"); 
     
        TextPrimitive textPrimitive = new TextPrimitive(); 
        textPrimitive.SetValue(ImageAndTextLayoutPanel.IsTextPrimitiveProperty, true); 
        textPrimitive.Text = "Asterisk"
     
        imageAndTextLayoutPanel.Children.Add(imagePrimitive); 
        imageAndTextLayoutPanel.Children.Add(textPrimitive); 
     
        //remove old TextPrimitive 
        this.radToolStripLabelElement1.Children.RemoveAt(0); 
         
        this.radToolStripLabelElement1.Children.Add(imageAndTextLayoutPanel); 

    I hope this suits to your scenario. If you need additional assistance, do not hesitate to contact me again.

    Sincerely yours,
    Martin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Haroon
    Haroon avatar
    38 posts
    Member since:
    Dec 2007

    Posted 24 Sep 2008 Link to this post

    Hi Martin Vasilev,
    Thank you for your reply. Telerik support is always been great (2 Thumbs up)

    Sincerely yours,
    Haroon.
Back to Top
UI for WinForms is Visual Studio 2017 Ready