简体   繁体   中英

trying to add/remove controls to a form

plz keep in mind I'm very noobish...

What I'm trying to do is add "blips" to my form. I have a calculation that determines where all these "blips" will be, which is plotted on a graph. the solution determines that the coordinates are "blipHours, blipAltitude"

I want to somehow add small dots to my form at these locations. At first I was going to create something to be my "blips" but then I realized that I want it so small that I could just use an empty picture box with the background color what I want (I know this isn't the best way but I'm still very new to this).

I've created the code that will add the blip

                    PictureBox blip = new PictureBox();
                    blip.Location = new Point(blipHours, blipAltitude);
                    blip.Size = new Size(6, 6);
                    blip.BackColor = System.Drawing.Color.Lime;
                    blip.Text = "";
                    blip.Name = callsign;
                    this.Controls.Add(blip); 

It adds the blip, but it always adds it underneath other controls. Is there a way to make it add the new blip on top of everything else so that it's visible?

my second question is how do I remove all of the blips that get created at once with the click of a button?

您可以使用.AddAt设置其在控件列表中的位置。

An alternative to nobugz' answer is to change the Z-order of your controls via the Form.Controls.SetChildIndex method:

this.Controls.Add(blip);
this.Controls.SetChildIndex(blip, 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM