Alex
Alex

Reputation: 5

Form background color or image stuck as white

I started teaching myself C# a week ago. I started by writing Tetris to get myself acquainted with the language. I got the main game mechanics working by painting onto presized bitmap and displaying it in a picturebox, which at the time was the same size of the window. Now I have expanded the windows size and started adding other controls to the side of the picture box.

The problem is, now that I have expanded the window, displaying the form background, the background color is permanently white or I get a weird white to black faded look in the bottom corner.

I have tried several things:
   - set the form backcolor manually, but it is only reflected on the labels
   - checked that the transparencykey is empty
   - set transparencykey to an unused color, nothing changes
   - added a bmp as the form's background image, still stays white
   - checked my code to see if I was every writing directly to the form background

I can't fingure out how to fix this; does anyone have any ideas?

EDIT:
I found the answer to my question. SetStyle(ControlStyles.Opaque, true) was called in my constructor. I'm not sure what exactly that does, but I commented it out and it fixed my problem.

Upvotes: 0

Views: 3374

Answers (2)

Alex
Alex

Reputation: 5

I found the answer to my question. SetStyle(ControlStyles.Opaque, true) was called in my initialization. I'm not sure what exactly that does, but it was the cause of my background color issue.

Upvotes: 0

aWebdesigner09
aWebdesigner09

Reputation: 257

Please list out the requirements means exactly what you need?

After I read your question. The following are my understandings.

If your problem is with changing window size, then

  • make use of Split container, which is available in toolbox from 'Containers' group.

  • set its Dock property to fill to fill entire window if resized/maximized.

  • Then use the right pane to contain your picture box and left pane for other controls.

  • If you require, you may also set dock property of picture box to fill to its parent container means right pane.

If your problem is with background color of the window, then

  • Actually Background color issue comes, If the form is an Mdi Container.

  • Check whether IsMdiContainer property is set to false. If true it is an MdiContainer.

  • The following code block sets Mdi Forms' backcolor to the forms' backcolor.

    foreach (Control c in this.Controls)
    {
        if (c is MdiClient)
        {
            c.BackColor = this.BackColor;
        }
    }
    

Upvotes: 1

Related Questions