RadMessageBox with SVG icon

2 Answers 11 Views
MessageBox
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Toby asked on 17 Apr 2025, 08:19 AM | edited on 17 Apr 2025, 08:19 AM

Is it possible to assign an SVG image to use as the image displayed in the RadMessageBox? 

 

I notice that PictureBox is used rather than RadPictureBox, RadPictureBox supports SVG and it seems that PictureBox does not. Is there a reason why it cannot use RadPictrureBox?

The reason I ask, is that when specifying the image directly, it does not scale nicely when used on monitors with different DPI.

Thanks
Toby

2 Answers, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 17 Apr 2025, 11:40 AM

Hi Toby,

Thank you for the provided image.

By design, the MS PictureBox control is used to show the image in the RadMessageBox control. You can still show an SVG image in the MS PictureBox control. To do that, you can use the following code:

public Form1()
{
    InitializeComponent();
	
    RadMessageBox.Instance.Shown += Instance_Shown;
    DialogResult ds = RadMessageBox.Show(this, "Are you sure?", "Title", MessageBoxButtons.YesNo, RadMessageIcon.Question);
    this.Text = ds.ToString();
}

private void Instance_Shown(object sender, EventArgs e)
{
    var radMessageBoxForm = sender as RadMessageBoxForm;
    (radMessageBoxForm.Controls["pictureBox1"] as PictureBox).Image = LoadSvgAsBitmap("../../MySvgImage.Svg");
}

private Bitmap LoadSvgAsBitmap(string filePath)
{
    // Load the SVG file
    Telerik.WinControls.Svg.SvgDocument svgDocument = Telerik.WinControls.Svg.SvgDocument.Open(filePath);

    // Render the SVG to a Bitmap
    Bitmap bitmap = svgDocument.Draw();

    return bitmap;
}

I hope that this approach will work for you.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

0
Toby
Top achievements
Rank 3
Iron
Iron
Iron
answered on 17 Apr 2025, 11:44 AM

Sounds like a good solution - with Telerik components there is usually a good solution!  Iwill adapt slightly as I already have the SVG stored as a project resource.

Thanks

Tags
MessageBox
Asked by
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Share this question
or