0

I'm a novice trying to make a simple game where you're a little cat boy traveling through a small village. I deleted my Picturebox and swapped it out for a Panel so I wouldn't have to use a workaround for transparency (giving it the same name as the Picturebox to connect it to the code I already had written out for the KittyBoy) I got this error after doing so, and I'm not sure what the issue is exactly.

It seems like 'Panel' probably doesn't have a definition for Image, but I'm not sure where to go from here.

I tried finding a definition I might be able to swap 'Image' out for that's connected to panel, but couldn't find any promising leads. I also tried seeing what other people did to solve this same compiler error, but the errors were too different from the one I'm getting for me to figure out a solution based on them. Again, I'm a super novice.

private void keyisdown(object sender, KeyEventArgs e)
    {
        if(e.KeyCode == Keys.Left)
        {
            goleft = true;
            KittyBoy.Image = Properties.Resources.KittyBoy;
        }

        if(e.KeyCode == Keys.Right)
        {
            goright = true;
            KittyBoy.Image = Properties.Resources.KittyBoyRight;
        }
    }

The code is meant to have the character face one direction when moving one way and the opposite direction when moving the opposite way. I still have these .PNG files in my resources folder too, and that's where I got them from when I attached them to the panel.

This was the error: error

  • No idea whom you asked and told you that a Panel is better than a PictureBox, in relation to transparency. They tricked you. Anyway, a Panel doesn't have an `Image` property (as the error clearly states). It just has a `BackgroundImage` property. Switch back to PictureBox controls. Also, assign the Images from the Project's Resources just once, to Bitmap objects that you then Dispose of when not needed anymore. Do not create a new Bitmap each time you move a container. `Properties.Resources` is a factory, it creates a new object each time you use it. – Jimi Aug 27 '19 at 03:33
  • Geez, I feel dumb now, I should've researched a little before blindly believing people haha. Thanks for the help! Converted back to PictureBox and now I'm trying to troubleshoot the transparency issue. Unfortunately Eric's code didn't work for my assets, but I think I can try and figure it out from here. Thanks everyone! – Alex Sprague Aug 27 '19 at 03:49
  • You'll have *transparency* problems in any case in WinForms. UI controls transparency is just a trick, not real transparency. If you want your Sprites to be actually transparent, you need semi-trasnparent Bitmaps that you can draw on a container (PictureBoxes, used as canvas for drawing, work well). – Jimi Aug 27 '19 at 03:56

1 Answers1

0

I am not familiar with any way to convert Panel into an Image, but you can try this if you switch back to your PictureBox.

myPictureBox.BackColor = Color.Transparent;

See How to make picturebox transparent?

Eric Warburton
  • 329
  • 3
  • 11
  • I guess convert was the wrong word. I deleted my PictureBox assets and created Panels instead with the same images I had on the PictureBoxes, gave them the names that the PictureBox assets had originally so they could connect back to the code (it worked in the end aside from these two lines) I didn't want to use PictureBoxes because the transparency didn't work very well and a lot of game developers were suggesting using panels instead because they're less glitchy with transparency and work similarly. – Alex Sprague Aug 27 '19 at 02:33