0

Im looking to dock a background image to the bottom of a form. Currently I have a background image that is in the centre of the form and would like to change to where the image is at the bottom. I have tried docking it but unfortunately failed.

Thanks in advance.

    this.BackgroundImageLayout = ImageLayout.Zoom;
    this.BackgroundImage = Image.FromFile(@"C:\Users\Desktop\Shooter\Shooter\AppleShooter\Resources\Finalbackground1.png");
Liam
  • 27,717
  • 28
  • 128
  • 190
user9769106
  • 21
  • 1
  • 6
  • 1
    Can you post some code that you have tried so far? – GMB Jun 01 '18 at 08:03
  • Use a `PictureBox` instead, you can dock that – Biesi Jun 01 '18 at 08:04
  • I tried picturebox, but Im using a picturebox over a picturebox which doesnt allow for transparency, therefore have to take this method of solution – user9769106 Jun 01 '18 at 08:05
  • I am using c#, Windows form application – user9769106 Jun 01 '18 at 08:07
  • 1
    Please try and add the correct tags when posting this kind of question, i.e. [tag:winforms], etc. – Liam Jun 01 '18 at 08:09
  • oh ok will keep it in mine! – user9769106 Jun 01 '18 at 08:11
  • 2
    Did you try using a Panel? You could dock that at the bottom of your form and set it's background image. Edit: I would also suggest adding your image as a resource rather than using Image.FromFile as that will not work if you deploy your application to another PC. – dekin88 Jun 01 '18 at 08:24
  • Possible duplicate of [Can I create a transparent background on a PictureBox in WinForms?](https://stackoverflow.com/questions/4983753/can-i-create-a-transparent-background-on-a-picturebox-in-winforms) – stefan.seeland Jun 01 '18 at 08:26
  • Not not really. Im not using that method any more. – user9769106 Jun 01 '18 at 08:35
  • No, this is not possible. if you need it you will have to use a helper control, say a Panel. Or draw it in the (On)Paint event. Or create a bitmap of the ratio&size you want at each resize.. – TaW Jun 01 '18 at 09:16
  • could u expand a little?? – user9769106 Jun 01 '18 at 09:18
  • On what? The simplest solution (short of making the bitmap larger at the top) is using a Panel although that may lead to complications in the form layout. But not knowing anything about your form I can't say. I think I would give drawImage in the Paint event a shot.. – TaW Jun 01 '18 at 10:03
  • 1
    You can achieve that by drawing it in the OnPaintBackground() method. https://stackoverflow.com/questions/3707562/position-of-backgroundimage-in-windows-form – L_J Jun 01 '18 at 10:57

1 Answers1

1

You can set a panel and dock it to the bottom and then your main picturebox you can dock it to the center. In the panel at the bottom add another picturebox then dock it to the center, and add the background image. Your form would look like this:

enter image description here

After you have your selected background image load it in the resource, then add it to the picturebox. In the picturebox setting be sure to set backgroundImageLayout to stretch when you maximize the form the background will expand.

Community
  • 1
  • 1
Halonic
  • 405
  • 2
  • 12