Scrollbar for canvas area
Posted on 2006-11-05
I have set the canvas for whole Client Rectangle size.
When i resize the form, my form's clientrectangle size gets smaller than canvas area size and some of the graphic objects on screen gets hidden inside. Im creating a scrollbar horizontal/vertical (which ever is required) inorder to view the hidden area of the canvas. But when i scroll i couldn't make the form to move to show the hidden area.
I tried the below code,
// when horizontal scrollbar thumb is moved
void hsb_ValueChanged(object sender, EventArgs e)
isHsbValChanged = true;
Invalidate(); // calling invalidate to raise paint event
private void Form1_Paint(object sender, PaintEventArgs e)
canvas.g.FillRectangle(new SolidBrush(SystemColors.Control), e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height); // g is graphic object created in canvas form
canvas.ScrollRender(canvas.g, 10, 0);
isHsbValChanged = false;
// Render function at canvas form
public void Render(Graphics g)
if (bmp != null) //bmp is empty bitmap created at runtime
// width & height are the canvas width & height
g.DrawImage(bmp, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel);
// Scroll Render function at canvas form
public void ScrollRender(Graphics g,int hVal, int vVal)
if (bmp != null)
// hVal is horizontal movement & vVal is vertical movement, values are taken just for example
g.DrawImage(bmp, new Rectangle(0, 0, width, height), hVal, vVal, width + hVal, height + vVal, GraphicsUnit.Pixel);
But this code doesn't seems to work, i dont see the form area is moving.
How could i connect scrollbar to form's display(visible) area?
Any suggession would be of great help.
Thanks in advance.