In my application i have a textbox from where i can generate image through command in runtime but now i want to check if the image is existing or not.If there is no image then i want to generate a label. here is my code. i was trying to implement it through regular expression.
else if (Regex.IsMatch(label, "^<IMG.*>"))
{
var imageLabel = Regex.Replace(label, "<IMG|>", "");
if (System.Drawing.Image.FromFile($"{imageLabel}.bmp") != null)
{
var image = System.Drawing.Image.FromFile($"{imageLabel}.bmp");
graphics.DrawImage(image, x, y, image.Width, image.Height);
x = image.Width + 5f;
if (image.Height > rowHeight)
{
rowHeight = image.Height;
}
}
else
{
var font = GetRowFont(isBold, isUnderLine, isHigh, selectedCharwidth);
graphics.DrawString("<?>", font, Brushes.Black, new PointF(x, y));
x += label.Length * font.Size;
}
}
For example i have an image named ABC.bmp in the folder.So if i type it would generate the image and if there is no image named ABC then it would generate a label ''. It shows an exception if I type wrong name.Sorry for the bad Explanation.