Windows Develop Bookmark and Share   
 index > Windows Forms Designer > My userControl is Blinking... :-(
 

My userControl is Blinking... :-(

Hi,

I developed a Slider UserControl to practice on VC2003 Framework 1.1. Now, i try to export the same control to VC2005 Framwork 2.0... but... oh my god, the Slider Control Blinks a lot, it's not an acceptable control.

Note:

Thumb.xxx is a Label.xxx

That's my draw routine:

private void OwnDraw()
{
PointF pStart = new PointF(0, 0);
PointF pEnd = new PointF(0, this.Height);

LinearGradientBrush lgb1 = new LinearGradientBrush(pStart, pEnd, m_RightUpColor, m_RightDownColor);
LinearGradientBrush lgb2 = new LinearGradientBrush(pStart, pEnd, m_LeftUpColor, m_LeftDownColor);

doublebuff = (Image)new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(doublebuff);

g.FillRectangle(lgb1, 0, 0, Thumb.Left, this.Height);
g.FillRectangle(lgb2, Thumb.Left + Thumb.Width, 0, this.Width, this.Height);

this.Invalidate();
}

Paint User control event:

private void hslider_Paint(object sender, PaintEventArgs e)
{
this.BackgroundImage = doublebuff;
}

Update hSlider ( property value ):

public int Value
{
get { return m_Value; }
set
{
if (this.m_Update == true)
{
if (value <= m_Max)
m_Value = value;
else
m_Value = m_Max;

if (value >= m_Min)
m_Value = value;
else
m_Value = m_Min;

ReallocateThumb();
this.OwnDraw();
}
}
}


Some suggestion/tips... are wellcome.
Thanks.
Mutola  Wednesday, July 26, 2006 8:43 AM
In the constructor, try using SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true); This prevents the background from being erased.
nobugz  Wednesday, July 26, 2006 9:14 AM
In the constructor, try using SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true); This prevents the background from being erased.
nobugz  Wednesday, July 26, 2006 9:14 AM
Great !!!

Thank you very much, nobugz :-)
Mutola  Wednesday, July 26, 2006 10:26 AM

You can use google to search for other answers

Custom Search

More Threads

• Overriding TextBox.WndProc problems
• Testing to see if a lable has been made...
• Resizing a control problem in design mode
• Validation With Tab Pages
• Parent Property
• DataGridView: Multiple column headers
• Custom Controls in Toolbox to be listed in a specific category
• Exposing ListView Column Header Collection Editor on a composite control
• Sorting CategoryAttributes for PropertyGrids
• CollectionTypeConverter / ArrayTypeConverter with PropertyGrid