请问大家,
我在winform里面添加了一个panel,设置成autoscroll,
然后在Panel里面放一个treeview不能滚动的,当treeview里面的数据多了以后,panel就会出现滚动条。问题:我选择treeview的一个节点以后,然后滚动到底部,当treeview再次获得焦点的时候(比如先让treeview失去焦点,然后点击下面的treeview的node,)每次点击都是treeview滚动到顶部,然后第二次点击才能选中节点。哪位高手能解释一下吗
我在winform里面添加了一个panel,设置成autoscroll,
然后在Panel里面放一个treeview不能滚动的,当treeview里面的数据多了以后,panel就会出现滚动条。问题:我选择treeview的一个节点以后,然后滚动到底部,当treeview再次获得焦点的时候(比如先让treeview失去焦点,然后点击下面的treeview的node,)每次点击都是treeview滚动到顶部,然后第二次点击才能选中节点。哪位高手能解释一下吗
当你选择NODE先是PANEL会滚动到TREE的0,0的位置。
Quote:
That depends, when would you set it? If you set it in one of the events related to the change of focus, it just doesn't work. The reason is because the AutoScroll behavior is occuring after your event handlers.
So I did that and it works. I just subscribe to the Enter event of each ScheduleBar I create on the ScheduleControl and implement this code.
Code:void ScheduleBar_Enter(object sender, EventArgs e)
{
if(Parent is Panel) // My AutoScroll is set on the panel that contains this (schedule)control for now.
{
Point p = (this.Parent as Panel).AutoScrollPosition;
AutoScrollPositionDelegate del = new AutoScrollPositionDelegate(SetAutoScrollPosition);
Object[] args = { this.Parent as Panel, p };
BeginInvoke(del, args);
}
}private void SetAutoScrollPosition(ScrollableControl sender, Point p)
{
p.X = Math.Abs(p.X);
p.Y = Math.Abs(p.Y);
sender.AutoScrollPosition = p;
}