Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
75
Icon in Formated ToolTipText
posted

I use the UltraToolTipManagerUltraToolTipInfo to show ToolTips on my Grid. I set the TooTipTextStyle to ToolTipTextStyle.Formatted because i want to display text and several images on different locations in the ToolTip.

For excample like that:

ultraToolTipInfo1.ToolTipTextFormatted = @"TEXT<img style=""width:16px; height:16px;"" data=""" + imageAsText + @"""/>";

I have the image loaded into an Image object with:

Image image = Image.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("TestApplication.Icon1.ico"));

How can i get the needed Image as a  string from the Image object?? I tried Convert.ToBase64String() but that results not in the correct string that will be rendered in the ToolTip.

string imageAsText =@"AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0yLjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA9wAAAAKJUE5HDQoaCgAAAA1JSERSAAAAEAAAABAIBgAAAB/z/2EAAAABc1JHQgCuzhzpAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAdUlEQVQ4T+1T0QqAMAjc/txP889qB7uSOF1BvTWQ6ZTzdNrbPGa2Ua/uEdelHwDxuPthUkdMmuguAFAlCB6RqZJBHWVGOashA9IEUKaDxQR6GWBVQvR/w4AdZkMf9+AvYb0LaDL3Iv1GbpBaphJAzPl17pXddulGKiWnEKT+AAAAAElFTkSuQmCCCwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";

Parents
No Data
Reply
  • 37774
    Verified Answer
    posted

    There is not a really simple/efficient want of doing this from an embedded resource in an assembly because the "data" attribute is expecting the serialized image information, which is not the same as the string representation of the bytes of the image.  If you were using an UltraFormattedTextEditor, you could use the EditInfo.EncodeImage() method in order to get the string that you would place in the data tag, but in this case you would have to do the logic yourself:

    string imageAsText = null;
    using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(typeof(Form1), "image.jpg"))
    {
        byte[ buffer = new byte[stream.Length];
        stream.Read(buffer, 0, (int)stream.Length);

        BinaryFormatter formatter = new BinaryFormatter();
        using (MemoryStream ms = new MemoryStream())
        {
            formatter.Serialize(ms, Image.FromStream(stream));
            ms.Position = 0;
            byte[ bytes = ms.GetBuffer();
            imageAsText = Convert.ToBase64String(bytes);
        }
    }

    As you can tell from the code, you have to read in the image from the assembly, convert it to an image, then serialize it into a different string in order to get the expected value; as I had mentioned, this attribute is designed for serializing the formatted information so it can be read later.  The other alternative here is to not use an embedded resource and instead specify the path to the image.

    -Matt 

Children
No Data