Getting location in a scrollable picturebox

J

jediknight

Hi,

I have a scrollable view which contains a picturebox.
I need to get the location of the top let hand corner of the view so I
can draw an icon.
When the picturebox is scrolled vertically I need the icon to remain in
the top left hand corner of the view.
At the moment whenever I scroll the picturebox down, the icon gets
hidden.
Thanks in advance.


private void pictureBox1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{

// Need to get the correct location otherwise the
rectangle will disappear when
// the picture is scrolled up
Rectangle boundingRect = new Rectangle(0, 0, 150, 50);
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(
boundingRect,
Color.AliceBlue,
Color.Silver,
LinearGradientMode.ForwardDiagonal);

e.Graphics.FillRectangle(myLinearGradientBrush, boundingRect);

Rectangle rc = boundingRect;
rc.Inflate(-1,-1);

e.Graphics.DrawRectangle(new Pen(SystemColors.Highlight), rc);
}
 
J

Jianwei Sun

jediknight said:
Hi,

I have a scrollable view which contains a picturebox.
I need to get the location of the top let hand corner of the view so I
can draw an icon.
When the picturebox is scrolled vertically I need the icon to remain in
the top left hand corner of the view.
At the moment whenever I scroll the picturebox down, the icon gets
hidden.
Thanks in advance.


private void pictureBox1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{

// Need to get the correct location otherwise the
rectangle will disappear when
// the picture is scrolled up
Rectangle boundingRect = new Rectangle(0, 0, 150, 50);
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(
boundingRect,
Color.AliceBlue,
Color.Silver,
LinearGradientMode.ForwardDiagonal);

e.Graphics.FillRectangle(myLinearGradientBrush, boundingRect);

Rectangle rc = boundingRect;
rc.Inflate(-1,-1);

e.Graphics.DrawRectangle(new Pen(SystemColors.Highlight), rc);
}

You need calculate how much height/width you scrolled (X, Y), and then
apply this offset when you do the actual drawing.
 
J

jediknight

Jianwei said:
You need calculate how much height/width you scrolled (X, Y), and then
apply this offset when you do the actual drawing.

I am using the autoscroll feature of the view. How can I get a handle
to the scrollbar in that case?
 
J

Jianwei Sun

jediknight said:
I am using the autoscroll feature of the view. How can I get a handle
to the scrollbar in that case?

Control has a property called Handle, is this what you look for.

Also, ScrollableControl should have AutoScrollPosition property which
you can tell how much you have scrolled.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top