|
-
May 23rd, 2006, 01:50 AM
#1
Thread Starter
New Member
Scrolling in a panel doesn't work in beginning
Hi,
I'm filling a panel with a set of controls in OnLoad. Autoscroll is set to true. I want to scroll to the top but it never works. The same exact code does work however, when I execute the code when everything is up and running (for instance on a button press).
Is this an initialisation problem?
Code:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
m_projects_split_main.Panel1.AutoScroll = true;
// Set up filters;
m_filter_comment3 = new FilterControlText("Comment 3");
_AddProjectsFilter(m_filter_comment3);
m_filter_comment2 = new FilterControlText("Comment 2");
_AddProjectsFilter(m_filter_comment2);
m_filter_comment1 = new FilterControlText("Comment 1");
_AddProjectsFilter(m_filter_comment1);
m_filter_id = new FilterControlText("Project id");
_AddProjectsFilter(m_filter_id);
// this code or equivalent (setting vscroll manually) does not work yet
m_projects_split_main.Panel1.ScrollControlIntoView(m_filter_id);
}
private void _AddProjectsFilter(FilterControl i_filter)
{
i_filter.Dock = DockStyle.Top;
m_projects_split_main.Panel1.Controls.Add(i_filter);
i_filter.InputChanged += ActionFilterProjects;
}
So only after everything is running, and I call ScrollControlIntoView again, then it does what's expected. Can anyone help please?
-
May 23rd, 2006, 02:01 AM
#2
Re: Scrolling in a panel doesn't work in beginning
I'd advise handling the Load event rather than overriding the OnLoad method.
Your problem is occurring because the OnLoad method is executed BEFORE the form becomes visible, so you cannot scroll a control into view when it can't be seen. If you're using .NET 2.0 (please specify in future) then you can handle the Shown event, which is raised immediately after the form is displayed for the first time. If you're using an earlier version then you can use the Activated event, but you'll need to use a class-level variable to ensure that your code is only executed the first time the form is activated:
Code:
private bool firstActivation = true;
private void Form1_Activated(object sender, EventArgs e)
{
if (this.firstActivation)
{
// Do whatever here.
this.firstActivation = false;
}
}
Also, it looks like some of what you're doing there would be more appropriately perfromed in the constructor or even in the designer. Is there any reason you've chosen not to set the AutoScroll property of a Panel in the designer?
-
May 23rd, 2006, 02:42 AM
#3
Thread Starter
New Member
Re: Scrolling in a panel doesn't work in beginning
Thank you. I am indeed using .NET 2.0, sorry for forgetting to mention it.
Your solution works perfectly when I use the control in a Form. However my control is can also be displayed in a webpage, and then there is no Shown event to hook into it seems. Would the PreRender event be okay there?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|