Reputation: 1
I'm having a problem with panels. I'm adding points to a panel with this code:
void panelDraw_Paint(object sender, PaintEventArgs e)
{
if (this.MeasuredValue == null)
return;
var g = e.Graphics;
int x = 0;
foreach (value m in this.MeasuredValue )
{
double percentage = m.MeasuredValue [(int)this.MeetType].GetValueOrDefault() / this.MaxValue * (double)100;
double y = this.Height / (double)100;
double pixels = y * percentage;
g.DrawRectangle(Pens.Green, x++, this.Height - (int)pixels, 1, 1);
g.DrawLine(Pens.GhostWhite, 0, this.Height / 4, panelDraw.Width, this.Height / 4);
g.DrawLine(Pens.GhostWhite, 0, this.Height / 2, panelDraw.Width, this.Height / 2);
g.DrawLine(Pens.GhostWhite, 0, (this.Height / 4) * 3, panelDraw.Width, (this.Height / 4) * 3);
if (x > panelDraw.Width)
{
panelDraw.AutoScroll = true;
}
}
}
The dimension of my panel is 230;218 I'ld like to see my points when x goes out of the boundaries (bigger then 230) but somehow autoscroll doesn't work .. I did also set AutoScroll on true in the panel properties from the beginning, but that also doesn't work.
This is what I get, when x is bigger than my panel width:
How can I see my points when they are out of the boundaries of the panel?
Upvotes: 0
Views: 85
Reputation: 32627
The reason why the panel does not show any scroll bars is that it does not know anything of its content. Even if it would scroll, the view would not change because you don't take the scroll position into account when painting the content.
Instead of painting directly to the panel, you should add another control with the appropriate size to it and paint on this control. This will give the panel the necessary scroll hints and you don't have to handle scrolling manually.
Upvotes: 0