将自动滚动条添加到窗体 [英] add AutoScroll bar to form

查看:93
本文介绍了将自动滚动条添加到窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我将子表单添加到表单中.

当我将其拖出父窗体的边界时,将出现一个滚动条.

以下是实现此目的的代码.

但是我想要这样,以便当我移动内部子窗体时,滚动条可以滚动到子窗体的新区域.

有人有什么想法吗?

谢谢.


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.


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();
    }
  }
}

推荐答案

首先,与WinForms滚动相关的都是flakey.

为了简单起见(因此我不必写一些东西来管理Windows)将frm_child的声明移到类级别.
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);
}



基本上,如果在表单中激活了任何控件,请输入将触发,然后您告诉父"表单将另一个滚动到视图中.

如果您尝试使用MDI,那就更糟了...

干杯,
-jc



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


这篇关于将自动滚动条添加到窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆