Answer the question
In order to leave comments, you need to log in
Scroll events in c#?
Is it possible to catch the scroll event on the form element and insert the value into the label?
I'm trying to do it but nothing happens... What am I doing wrong?
private void Form1_Scroll(object sender, ScrollEventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
int xWidth = pictureBox1.Width;
int yHeight = pictureBox1.Height;
int x;
int y;
if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
{
x = e.NewValue;
y = vScrollBar1.Value;
}
else //e.ScrollOrientation == ScrollOrientation.VerticalScroll
{
y = e.NewValue;
x = hScrollBar1.Value;
}
g.DrawImage(pictureBox1.Image,
new Rectangle(0, 0, xWidth, yHeight), //where to draw the image
new Rectangle(x, y, xWidth, yHeight), //the portion of the image to draw
GraphicsUnit.Pixel);
pictureBox1.Update();
label1.Text = x.ToString();
}
Answer the question
In order to leave comments, you need to log in
1 - the contents of containers and not forms are usually copied. make sure you actually hang the handler on the container you're scrolling in
2 - use breakpoints to make sure you hit that handler at all
3 - once upon a time, I would probably start by putting a line like label1.Text = "bingo!";
the very first one in the handler, and only then would complicate the logic
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question