VB.NET - To get the scroll position at the bottom in vb.net

Asked By abinav shankar on 23-Aug-11 07:55 AM
hi i want to set the scroll position at the bottom i am using a panel and i need this for windows application
Sreekumar P replied to abinav shankar on 23-Aug-11 07:58 AM
Hi,

here is the oldschool way to do it. It will probably also be possible with caret positions or something, using .NET

This is the form code. Put two richtextbox's on the form and set the vscroll event for the first textbox to the myRichTextBox1_VScroll method.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
 
namespace RichTextBoxScroll
{
  public enum ScrollBarType : uint
  {
    SbHorz = 0,
    SbVert = 1,
    SbCtl = 2,
    SbBoth = 3
  }
 
  public enum Message : uint
  {
    WM_VSCROLL = 0x0115
  }
 
  public enum ScrollBarCommands : uint
  {
    SB_THUMBPOSITION = 4
  }
 
  public partial class Form1 : Form
  {
    [DllImport( "User32.dll" )]
    public extern static int GetScrollPos( IntPtr hWnd, int nBar );
 
    [DllImport( "User32.dll" )]
    public extern static int SendMessage( IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam );
 
    public Form1()
    {
      InitializeComponent();
    }
 
    private void myRichTextBox1_VScroll( object sender, EventArgs e )
    {
      int nPos = GetScrollPos( richTextBox1.Handle, (int)ScrollBarType.SbVert );
      nPos <<= 16;
      uint wParam = (uint)ScrollBarCommands.SB_THUMBPOSITION | (uint)nPos;
      SendMessage( richTextBox2.Handle, (int)Message.WM_VSCROLL, new IntPtr( wParam ), new IntPtr( 0 ) );
    }
  }
}
Web Star replied to abinav shankar on 23-Aug-11 08:01 AM
you just need to set Me.Panel1.AutoScroll = True and put height and width of panel equals form height and width 
http://www.java2s.com/Tutorial/VB/0260__GUI/Panelautoscrollposition.htm
dipa ahuja replied to abinav shankar on 23-Aug-11 01:59 PM
Panel is used as the container of the other constrols..

and as you insert control in the panel , scrollbar will be added based on the size..

So set the AutoScrollbar= true