Hi,
We have placed ScrollableControl within one of the SplitterContainer panel. AutoScrolling is enabled on the ScrollableControl as well as DoubleBuffering.
We have some static drawing to be drawn in a fixed (absolute) position and some drawing to be drawn considering the Scroll position (relative to the view).
As scrolled, it appears as all the drawing is moving for a moment and redrawn again as expected.
Is there any way flickering can be avoided when scrolling?
The control in the following code is placed on one of the panel of a SplitContainer in a form.
Regards,
NaderUK
We have placed ScrollableControl within one of the SplitterContainer panel. AutoScrolling is enabled on the ScrollableControl as well as DoubleBuffering.
We have some static drawing to be drawn in a fixed (absolute) position and some drawing to be drawn considering the Scroll position (relative to the view).
As scrolled, it appears as all the drawing is moving for a moment and redrawn again as expected.
Is there any way flickering can be avoided when scrolling?
The control in the following code is placed on one of the panel of a SplitContainer in a form.
class GraphView : ScrollableControl
{
int X = 200;
int Y = 50;
int newval = 0;
int _StartDev = 0;
public void Draw(Graphics Gx)
{
//Force to Display Scroll
AutoScrollMinSize = new Size(X, 1000);
if (VerticalScroll != null && VerticalScroll.Visible)
{
VerticalScroll.SmallChange = 34;
}
DrawTitle(Gx);
DrawTextinRec(Gx);
}
//Display "Title" at this fixed position (45,0), regarless of Scrolling
void DrawTitle(Graphics Gx)
{
Font ft = new Font("Arial", 10, FontStyle.Bold);
Rectangle rc = new Rectangle(45, 0, this.Width, 50);
Gx.DrawString("Title", ft, Brushes.Black, rc);
ft.Dispose();
}
void DrawTextinRec(Graphics Gx)
{
Font ft = new Font("Arial", 10, FontStyle.Bold);
//Scroll This text only
Rectangle rc = new Rectangle(X, Y - newval, 50, 110);
Gx.DrawRectangle(Pens.Black, rc);
StringFormat SF = new StringFormat();
SF.LineAlignment = StringAlignment.Center;
Gx.DrawString("This is the test window", ft, Brushes.Black, rc, SF);
ft.Dispose();
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// GraphView
//
this.Scroll += new System.Windows.Forms.ScrollEventHandler(this.GraphView_Scroll);
this.ResumeLayout(false);
}
private void GraphView_Scroll(object sender, ScrollEventArgs e)
{
if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
newval = e.NewValue;
if (VerticalScroll == null)
return;
Int32 y = e.NewValue;
Int32 yMax = VerticalScroll.Maximum;
Int32 iStartDevOrig = y / 34;
switch (e.Type)
{
case ScrollEventType.First:
y = 0;
break;
case ScrollEventType.Last:
y = Int32.MaxValue;
break;
case ScrollEventType.SmallDecrement:
y -= VerticalScroll.SmallChange;
break;
case ScrollEventType.SmallIncrement:
y += VerticalScroll.SmallChange;
break;
case ScrollEventType.LargeDecrement:
y -= VerticalScroll.LargeChange;
break;
case ScrollEventType.LargeIncrement:
y += VerticalScroll.LargeChange;
break;
case ScrollEventType.ThumbTrack:
y = e.NewValue;
break;
}
if (y < 0)
y = 0;
else if (y > yMax)
y = yMax;
_StartDev = y / 34;
newval = e.NewValue = _StartDev * 34;
Invalidate();
}
Refresh();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Draw(e.Graphics);
}
}
Thank you.Regards,
NaderUK