[try Beta version]
Not logged in

 
HScrollBar value glitch

Oct 8, 2022 at 4:07am
Hi,

I created a HScrollBar control and set its maxvalue to 255.
Changing its value will show the value in a NumericUpDown control.

When I scroll to its maximum it only reaches 446... Shouldn't it reach 255?
To fix this I have to add 0x9 to the max value of the HSCrollBar.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// NumericUpDow1
			this->NumericUpDow1->Name = L"label1fda";
			this->NumericUpDow1->Location = System::Drawing::Point(150, 125);
			this->NumericUpDow1->Text = "Current Value";
			this->NumericUpDow1->Size = System::Drawing::Size(190,25);
			this->NumericUpDow1->ValueChanged += gcnew System::EventHandler(this, &Music_FormB::NumericUpDow1_Val_Changed);
			this->NumericUpDow1->Maximum = 255;

// Music Speed scroll
			this->Music_Scroll->AutoSize = true;
			this->Music_Scroll->Location = System::Drawing::Point(80, 75);
			this->Music_Scroll->Name = L"label1fda";
			this->Music_Scroll->Size = System::Drawing::Size(325, 30);
			this->Music_Scroll->TabIndex = 0;
			this->Music_Scroll->ValueChanged += gcnew System::EventHandler(this, &Music_FormB::Music_Scroll_Val_Changed);
			this->Music_Scroll->Maximum = 0xFF + 0X9;

private: System::Void Music_Scroll_Val_Changed(System::Object^ sender, System::EventArgs^ e)
	{
		NumericUpDow1->Value = Music_Scroll->Value;
	}
Last edited on Oct 8, 2022 at 4:10am
Oct 8, 2022 at 7:55am
Last edited on Oct 8, 2022 at 7:55am
Oct 8, 2022 at 8:13am
Are you sure a ScrollBar is the most suitable control for what you're doing? Have you considered using a TrackBar instead?
Last edited on Oct 8, 2022 at 8:15am
Oct 9, 2022 at 12:59am
Thanks Peter.

If you don't want the scrollbar to compensate for viewable space, you have to set your LargeChange to 1.


This solved my issue. What does it mean? I just don't understand why I need to change the "LargeChange" Value???

Oct 9, 2022 at 7:26am
Scrollbars are normally used when you want to display something in a space that is too small to show all at once. For example, this web page is probably too long to display all at once so your browser shows a vertical scrollbar to the right to let you choose which part of the page you want to view at the moment.


If "Maximum" is the y position at the bottom of the page (i.e. the height - 1), ...

... "Value" is the topmost y position of the page that is currently within the visible area, ...

... and "LargeChange" is the height of the visible area ...

... then it makes sense that you cannot scroll down so that Value becomes equal to the Maximum ...

... unless the visible area is only 1 pixel high or your browser allows you to scroll past the end of the page (so that the bottom gets all the way to the top).


I haven't had the opportunity to test and the official documentation doesn't seem to explain it like this but it is how I understand the discussions I linked to.
Last edited on Oct 9, 2022 at 7:53am
Oct 10, 2022 at 8:03am
Thanks for the explanation. Hmm that makes sense.
Topic archived. No new replies allowed.