472,951 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

Scrollbar mystery

I have a mystery where my scrollbar behaves differently from when I use it's
slider/arrow keys compared to when I manipulate it's value with a
onMouseWheel event...

When I manipulate my scrollbar's controls (the slider or the arrow key) to
go to the bottom, Once it reaches the bottom and cannot go any further I
somehow lose 9 pixels of height, so when it refreshes my image the bottom 9
pixels are clipped off.

But if I use my MouseWheel event and wheel down to the bottom, it lines up
perfectly. The MouseWheel event just takes the Delta and modified the
scorllbar.Value property directly, not allowing it to go max or < min.

So why does this happen?

The only properties I change are the scrollbar's Maximum and Minimum values,
where Minimum is 0 and Maximum is my image's height subtracted by the height
of the client size rectangle. Everything else left at default.

Nov 2 '06 #1
3 5824
I created a small sample app which demonstrates the behavior I am talking
about, since it's really hard for me to explain in text.

create a WindowsApplication and add my control like this:

ScrollControl s = new ScrollControl();
s.Location = new Point(10, 10);
s.Size = new Size(250, 250);
this.Controls.Add(s);

here is the control itself:

public partial class ScrollControl : UserControl
{
Bitmap bmp;

public ScrollControl()
{
InitializeComponent();

bmp = new Bitmap(400, 400);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.Black, 0, -vScrollBar1.Value, 400, 400);
Pen p = new Pen(Brushes.Red, 10);
g.DrawRectangle(p, 0, -vScrollBar1.Value, 400, 400);
g.Dispose();

vScrollBar1.Scroll += new ScrollEventHandler(vScrollBar1_Scroll);
}

protected override void OnPaint(PaintEventArgs e)
{
Point loc = new Point(0, -vScrollBar1.Value);
e.Graphics.DrawImageUnscaled(bmp, new Rectangle(loc, bmp.Size));
}

public override void Refresh()
{
this.OnPaint(new PaintEventArgs(this.CreateGraphics(), new
Rectangle(new Point(0, 0), this.ClientSize)));
}

protected override void OnSizeChanged(EventArgs e)
{
vScrollBar1.SetBounds(ClientRectangle.Right - vScrollBar1.Width,
0, vScrollBar1.Width, ClientRectangle.Height);
vScrollBar1.Maximum = bmp.Height - ClientSize.Height;
}

void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
Refresh();
}

protected override void OnMouseWheel(MouseEventArgs e)
{
int move = e.Delta / 10 * -1;
if (move 0)
{
if (vScrollBar1.Value <= vScrollBar1.Maximum &&
vScrollBar1.Value + move >= vScrollBar1.Maximum)
vScrollBar1.Value = vScrollBar1.Maximum;
else
vScrollBar1.Value += move;
}
else
{
if (vScrollBar1.Value >= vScrollBar1.Minimum &&
vScrollBar1.Value + move <= vScrollBar1.Minimum)
vScrollBar1.Value = vScrollBar1.Minimum;
else
vScrollBar1.Value += move;
}
Refresh();
}
}
Nov 2 '06 #2
int move = e.Delta * SystemInformation.MouseWheelScrollLines / 120;

"MrNobody" <Mr******@discussions.microsoft.comwrote in message
news:9D**********************************@microsof t.com...
>I created a small sample app which demonstrates the behavior I am talking
about, since it's really hard for me to explain in text.
protected override void OnMouseWheel(MouseEventArgs e)
{
int move = e.Delta / 10 * -1;
if (move 0)
{
if (vScrollBar1.Value <= vScrollBar1.Maximum &&
vScrollBar1.Value + move >= vScrollBar1.Maximum)
vScrollBar1.Value = vScrollBar1.Maximum;
else
vScrollBar1.Value += move;
}
else
{
if (vScrollBar1.Value >= vScrollBar1.Minimum &&
vScrollBar1.Value + move <= vScrollBar1.Minimum)
vScrollBar1.Value = vScrollBar1.Minimum;
else
vScrollBar1.Value += move;
}
Refresh();
}
}


Nov 3 '06 #3


"Alex Fu" wrote:
int move = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
Ah, that makes the mouse wheel scrolling alot smoother, thanks!

Just that, it didnt solve the problem with the normal scroll bar control...

notice how when you you the mouse wheel to go to the very bottom of the
scroll area, you will be able to see the bottom red border?

now try doing the same thing using the scroll bar control, either the down
arrow or the thumb tab. It wont let you each the actual bottom so you can
never see that bottom red border...

why is that?
Nov 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Marion | last post by:
Hello. I am using Tkinter and Pmw. I would like to build 2 canvases/frames that are scrollable together horizontally, and independently vertically (so, the vertical scrollbars should not be...
7
by: Sujan | last post by:
Hello all, Is it possible to remove scrollbar(s) without using frames. Is there any code which could be applied in body tag to remove scrollbar(s). Thanks in adv, Sujan
4
by: Price Brattin | last post by:
I dragged a datagrid onto a VB.Net WinForm and used the properties page and a few lines of code to set it up, including the DataSource. No wizard setup was used. It works fine except for one...
9
by: kjs | last post by:
Is there any was to control the color of the scrollbars when using the 'overflow: scroll' attribute? TIA, Karl
0
by: h-h | last post by:
BODY { scrollbar-face-color: #f5f5f5; scrollbar-highlight-color: #666666; scrollbar-shadow-color: #666666; scrollbar-3dlight-color: #ffffff; scrollbar-arrow-color: #666666;...
1
by: Shun | last post by:
Hello, How to the add a blue color scrollbar to the browser Left and bottom. Thanx Shun
2
by: kurt sune | last post by:
How do I render the scrollbars by CSS in a listbox? I have understood that an asp listbox gets rendered as a select element. So I tried first by adding a style element: ..TA...
3
by: nicky77 | last post by:
Hi, before you say it i know frames are bad practice - but i'm developing dynamic content on a site which has already been designed, so alas there's no option but to use them. Anyway, I just want to...
1
by: Tom | last post by:
First, I posted a similar request for help in another group and now don't find the posting. Problem with my newsreader perhaps ... but apologies if this appears as a cross posting. My code is...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.