Advertisement

11.12.2007 at 08:39PM PST, ID: 22956363
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

Reposition Windows Form Controls within Panel

Asked by HobartSmelter in C# Programming Language

Tags: , ,

Gday experts,

I've created a composite user control (JSEAAnalysisDisplay) to use as a means of adjusting the data in a series of records (so it contains dropdownlists, rich text boxes, checkboxes, etc). I then have a form which contains two buttons (btnAnalysisAdd and btnAnalysisDelete) and a panel (panelAnalysis).

The way the form is meant to work is that the user can click the 'Add' button as many times as they desire to create several of these JSEAAnalysisDisplay controls within the panel in the form, adjust them as appropriately and then save it all back to the database.

In the code below you can see the methods I have tied to the two buttons to first add a new blank instance of the control, and then the other button to remove those with a field flagged.

The problem I have is that when I'm appending these new custom controls to the control list of the panel, they all get positioned on top of each other - thus effectively making them impossible for the user to navigate correctly. The only solution I could think of was to reprocess their locations after they are added to the control list and also when any are removed (to reposition those left around the deleted instances to compensate).

Initially this appears to have resolved my problem, but now I have encountered another flaw in my design - when there are several instances of the JSEAAnalysisDisplay control within the panel, enough to force the panel's autoscroll to display, any repositioning is done relative to the scroll! So when I delete several of the controls using my button the first control in the collection is repositioned wherever the scroll is currently positioned. That means that the user can then scroll back to the start of the panel and see nothing but white space.

So my question is this;

How can I correctly position my new user controls when added to the panel control collection so that when added they cleanly display in a flat list down the form. And also, when they are removed the controls reposition relative to the panel, not the scroll bars.

methods as follow;

private void btnAnalysisAdd_Click(object sender, EventArgs e)
{
      panelAnalysis.Controls.Add(new JSEAAnalysisDisplay());
                  
      RepositionAnalysis();
}

private void btnAnalysisDelete_Click(object sender, EventArgs e)
{
      for (int iCon = 0; iCon < panelAnalysis.Controls.Count;iCon++ )
      {
            // Is this an analysis display segment?
            if (typeof(JSEAAnalysisDisplay) == panelAnalysis.Controls[iCon].GetType())
            {
                  JSEAAnalysisDisplay curCon = (JSEAAnalysisDisplay)panelAnalysis.Controls[iCon];

                  if (curCon.IsSelected)
                  {
                        panelAnalysis.Controls.RemoveAt(iCon);
                        iCon--;
                  }
            }
      }
                  
      RepositionAnalysis();
}
            
private void RepositionAnalysis()
{
      for (int iCon = 0; iCon < panelAnalysis.Controls.Count; iCon++)
      {
            if(iCon > 0)
            {
                  panelAnalysis.Controls[iCon].Location = new Point(
                        0,
                        panelAnalysis.Controls[iCon - 1].Location.Y +
                        panelAnalysis.Controls[iCon - 1].Height);
            }
            else
            {
                  panelAnalysis.Controls[iCon].Location = new Point(0, 0);
            }
      }
}

Any help is appreciated, many thanks in advance.Start Free Trial
[+][-]11.12.2007 at 11:10PM PST, ID: 20269950

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C# Programming Language
Tags: panel, form, controls
Sign Up Now!
Solution Provided By: arif_eqbal
Participating Experts: 2
Solution Grade: A
 
 
[+][-]11.12.2007 at 11:22PM PST, ID: 20269991

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628