Scrollbars with Panel (Urgent);

  • Thread starter Thread starter Kam
  • Start date Start date
K

Kam

Hi everyone,

I've finally managed to zoom in and out an image painted on a Panel.
However, i'm
having a problem with the scrollbar in my Pocket PC. I can't get the exact
size to scroll.

Firstly, the picture get painted on the panel, and then to get the width or
the height of
the scrollbar i have developed the following metric:

(WidthOfBitmap * TheScale(1,2,3...etc)) - WidthOfPanel +
TheSizeOfTheScrollBar(e.g.10)

However, I always end up with the wrong size.. It's not a liner so at least
I would know how much I have to increase the scrollbar size everytime I zoom
in...

any idea, links, tutorial, sample would be very much appreciated..

Thanks in advance
Kam
 
Hi Cam,

The following will return the scrollbars size:

using System.Reflection;

.....

FieldInfo fi = this.GetType().GetField("m_sbVert",
BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.
Instance);
int width = ((VScrollBar)fi.GetValue(this)).Width;
fi = this.GetType().GetField("m_sbHorz",
BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.
Instance);
int height = ((HScrollBar)fi.GetValue(this)).Height;

The following can be used to programatically move the
scroll bars (this example scrolls down a specified
amount):

FieldInfo fi = this.GetType().GetField("m_sbVert",
BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.
Instance);
VScrollBar vsb = (VScrollBar)fi.GetValue(this);
vsb.Value += (your value);

Hope this is of some help.

Cheers, Ian
 
When you get this fix, could you send a Comact Sample showing how the Zoom
and Scroll bar is done?

Mark Johnson, Berlin Germany
(e-mail address removed)
 
Thx Ian,

I've tried to use the sample code u posted. However, I keep getting Null
Exception on the following line:
int width = ((VScrollBar)fi.GetValue(this)).Width;

and when i move the mouse over the (fi), it says (fi = <undefined value>),
Any idea what that can be.. Im using the code inside a property get{} as
follows:

public int ScrollWidth
{
get
{
System.Reflection.FieldInfo fi = this.GetType().GetField("m_sbVert",
BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance);
int width = ((VScrollBar)fi.GetValue(this)).Width;

//int width = (this.bmp.Width * this.scale - this.Right * this.scale);
if(width > 0)
return width;
else
return 0;
}
}

Any idea where am i going wrong?

Hope to hear from u asap,.,and many thanks for yr help.. and I will post the
code on the newsgroup in full when i complete it (hopefully) :o)

Regards,
Kam
 
I snipped these from a custom DataGrid object of mine, so
you need to replace all references to "this" to your
object which contains the scrollbars.

I may have been hasty giving you an answer, since it
appears that you must be adding the scrollbars yourself
to the panel. If so, then all the properties are already
exposed and there is no need for reflection.

So, you are not really looking to change the width/height
of your scrollbars, but rather the Maximum property and
most likely the Value property upon initial zoom.

Let's go through a trial run and see if I have it right.

Form 100x150 (FormBorderStyle = None)
Panel 85x135 (WxH) pixels.
Horiz & Vert scrollbars 100x15 & 15x135, respectively

Now if we place all these together with the H bar at the
bottom of your Form and the V bar at the right with the
Panel positioned at 0, 0 within the Form, then the Panel
(picture) is 100% visible. The H and V bars should have
their Maximum property set to 0.

When you zoom, you can calculate your scrollbars new
Maximum values as such:
myHBar.Maximum = myPanel.Width + myVBar.Width +
myHBar.LargeChange - myForm.Width
myVBar.Maximum = myPanel.Height + myHBar.Height +
myVBar.LargeChange - myForm.Height

In the ValueChanged events for the scrollbars:
private void hScrollBar1_ValueChanged(object sender,
System.EventArgs e)
{
this.myPanel.Left = -hScrollBar1.Value;
}

private void vScrollBar1_ValueChanged(object sender,
System.EventArgs e)
{
this.myPanel.Top = -vScrollBar1.Value;
}


I hope this can help a bit.

Cheers, Ian
 
Back
Top