Getting location in a scrollable picturebox  
Author Message
LRAZ





PostPosted: Mon Jul 24 06:46:36 CDT 2006 Top

Visual C#.Net >> Getting location in a scrollable picturebox 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);
}

DotNet159  
 
 
Jianwei





PostPosted: Mon Jul 24 06:46:36 CDT 2006 Top

Visual C#.Net >> Getting location in a scrollable picturebox jediknight wrote:
> 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.
 
 
jediknight





PostPosted: Mon Jul 24 09:28:49 CDT 2006 Top

Visual C#.Net >> Getting location in a scrollable picturebox
Jianwei Sun wrote:
> jediknight wrote:
> > 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.

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

 
 
Jianwei





PostPosted: Mon Jul 24 10:08:45 CDT 2006 Top

Visual C#.Net >> Getting location in a scrollable picturebox jediknight wrote:
> Jianwei Sun wrote:
>> jediknight wrote:
>>> 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.
>
> 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.