newbie: Windows Forms Drawing

D

Derrick

Hello all;

I have a UserControl (named "GridDisplay") onto which I'm drawing a grid.
What I need to know is, as the grid height grows beyond the bounds of the
UserControl , how to I get the UserControl to show it's scrollbars, so I can
let the user scroll to the bottom of my grid (and horizontally as well, if
need be)? I know it does this automatically when there are controls on the
UserControl . I have the UserControl's dockstyle set to "Fill" on the host
Form, and AutoScroll set to True.

Here's my paint code:

private void GridDisplay_Paint(object sender, PaintEventArgs e)

{

Point DrawStartPoint = new Point(10,10);

Size cellSize = new Size(30,15);

numCols = 20; //just an example number


numRows = 200; //just an example number

Graphics g = e.Graphics;


g.Clear(this.BackColor);

for(int j = 0; j < numRows; j++)

{

int yLoc = DrawStartPoint.Y + j*cellSize.Height;

Rectangle[] cells= new Rectangle[numCols];

for(int i = 0; i < this.numCols; i++)

{

int xLoc = DrawStartPoint.X + i*cellSize.Width;

Point p = new Point(xLoc, yLoc);

cells = new Rectangle(p, ByteDrawSize);

}

g.DrawRectangles(new Pen(Color.Black), cells);

}

}
 
D

Dave

I don't think it's possible (without bending over backwards) to force Windows controls to show scroll bars without child windows.

Your best bet is to add scrollbar controls and manually handle the scrolling logic.
 
D

Derrick

Thanks for the info Dave. Instead of tackling the scroll bars manually, I
programmatically added another panel, tied the paint code to that (and
resized the panel as appropriate), then added that to the user control. Now
I have scrolling automatically!

Cheers,

Derrick


Dave said:
I don't think it's possible (without bending over backwards) to force
Windows controls to show scroll bars without child windows.

Your best bet is to add scrollbar controls and manually handle the
scrolling logic.

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
Derrick said:
Hello all;

I have a UserControl (named "GridDisplay") onto which I'm drawing a grid.
What I need to know is, as the grid height grows beyond the bounds of the
UserControl , how to I get the UserControl to show it's scrollbars, so I
can let the user scroll to the bottom of my grid (and horizontally as
well, if need be)? I know it does this automatically when there are
controls on the UserControl . I have the UserControl's dockstyle set to
"Fill" on the host Form, and AutoScroll set to True.

Here's my paint code:

private void GridDisplay_Paint(object sender, PaintEventArgs e)

{

Point DrawStartPoint = new Point(10,10);

Size cellSize = new Size(30,15);

numCols = 20; //just an example number


numRows = 200; //just an example number

Graphics g = e.Graphics;


g.Clear(this.BackColor);

for(int j = 0; j < numRows; j++)

{

int yLoc = DrawStartPoint.Y + j*cellSize.Height;

Rectangle[] cells= new Rectangle[numCols];

for(int i = 0; i < this.numCols; i++)

{

int xLoc = DrawStartPoint.X + i*cellSize.Width;

Point p = new Point(xLoc, yLoc);

cells = new Rectangle(p, ByteDrawSize);

}

g.DrawRectangles(new Pen(Color.Black), cells);

}

}

 
Top