Click here to Skip to main content
16,023,339 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I add a child form to my form.

When I drag it out of the bounds of the parent form, a scroll bar appears.

The following is the code to implement this.

But I want it so that when I move the inside child form, the scroll bar could scroll to the new area of the child form.

Does anyone have any ideas?

Thanks.


C++
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
  public class Form1 : Form
  {
    public Form1()
    {
      this.AutoScroll = true;
      Form frm_child = new Form();
      frm_child.TopLevel = false;
      this.Controls.Add(frm_child);
      frm_child.Show();
    }
  }
}
Posted
Updated 14-Jun-10 23:14pm
v2
Comments
Dalek Dave 15-Jun-10 5:14am    
Edited for readability and correct placement of code tags.

1 solution

First off...anything to do with scrolling on WinForms is flakey.

For simplicity sake (and so I don't have to write something to manage windows) move the declaration of frm_child to the class level.
public partial class Form1 : Form
{
    Form frm_child = new Form();
...


Add this (when you create the form):
frm_child.Enter += new EventHandler(frm_child_Enter);


...and in the event handler:
void frm_child_Enter(object sender, EventArgs e)
{
    this.ScrollControlIntoView(frm_child);
}


Basically, if any control is activated in the form, enter will fire and then you are telling the 'parent' form to scroll the other one into view.

It's even worse if you try to use MDI...

Cheers,
-jc
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900