Smooth panel scroll

M

mateusz.zajakala

Hi,

I have panel (with autoscroll property) on which I'm dynamicaly adding
of controls. When I want to scroll my panel using scrollbars it
freezes all the controls added on that panel, makes them nasty
stretch.

Is there any way to prevent that stretch, and scroll panel smoothly?

I tried to add DoEvents() to Scroll event of my panel, which prevent
controls from stretching, but after that new problem shows up. When
I'm scrolling my panel very fast from in ex. right to left, graphics
on panel hang over, and freez too.

I will be very gratefull for any kind of help, tpis or tricks how to
solve that problem.

Mateusz Zaj±ka³a
 
P

Peter Duniho

I have panel (with autoscroll property) on which I'm dynamicaly adding
of controls. When I want to scroll my panel using scrollbars it
freezes all the controls added on that panel, makes them nasty
stretch.

Is there any way to prevent that stretch, and scroll panel smoothly?

Normally, it would do so without any extra effort on your part. That
means that you've done something unusual that's causing the problem.

You should post a concise-but-complete sample of code that reliably
demonstrates the problem. Then we'll have a better idea of what problem
you're dealing with.

Pete
 
M

mateusz.zajakala

Normally, it would do so without any extra effort on your part. That
means that you've done something unusual that's causing the problem.

I don't think it would normaly works fine. Just try to add panel (ex.
400x300) to form, and then 15 columns of controls (textboxes) and 5
rows. Set panel autoscroll property to true, and you'll see what I
mean. When scrolling panel using thumb you'll see terrible scretch
effect.

Thanks for answer,
Mateusz Zaj±ka³a
 
P

Peter Duniho

I don't think it would normaly works fine. Just try to add panel (ex.
400x300) to form, and then 15 columns of controls (textboxes) and 5
rows. Set panel autoscroll property to true, and you'll see what I
mean. When scrolling panel using thumb you'll see terrible scretch
effect.

Well, I tried exactly what you suggested. It works fine on my computer.
Sample code below.

Pete


using System;
using System.Windows.Forms;
using System.Drawing;

namespace TestAutoScrollPanel
{
public partial class Form1 : Form
{
public Form1()
{
int cyHeight = 0;
Point ptLocation = new Point(5, 5);

InitializeComponent();

for (int irow = 0; irow < 5; irow++)
{
for (int icol = 0; icol < 15; icol++)
{
TextBox tbx = new TextBox();

panel1.Controls.Add(tbx);
tbx.Location = ptLocation;
ptLocation.X += tbx.Width + 5;
cyHeight = tbx.Height;
}

ptLocation.X = 5;
ptLocation.Y += cyHeight + 5;
}
}

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.AutoScroll = true;
this.panel1.Location = new System.Drawing.Point(13, 13);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(417, 300);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(442, 366);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Panel panel1;
}

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
 
M

mateusz.zajakala

Well, I tried exactly what you suggested. It works fine on my computer.
Sample code below.

Incredible. I tried your example, and I still have the same problem.
BUT when I run my application on another computer it worked just fine!
Looks like the problem is in my computer, not in code, so... Thank you
for your help, and sorry for posting problem which has nothing to do
with this group :>
 
P

Peter Duniho

Incredible. I tried your example, and I still have the same problem.
BUT when I run my application on another computer it worked just fine!
Looks like the problem is in my computer, not in code, so... Thank you
for your help, and sorry for posting problem which has nothing to do
with this group :>

That's okay...sometimes what's needed is independent confirmation that
your code is _correct_, so you can move on to other diagnostics. :)
Happy to help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top