Jump to content
  • Advertisement
Sign in to follow this  
UnshavenBastard

[.net] Strange behavior Arranging child controls

This topic is 3632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello there. Using C#/.NET 3.5, I made a UserControl that houses some child Panels, and has to arrange them. The "container control" has a vertical shape and when controls are added, it should arrange them so that each next control is below the previous. To do that, I put something like this in the overridden OnLayout() method: (I hope the PLUS chars get shown here, they don't in the preview)
			int verticalDistance = 2;
			int y = 0;						
			foreach (Panel p in this.Controls)
			{
				p.Location = new Point(0, y);
				p.Width = this.ClientSize.Width;
				y	+=	p.Height + verticalDistance; 
			}



I have a button on each child panel that is to allow to change its "rank" in the contaning control ("move up"), clicking on it does this:
int index = Controls.GetChildindex( panel );
if (index > 0)
{
    Controls.SetChildindex(panel, index-1);
}


Now the strange thing is, if I put more than two panels into the container control, when I click the "MoveUp" button on some, somtimes, the arrangement fails such that the actual Y-position of the topmost control will not be 0 as you saw in the code, but a lot lower, so that there is a lot of free space above the top control, which I obviously don't want. Sometimes panels will even overlap. Maybe it's noteworthy that AutoScale is true for the container control. There is no other code that alters the vertical position of the child panels in my project, and it's as simple as shown. I can't see what's happening, so I guess it must have to do with some behavior of .NET controls I don't know o_O Any ideas? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by UnshavenBastard
Maybe it's noteworthy that AutoScale is true for the container control.


If you're manually positioning or moving items I would have anything related to sizing and positioning that fires automatically turned off. I'm not sure that this is your problem; however, I have had issues in the past where programmatic manipulation of properties such as the control's location would fail to update related properties that the automatic methods relied upon.

As well: if you have isolated the incident as cleanly as you seem to have a trip through the application with a debugger would probably prove beneficial.

Share this post


Link to post
Share on other sites
yeah, yeah.

I disabled the autoscrolling stuff and did it all by hand,
now it works fine... *sigh*

another funny thing I had was that if I moved the mousewheel, a control I had on the mainForm would move slightly left/right, (3..4 pixels?), depending on the direction I was "wheeling".
Strange...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!