I found this code online that can help me fit my image in my panel as best as possible.
double largestRatio = Math.Max((double)image.Width / this.ImageDrwPanel.Width, (double)image.Height / this.ImageDrwPanel.Height);
float posX = (float)(this.ImageDrwPanel.Width * largestRatio / 2 - image.Width / 2);
float posY = (float)(this.ImageDrwPanel.Height * largestRatio / 2 - image.Height / 2);
mx = new Matrix(1.0f / (float)largestRatio, 0, 0, 1.0f / (float)largestRatio, 0, 0);
this.statusBarPanelZoom.Text = "Best Fit";
memGraphic.Transform = mx;
This code work perfectly and it fit the image in my panel as best as possible, but I wanted to expand on this code and fill in the rest of the panel with a different color. Such as red or yellow. Can some experts tell me how can I fill in the rest of the background with another color? I've been trying to generate another matrix to draw in my memGraphic, but I can't seem to make it working properly.
I overrided the OnPaintBackground method because I don't like the way it render the background and I wanted to generate the background manually.