M
Michael Böckinghoff
Hello NG,
i have a solution with a control dll for the compact Framework.
For exampel with a Button wich behaves on a special way i want to.
Im painting the button in the overriden OnPaint Method of the control.
Now i see sometimes a littel flickering wich on the full framwork i could
avoid by this 2 codelines:
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
How can i do this in the compactframework?
TIA!
Michael
Codesnippet of the OnPaint methode:
#######################
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//Nichts machen damit nicht doppelt gezeichnet wird
//base.OnPaintBackground (pevent);
}
/// <summary>
/// Override the OnPaint method so we can draw the background image
and the text.
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
SolidBrush brush = new SolidBrush(this.ForeColor);
Graphics g = e.Graphics;
if (this._bPressed)
{
if (this._imgBackgroundImage2 != null)
g.DrawImage(this._imgBackgroundImage2, 0, 0);
else
{
if (this._imgBackgroundImage != null)
{
g.DrawImage(this._imgBackgroundImage, 0, 0);
}
else
{
// Ansonsten ein Graues Kästchen so groß wie der
Button zeichnen!
SolidBrush brushBack = new
SolidBrush(this.BackColor);
g.FillRectangle(brushBack, 0, 0, ClientSize.Width,
ClientSize.Height);
}
}
if (!_bDrawWithoutBorder)
DrawButtonDown(g);
}
else
{
if (this._imgBackgroundImage != null)
g.DrawImage(this._imgBackgroundImage, 0, 0);
else
{
// Ansonsten ein Graues Kästchen so groß wie der Button
zeichnen!
SolidBrush brushBack = new SolidBrush(this.BackColor);
g.FillRectangle(brushBack, 0, 0, ClientSize.Width,
ClientSize.Height);
}
if (!_bDrawWithoutBorder)
DrawButtonUp(g);
}
// LED Links oben einzeichen wenn LED angezeigt werden soll
if (this._bShowLED)
{
if (this._bLEDStatus)
g.DrawImage(this._imgLEDON, 2, 2);
else
g.DrawImage(this._imgLEDOFF, 2, 2);
}
// Wenn Enable false ist dann zeichne ein Rotes X durch das
Control
if (!this.Enabled)
{
DrawRedXross(g);
}
RectangleF recText;
if (this._bShowLED)
{
recText = new RectangleF(15, 2, this.ClientSize.Width - 17,
this.ClientSize.Height - 4);
}
else
{
recText = new RectangleF(2, 2, this.ClientSize.Width - 4,
this.ClientSize.Height - 4);
}
if (this.Text.Length > 0)
{
SizeF sizeText = e.Graphics.MeasureString(this.Text,
this.Font);
StringFormat stringFormat = new
StringFormat(StringFormatFlags.NoClip);
if (sizeText.Width > recText.Width)
{
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Near;
}
else
{
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
}
e.Graphics.DrawString(this.Text,
this.Font,
new SolidBrush(this.ForeColor),
recText,
stringFormat);
}
brush.Dispose();
}
i have a solution with a control dll for the compact Framework.
For exampel with a Button wich behaves on a special way i want to.
Im painting the button in the overriden OnPaint Method of the control.
Now i see sometimes a littel flickering wich on the full framwork i could
avoid by this 2 codelines:
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
How can i do this in the compactframework?
TIA!
Michael
Codesnippet of the OnPaint methode:
#######################
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//Nichts machen damit nicht doppelt gezeichnet wird
//base.OnPaintBackground (pevent);
}
/// <summary>
/// Override the OnPaint method so we can draw the background image
and the text.
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
SolidBrush brush = new SolidBrush(this.ForeColor);
Graphics g = e.Graphics;
if (this._bPressed)
{
if (this._imgBackgroundImage2 != null)
g.DrawImage(this._imgBackgroundImage2, 0, 0);
else
{
if (this._imgBackgroundImage != null)
{
g.DrawImage(this._imgBackgroundImage, 0, 0);
}
else
{
// Ansonsten ein Graues Kästchen so groß wie der
Button zeichnen!
SolidBrush brushBack = new
SolidBrush(this.BackColor);
g.FillRectangle(brushBack, 0, 0, ClientSize.Width,
ClientSize.Height);
}
}
if (!_bDrawWithoutBorder)
DrawButtonDown(g);
}
else
{
if (this._imgBackgroundImage != null)
g.DrawImage(this._imgBackgroundImage, 0, 0);
else
{
// Ansonsten ein Graues Kästchen so groß wie der Button
zeichnen!
SolidBrush brushBack = new SolidBrush(this.BackColor);
g.FillRectangle(brushBack, 0, 0, ClientSize.Width,
ClientSize.Height);
}
if (!_bDrawWithoutBorder)
DrawButtonUp(g);
}
// LED Links oben einzeichen wenn LED angezeigt werden soll
if (this._bShowLED)
{
if (this._bLEDStatus)
g.DrawImage(this._imgLEDON, 2, 2);
else
g.DrawImage(this._imgLEDOFF, 2, 2);
}
// Wenn Enable false ist dann zeichne ein Rotes X durch das
Control
if (!this.Enabled)
{
DrawRedXross(g);
}
RectangleF recText;
if (this._bShowLED)
{
recText = new RectangleF(15, 2, this.ClientSize.Width - 17,
this.ClientSize.Height - 4);
}
else
{
recText = new RectangleF(2, 2, this.ClientSize.Width - 4,
this.ClientSize.Height - 4);
}
if (this.Text.Length > 0)
{
SizeF sizeText = e.Graphics.MeasureString(this.Text,
this.Font);
StringFormat stringFormat = new
StringFormat(StringFormatFlags.NoClip);
if (sizeText.Width > recText.Width)
{
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Near;
}
else
{
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
}
e.Graphics.DrawString(this.Text,
this.Font,
new SolidBrush(this.ForeColor),
recText,
stringFormat);
}
brush.Dispose();
}