adding scrollbars in C# Forms 2.0 - howto here

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raylopez99

    #1

    adding scrollbars in C# Forms 2.0 - howto here

    Scrollbars scroll bars adding scrollbars in C# Forms 2.0 scrollbars
    don't work won't work how to add scrollbar in C#

    Here is how to add a scrollbar to a form. It's not in any book. For
    future reference only, no question being asked.

    This works for forms, as well as "panels".

    Below example is for forms, but will also work in a panel.

    RL

    public MyForm()
    {

    InitializeCompo nent();
    myRect = new Rectangle(150,1 50,10,5000); //this is what
    you want to draw, but it's really long and won't fit in a normal
    window, so add a scrollbar

    //first, you *must* add a dummy control to your form (mandatory).
    Here called button b
    Button b = new Button();
    b.Location = new Point(0, 5000); //place it at the lower
    left corner
    b.Text = "dummy_butt on"; //call it something (you can also
    make it invisible but that's optional)

    this.Controls.A dd(b); //add to form
    }

    //now make sure you check the Properties checkbox for the form (MyForm
    here) for "AutoScroll " to "true" in the Visual Studio Designer
    (Wizard), which will add a line in the machine generated constructor

    // now you have scrollbars added automatically.

    //these below lines are to prevent flicker (also check DoubleBuffer
    property in the form)

    private void MyForm_Scroll(o bject sender, ScrollEventArgs e)
    {
    this.Invalidate (true);
    }

    private void MyForm_VisibleC hanged(object sender, EventArgs e)
    {
    this.Invalidate (true);
    }

    private void MyForm_Resize(o bject sender, EventArgs e)
    {
    this.Invalidate (true);


    // more here: http://www.bobpowell.net/understanding_autoscroll.htm //
    if you want your graphic to 'move' with the scrollbar--note how the
    matrix is used --I find this is nice but optional
  • raylopez99

    #2
    Re: adding scrollbars in C# Forms 2.0 - howto here

    raylopez99 wrote:
    // more here: http://www.bobpowell.net/understanding_autoscroll.htm //
    if you want your graphic to 'move' with the scrollbar--note how the
    matrix is used --I find this is nice but optional
    Update: turns out bob powell's suggestion here is more than just
    optional--it really does make your scroll bars work. So in addtion to
    the above I would add the Matrix transform suggested in Powell's site.

    Comment

    Working...