Smooth scrolling of .net forms

Hi I am using forms in .net and I add many related shortcuts dynamically at runtime, I add these labels for a panel and add this panel to winform. When the number of reference characters increases, the form pops up an automatic scrollbar (vertically) ... Now when I scroll down using this autoscroll, the form does not update its view as I scroll, the form only updates when I stop scrolling .. Also when it is updated it looks too bad. I see him drawing slowly ...

Has anyone dealt with this before?

I've tried form.refresh () in the scroll event handler but doesn't seem to help.

Any hints?

+2


source to share


3 answers


Put this in your class (UserControl, Panel, etc.) then it will work with thumb dragging.



private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;

protected override void WndProc (ref Message m)
{
    if ((m.Msg == WM_HSCROLL || m.Msg == WM_VSCROLL)
    && (((int)m.WParam & 0xFFFF) == 5))
    {
        // Change SB_THUMBTRACK to SB_THUMBPOSITION
        m.WParam = (IntPtr)(((int)m.WParam & ~0xFFFF) | 4);
    }
base.WndProc (ref m);
}

      

+5


source


If you don't want to use WinAPI calls, you can do this:



// Add event handler to an existing panel
MyPanel.Scroll += new EventHandler(MyPanelScroll_Handler);

// Enables immediate scrolling of contents
private void MyPanelScroll_Handler(System.Object sender, System.Windows.Forms.ScrollEventArgs e)
{
    Panel p = sender As Panel;
    if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll) {
        p.HorizontalScroll.Value = e.NewValue;
    } else if (e.ScrollOrientation == ScrollOrientation.VerticalScroll) {
        p.VerticalScroll.Value = e.NewValue;
    }
}

      

+3


source


Try setting the DoubleBuffered property to True.

Update : In fact, this probably won't do anything since your controls are in a panel on your form. The inline panel control does not have a public DoubleBuffered property, so the way to do it is to add the username UserControl DBPanel to your project and change the code to inherit from Panel instead of UserControl (you can change this manually in the CS file after adding it). When you add a UserControl, the code looks like this:

public partial class DBPanel : UserControl
{
    public DBPanel()
    {
        InitializeComponent();
    }
}

      

Edit it so that it looks like this (change UserControl to Panel and add this this.DoubleBuffered = true; line to the constructor):

public partial class DBPanel : Panel
{
    public DBPanel()
    {
        InitializeComponent();
        this.DoubleBuffered = true;
    }
}

      

When you create a project, the compiler will close the line starting with "this.AutoScaleMode ...". Remove this line and rebuild.

Now you can use a DBPanel control in your form instead of a regular panel and that should take care of your flickering issue.

Update 2 : Sorry, I haven't read your question closely enough. You're right, the panel doesn't redraw until you release your scroll thumb. I think you just need to create your own UserControl to achieve this effect.

Basically, you will only have a UserControl with a VScrollBar binding on the right, and a panel with AutoScroll = false anchored to the left, taking up the rest of the space. Scroll and ValueChanged events when firing a VScrollBar while moving your finger up and down, so after adding a bunch of LinkLabels to the inner bar, you can use these events to change the top position of the bar and thus achieve the dynamic scrolling effect you are looking for.

It's annoying that Panel doesn't work by default, or even has an option that allows it.

+2


source







All Articles