0

I wasn't able to find an answer for this:

I have a background image on my form that I want to remain visible even when the system is on High Contrast mode. Is there code that can be entered that overrides the HC mode?

I've tried this on the Form Load event but no luck- no definition for graphics. (Not sure this would even be a viable solution):

OnPaint: e.Graphics.DrawImage(new Bitmap(BackgroundImage), 0, 0);

Aside from creating a PictureBox across my form and putting the image that way, does anyone know of a way to show the BG image of the form always?

EyeSeeSharp
  • 604
  • 1
  • 8
  • 21
  • possible duplicate of [Keep Form.BackgroundImage visible in high contrast mode](http://stackoverflow.com/questions/11110050/keep-form-backgroundimage-visible-in-high-contrast-mode) – cbr Feb 17 '15 at 15:54
  • What the "OnPaint" line means is that you need to put the the code in your form's `OnPaint` event handler – cbr Feb 17 '15 at 15:55
  • @GrawCube Ah, gotcha. Is there anyway to get it on the FormLoad event perhaps? – EyeSeeSharp Feb 17 '15 at 15:57
  • OnPaint is called every time the form is repainted, including the first time it's opened. – cbr Feb 17 '15 at 15:57
  • my bad, you'll probably want to *override* the OnPaint event. If you're just painting the background, it'd probably work in OnPaintBackground. Override the method by adding a method like this: `protected override void OnPaintBackground(PaintEventArgs e)` – cbr Feb 17 '15 at 16:04
  • I've gotten it to work, but now is the issue of re sizing the image on 'Stretch'...by default it puts the image as is. – EyeSeeSharp Feb 17 '15 at 16:28

1 Answers1

1

Override the OnPaintBackground method:

protected override void OnPaintBackground(PaintEventArgs e)
{
    e.Graphics.DrawImage(new Bitmap(BackgroundImage), e.ClipRectangle);
}

This DrawImage overload will stretch the image to fit the rectangle. If the ClipRectangle doesn't work (sorry, I can't test this right now!), create a new Rectangle with the background dimensions

cbr
  • 12,563
  • 3
  • 38
  • 63