I am having a tough time in vb.net to make the scrollbars to work of the contents of a panel.... here is my code

Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
Panel122.Left = HScrollBar1.Value

now, i want to change .Left to .Right, but it won't let me?
HELP!!!!!

Dani AI

Generated

A few clarifications and practical options that fill the gap in the thread between and .

First, there is a Right property on Windows Forms controls, but it is read-only — Right is computed as Left + Width, so you cannot assign to Right directly; move a control by changing Left (or Width/Bounds) instead. (learn.microsoft.com)

If the goal is "put the panel against the right edge" compute Left from the parent/client width. For example:

' align panel's right edge to its parent's client area
Dim newLeft As Integer = Panel122.Parent.ClientSize.Width - Panel122.Width
Panel122.Left = newLeft

This uses the parent client width (not the window chrome) so the panel lines up visually with the visible client area. (stackoverflow.com)

If you want scrolling of content inside the panel, prefer the built-in auto-scroll support instead of manually moving controls. Enable AutoScroll, set AutoScrollMinSize (or add child controls outside the visible area) and then use AutoScrollPosition or ScrollControlIntoView to move the viewport. Note: AutoScrollPosition behaves oddly when read back (it returns negative offsets), so assign positive coordinates and be aware of that sign flip. (learn.microsoft.com)

If you must use a separate HScrollBar, set its range to match the unseen content and map the value to the content offset. The ScrollBar.Maximum needs attention (it usually includes a LargeChange adjustment), so a typical formula is something like contentWidth - viewportWidth (+ LargeChange), and then set the inner content's Left to the negative of the scrollbar value. Also watch docking/anchoring — those will overwrite manual Left adjustments; add dynamic repositioning after layout (OnShown / PerformLayout) when creating controls at runtime. (learn.microsoft.com)

Summary: Right exists but is read-only; align using Left = parent.ClientSize.Width - Width; for scrolling prefer Panel.AutoScroll; if you use a separate ScrollBar, set Maximum carefully and map values to a negative offset of the inner content.

Recommended Answers

All 3 Replies

The Left property is the horizontal position of the panel within it's parent container, there is no Right property.
If you need to move the panel from left to right, then you have to change the value of Left.

Panel122.Left = 0, means that the panel is at it's left-most position.
Panel122.Left = parent.Width, means that the panel is at it's right-most position.

Bigggg help =D thanks+D

You're welcome. :)
Please mark this thread as solved if your problem is fixed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.