• 0

[C#] Issue with making one picturebox appear ontop of another


Question

Hey,

I am currently working on a program to teach myself C#. In it, a person is "throwing" meatloaf at a picture of Hilary Clinton's head. (long story). I've created the picturebox containing Hilary's head from the toolbox, but I created my meatloaf pictureboxes from code. I have right clicked on Hilary's picture and selected "Send to Back", and used the Meatloaf.BringToFront();, but for some reason, the meatloaf always goes behind Hilary's head, making it hidden.

The code I used to set up the Meatloaf pictureboxes is

(global)
public PictureBox[] picNewMeatLoaf = new PictureBox[20];

(In a FormLoad)

			for (int j = 1; j <= 19; j++)
			{
				picNewMeatLoaf[j] = new PictureBox();
				picNewMeatLoaf[j].BringToFront();
			}
__________________________________
(In a AddMeatLoaf() procedure)

this.SuspendLayout();

   picNewMeatLoaf[i].Location = new Point(0, 0);
   picNewMeatLoaf[i].Size = new Size(75, 25);
   picNewMeatLoaf[i].BringToFront();
   picNewMeatLoaf[i].Image = this.picMeatLoaf.Image;
  this.Controls.AddRange(new Control[] { picNewMeatLoaf[i] });


	this.ResumeLayout();

___________________________________
(in a timer)
 for (int j = 1; j < 20; j++)
		 {
			 if (this.picNewMeatLoaf[j].Top < 305 & picNewMeatLoaf[j].Left < 693)	//305 is the ground level, 693 is the spot on Hilary's face to stop
			 {
				 this.picNewMeatLoaf[j].Top = picNewMeatLoaf[j].Top + 1;
				 this.picNewMeatLoaf[j].Left = picNewMeatLoaf[j].Left + MeatLoafSpeed[j];
			 }

That is just the code related to the MeatLoaf picturebox, so obviously there is a lot more code. Note, this is my first real attempt at a program with C#, so the code isn't going to be the best.

Does anyone see what I'm doing wrong or have any suggestions? I'm all out of ideas, and I'd rather not have to just add it into the form1's background image. If you need anymore code or information, just let me know.

Oh, and if anyone has any ideas on how to make parts of picture boxes transparent, meaning they show the objects behind it, it would be VERY appreciated.

Pierce

1 answer to this question

Recommended Posts

  • 0

Try using .Visible instead of BringToFront()

ie.

picNewMeatLoaf[j].Visible = false; // The image you wanna hide

picNewMeatLoaf.Visible = true; // The image you wanna show

Also, you can try putting them in small containers, such as panels if you still have trouble and use panel1.BringToFront() or Panel1.Visible = true and panel2.Visible = false;

To make the image transparent, try opening it in paint or something and selecting the area you want to be transparent and delete it and save and re-import into visual studio.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • All set as AI did the trick
    • AnyDesk 9.5.7 by Razvan Serea AnyDesk is a fast remote desktop system and enables users to access their data, images, videos and applications from anywhere and at any time, and also to share it with others. AnyDesk is the first remote desktop software that doesn't require you to think about what you can do. CAD, video editing or simply working comfortably with an office suite for hours are just a few examples. AnyDesk is designed for modern multi-core CPUs. Most of AnyDesk's image processing is done con­currently. This way, AnyDesk can utilize up to 90% of modern CPUs. AnyDesk works across multiple platforms and operating systems: Windows, Linux, Free BSD, Mac OS, iOS and Android. Just five megabytes - downloaded in a glimpse, sent via email, or fired up from your USB drive, AnyDesk will turn any desktop into your desktop in se­conds. No administrative privileges or installation needed. AnyDesk 9.5.7 changelog: Fixed Bugs Fixed deadlock when updating chat server Fixed crashes caused by exceptions in internal communication layer Fixed crash when opening new monitor in Session in a new window Fixed crash on shutdown Fixed bug that allowed naming Permission Profiles identical to predefined Profiles Fixed bug that could cause licensed remote clients to show up as free Fixed visual bug that caused Set-Password button to show up when Unattended Access was disabled Fixed bug that lead to selecting the wrong initial resolution for webcams New Features Added command line option --record-screen to start a Screen Recording Other Changes Improved visual consistency in some list views Download: AnyDesk 9.5.7 | macOS ~14.0 MB (Free for private use, paid upgrade available) Links: AnyDesk Home Page | Other platforms | Release History | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • WUT?! Tell us you've never built desktop software without telling us you've never built desktop software... The chromium rendering engine is the content-rendering engine for "chromium-based browsers," but that does NOT mean there's a full-on UI underneath that is somehow bloating these products. The bloat is from the additional UI components that the browser vendor (Vivaldi) is adding atop the base package. Most chromium browsers customize the default skin/theme of the overall package so there's absolutely zero added overhead; it's really just a different CSS-based theme pack. Vivaldi, however, adds more than just a different skin; they add built-in extensions (that are managed by other built-in extensions), add other customization modules, and all kinds of other bloat -- and these add-ons are EXACTLY where the resource-hogging stems from. The mere fact it's a chromium-based browser has no impact on the matter. Lastly, power users literally DO notice resource-intensive applications -- they'll even be familiar with tools and widgets that expose those measurements the way only a power-user would! General consumers, however, would simply remark that their rig is sluggish and probably outdated and blindly upgrade to whatever the salespeople are hawking at the local computer store. General consumers wouldn't even upgrade their existing computer cuz they wouldn't know how to!
    • Nope, they just removed the game from sales.
  • Recent Achievements

    • First Post
      Celilo earned a badge
      First Post
    • One Year In
      K.I.S.S. earned a badge
      One Year In
    • Week One Done
      solidox earned a badge
      Week One Done
    • Dedicated
      solidox earned a badge
      Dedicated
    • Week One Done
      Devesh Beri earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      438
    2. 2
      ATLien_0
      166
    3. 3
      +FloatingFatMan
      151
    4. 4
      Nick H.
      66
    5. 5
      macoman
      63
  • Tell a friend

    Love Neowin? Tell a friend!