EpiButton background image

Is it possible to set a background image to an EpiButton? If so, does anybody knows how to?

I have already tried the "epiButton1.BackgroundImage = Image.File(@“filepath”); but it is not working…

I also tried the "epiButton1.Image = Image.File(@“filepath”); but it is still not working…

I’ve never done this but when you set the background image, did you also set UseDefaultAppStyling = false?

Hi Chris, yes I have… actually I´m not able to save the custom due to errors in the code. when I test the written code some errors are shown. will paste them here once I get to the office.

1 Like

Sounds good. Also I read that there may be an ImageList property you can set and the you pick an ImageIndex.

Also there is this: Button1.Appearance.Image = System.Drawing.Image.FromFile(“C:\test.jpg”).

well well well… I don´t know why but today when I came in and test it, trying to duplicate the error messages, it start working… the working code is:
`

epiButton1.Image = Image.File(@“filepath”)

`later today will give it a try with the

Button1.Appearance.Image = System.Drawing.Image.FromFile(“C:\test.jpg”)

sentence and will update you

2 Likes

Did you manage to get this to work with correct scale of the image? When I add an image, it is scaled to only a few pixels.

Hi Andrew,

unfortunately no, I was not able to. it was not working as expected and I give up on that.

Thanks for the response… at least I’m not the only one. :slight_smile:

image

epiButtonC21.Appearance.ImageBackgroundStyle = Infragistics.Win.ImageBackgroundStyle.Centered;
epiButtonC21.Appearance.Image =  Image.FromFile(@"c:\BellaNapoliSnip2Photos.png");
epiButtonC21.ImageSize = new System.Drawing.Size(epiButtonC21.Width, epiButtonC21.Height);
3 Likes

I couldn’t get the image to center properly using the ImageBackgroundStyle, but ImageHAlign and ImageVAlign worked.

epiButtonC1.Appearance.ImageHAlign = Infragistics.Win.HAlign.Center;
epiButtonC1.Appearance.ImageVAlign = Infragistics.Win.VAlign.Middle;

Also, this will resize the image to fill the button while maintaining the image’s aspect ratio.

double ratioX = (double) epiButtonC1.Width / (double) img.Width;
double ratioY = (double) epiButtonC1.Height / (double) img.Height;
// use whichever multiplier is smaller
double ratio = ratioX < ratioY ? ratioX : ratioY;

// get the new height and width
int newWidth = Convert.ToInt32(img.Width * ratio);
int newHeight = Convert.ToInt32(img.Height * ratio);

epiButtonC1.ImageSize = new System.Drawing.Size(newWidth, newHeight);
1 Like

Fantastic!
I also had to use the ImageHAlign and ImageVAlign proporties to correctly align the image.