PC Review


Reply
Thread Tools Rate Thread

adding scrollbars in C# Forms 2.0 - howto here

 
 
raylopez99
Guest
Posts: n/a
 
      31st Oct 2008
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()
{

InitializeComponent();
myRect = new Rectangle(150,150,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_button"; //call it something (you can also
make it invisible but that's optional)

this.Controls.Add(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(object sender, ScrollEventArgs e)
{
this.Invalidate(true);
}

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

private void MyForm_Resize(object 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
 
Reply With Quote
 
 
 
 
raylopez99
Guest
Posts: n/a
 
      1st Nov 2008
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.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Print Scrollbars Property Of All Forms Marshall Barton Microsoft Access Form Coding 2 20th Sep 2008 08:01 PM
Printing Forms having scrollbars Chetana Microsoft Dot NET 0 30th Oct 2006 10:43 AM
HOWTO: Use multiline asp:texbox scrollbars on panel that is disabl =?Utf-8?B?RGFuIFNpa29yc2t5?= Microsoft ASP .NET 0 11th Apr 2006 03:26 PM
scrollbars in access database forms =?Utf-8?B?UmljaGFyZA==?= Microsoft Access Forms 1 25th Sep 2005 05:11 PM
Adding scrollbars to a usercontrol, HOW? Antony Microsoft VB .NET 1 22nd Sep 2003 06:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:20 AM.