473,385 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 5839
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.