• 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

    • Taiwan hits Huawei and SMIC with new export restrictions by David Uzondu Taiwan has added Huawei and Semiconductor Manufacturing International Corporation, or SMIC, to its export control entity list. According to CNBC, this means companies in Taiwan now need a special license to ship certain high-tech goods to these two mainland Chinese firms. The conflict has been escalating for a while. The United States government, for instance, has been going after Huawei since at least 2019, putting the telecom equipment maker on its own Entity List over national security fears. The worry has always been about Huawei's connections to the Chinese government and the potential for its network gear to be used for spying. The United Kingdom eventually followed suit, ordering all Huawei 5G equipment to be ripped out of its networks by 2027. Remember, in December 2020, the US added SMIC to its Entity List over its alleged ties to the Chinese military. The goal was to choke off the chipmaker's access to the tools it needs to produce the most advanced semiconductors. Despite all the pressure, the two firms managed to collaborate and produce a 7nm chip for Huawei's Mate 60 phone, which annoyed some people in Washington who thought the sanctions had completely crippled China's chipmaking ambitions. This new blacklisting from Taiwan just tightens the screws even more. Last year, research firm TechInsights found a TSMC-made chip inside a Huawei AI training card. That was a huge "oh no" moment because it showed that, despite all the American restrictions, Huawei was still getting its hands on advanced Taiwanese silicon. That discovery led directly to the U.S. Commerce Department leaning on TSMC to shut down access for Chinese clients to specific AI chips. Huawei had cleverly exploited loopholes to hoard millions of GPU dies for its Ascend AI chip program, a direct attempt to build a homegrown alternative to Nvidia's dominant hardware. For Taiwan, this feels less like a trade issue and more like a matter of survival. The island's lead in chipmaking, largely thanks to TSMC, is often seen as its "silicon shield." The idea is that global reliance on Taiwanese chips makes any military action by China a huge risk for the world. Letting its most advanced tech reach the country that threatens its very existence could seriously weaken that shield. Source: CNBC
    • Anything is "news worthy" if it's new and someone writes about it. Something like an inconsequential note about "correcting a typo in the readme file" buried deep in the changelog could become "news worthy". And, on related note, anything can be used as a justification to complain about something one is clearly already biased against. Say, if someone's biased against Windows 11, they could see even an inconsequential change like an added time display as a reason to rant about "Microsoft these days"... ¯\_(ツ)_/¯
    • I expect i will always have the choice, I doubt I will be around to see self drive cars on the roads in any great amounts. I can understand where your wife is coming from, but then being in a car alone can have other problems.
    • I have no interest in changing to Windows 11, even if I update my PC. My Pc can run it unofficially, and I have had a peek now and again, but so many things that put me off, All the AI stuff that is all over the place, so not an easy way to switch it off, the forced MS account, the way Windows 11 pops up dialogues when you are not using Edge or any other MS supplied software. The awful context menus. The search in windows using Bing and then the results in Edge. There are other reason. I changed to Mac for the most part, but as I have said before, I do have an old AMD R 7 1700 machine for my games, unless it stops working I will keep it going with Windows 10.
    • I switched to Mac, I would have changed to Linux, but i run software that is no compatible with Linux and no replacement.
  • Recent Achievements

    • Explorer
      Legend20 went up a rank
      Explorer
    • One Month Later
      jezzzy earned a badge
      One Month Later
    • First Post
      CSpera earned a badge
      First Post
    • One Month Later
      MIR JOHNNY BLAZE earned a badge
      One Month Later
    • Apprentice
      Wireless wookie went up a rank
      Apprentice
  • Popular Contributors

    1. 1
      +primortal
      615
    2. 2
      ATLien_0
      277
    3. 3
      +FloatingFatMan
      180
    4. 4
      Michael Scrip
      150
    5. 5
      Steven P.
      115
  • Tell a friend

    Love Neowin? Tell a friend!