Re: Panel mit Hintergundgrafik 1024x768 und ca. 50 Controls Labels performance Problem

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hallo Michael,

"Michael Böckinghoff" <webcrawler@xxxxxxxxxxxx> schrieb im Newsbeitrag
news:%23vbGm7IYHHA.1244@xxxxxxxxxxxxxxxxxxxxxxx
[...]
"Linke Kante Abquetscher" usw.
Ja genau die Labels sind das Problem
Und ja auf dem Panel ist es das Backgroundimage


(1) Schau, dass du das BackgroundImage nicht stretchen musst, also nur
bei einer Größenänderung der Form einmal eine Bitmap in der richtigen
Größe erzeugst.

(2) Ggf. das BackgroundImage mittels DrawImage sebst in OnPaint
ausgibst.

Wäre das keine Möglichkeit?

Ich werds auf alle Fälle mal ausprobieren, das blöde ist nur die
Oberfläche die du oben siehtst
wird über ien xml File gesteuert, je nachdem wie die Maschiene
aussieht kann man Beliebig seine Labels Button usw platzieren,

also sonne art xaml, ich glaub MS hat das von mir abgeguckt ;),

Wie gesagt ich muss mal gucken ob ich das irgendwie in das Konzept
der fexiblen Oberfäche einbauen kann...


Dass kannst du aber mit "Pseudo-Label" selbst nachstellen. Du kapselst
DrawString in eine geeignete Klasse, die aber keine Komponente ist.
Als Beispiel habe ich das Beispiel von gestern entsprechend
abgewandelt. Dann kannst du die Initialisierung mittels XML Datei auch
für die Pseudo-Label nachstellen.

Der Code ist wieder lauffähig (vgl. Anmerkungen gestern):

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


public class DurchsichtigeLabel2 : Form {


private Image bild;
private Panel panelLabel;
private DSPanel panelDrawString;


public static void Main() {
Application.EnableVisualStyles();
Application.Run( new DurchsichtigeLabel2() );
} // public static void Main()


public DurchsichtigeLabel2() {
Text = "Durchsichtige Label vs. DrawString";
ClientSize = new Size( 800, 600 );
CheckBox cb = new CheckBox();

cb.Parent = this;
cb.Location = new Point( (int) Font.GetHeight(), (int)
Font.GetHeight() );
cb.Size = new Size( 20 * (int) Font.GetHeight(), 2 * (int)
Font.GetHeight() );
cb.Text = "Durchsichtige Label aktiv";
cb.Click += new EventHandler( CBLabel );
cb.Checked = false;

cb = new CheckBox();
cb.Parent = this;
cb.Location = new Point( ClientSize.Width / 2 + (int)
Font.GetHeight(), (int) Font.GetHeight() );
cb.Size = new Size( 20 * (int) Font.GetHeight(), 2 * (int)
Font.GetHeight() );
cb.Text = "DrawString(...) aktiv";
cb.Click += new EventHandler( CBDrawString );
cb.Checked = false;

// BMP-Datei in 350 x 500 Pixel bei 24 Bit Farbtiefe
bild = Image.FromFile( "..//..//foto.bmp" );

panelLabel = new Panel();
panelLabel.Parent = this;
panelLabel.Location = new Point( (int) Font.GetHeight(), 2 *
(int) Font.GetHeight() + cb.Height );
panelLabel.Size = new Size( 350, 500 );
panelLabel.BackgroundImage = bild;
panelDrawString = new DSPanel();
panelDrawString.Parent = this;
panelDrawString.Location = new Point( ClientSize.Width / 2 +
(int) Font.GetHeight(), 2 * (int) Font.GetHeight() + cb.Height );
panelDrawString.Size = new Size( 350, 500 );
panelDrawString.BackgroundImage = bild;
} // public DurchsichtigeLabel2()


private void CBLabel( object sender, EventArgs ea ) {
CheckBox cb = (CheckBox) sender;
if (cb.Checked) {
panelLabel.Controls.Clear();
for (int i = 0; i < 20; i++) {
Label label = new Label();
label.Parent = panelLabel;
label.Location = new Point( (int) Font.GetHeight(),
(int) Font.GetHeight() + i * 2 * (int) Font.GetHeight() );
label.BackColor = Color.Transparent;
label.Text = "bla, bla, bla";

label = new Label();
label.Parent = panelLabel;
label.Location = new Point( (int) Font.GetHeight() +
100, (int) Font.GetHeight() + i * 2 * (int) Font.GetHeight() );
label.BackColor = Color.Transparent;
label.Text = "bla, bla, bla";

label = new Label();
label.Parent = panelLabel;
label.Location = new Point( (int) Font.GetHeight() +
200, (int) Font.GetHeight() + i * 2 * (int) Font.GetHeight() );
label.BackColor = Color.Transparent;
label.Text = "bla, bla, bla";
} // for (int i ...)
} else {
panelLabel.Controls.Clear();
} // else-if (...)
} // private void CBLabel( object sender, EventArgs ea )


private void CBDrawString( object sender, EventArgs ea ) {
CheckBox cb = (CheckBox) sender;
if (cb.Checked) {
panelDrawString.SuspendLayout();
for (int i = 0; i < 20; i++) {
PseudoLabel lbl = new PseudoLabel();
lbl.Font = panelDrawString.Font;
lbl.Location = new Point( (int) Font.GetHeight(),
(int) Font.GetHeight() + i * 2 * (int) Font.GetHeight() );
lbl.Text = "bla, bla, bla";
lbl.ForeColor = Color.Black;
panelDrawString.AddPseudoLabel( lbl );

lbl = new PseudoLabel();
lbl.Font = panelDrawString.Font;
lbl.Location = new Point( (int) Font.GetHeight() +
100, (int) Font.GetHeight() + i * 2 * (int) Font.GetHeight() );
lbl.Text = "bla, bla, bla";
lbl.ForeColor = Color.Black;
panelDrawString.AddPseudoLabel( lbl );

lbl = new PseudoLabel();
lbl.Font = panelDrawString.Font;
lbl.Location = new Point( (int) Font.GetHeight() +
200, (int) Font.GetHeight() + i * 2 * (int) Font.GetHeight() );
lbl.Text = "bla, bla, bla";
lbl.ForeColor = Color.Black;
panelDrawString.AddPseudoLabel( lbl );
} // for (int i ...)
panelDrawString.ResumeLayout();
} else {
panelDrawString.ClearPseudoLabels();
} // else-if (...)
} // private void CBDrawString( object sender, EventArgs ea )


} // public class DurchsichtigeLabel2 : Form



public class DSPanel : Panel {

private bool ausgabeAktiv = true;
private ArrayList labels;

public DSPanel() {
labels = new ArrayList();
} // public DSPanel()

public new void SuspendLayout() {
base.SuspendLayout();
ausgabeAktiv = false;
} // public new void SuspendLayout()

public new void ResumeLayout() {
base.ResumeLayout();
ausgabeAktiv = true;
Invalidate();
} // public void ResumeLayout()

public void AddPseudoLabel( PseudoLabel lbl ) {
labels.Add( lbl );
if (ausgabeAktiv) {
Invalidate();
} // if (...)
} // public void AddPseudoLabel( PseudoLabel lbl )

public void ClearPseudoLabels() {
labels = new ArrayList();
Invalidate();
} // public void ClearPseudoLabels()

// weitere Methoden nach Bedarf

protected override void OnPaint( PaintEventArgs e ) {
base.OnPaint( e );
Graphics grfx = e.Graphics;
for (int i = 0; i < labels.Count; i++) {
PseudoLabel lbl = (PseudoLabel) labels[ i ];
lbl.DrawString( grfx );
} // for (int i ...)
} // protected override void OnPaint( PaintEventArgs e )

// ggf. in Dispose die PseudoLabel freigeben (Brush !)

} // public class DSPanel : Panel



public class PseudoLabel {

private String text;
private Font font;
private Point location;
private Color foreColor;
private Brush brush;

public PseudoLabel() {
// bei Bedarf initialisieren
} // public PseudoLabel

public Color ForeColor {
get {
return foreColor;
} // get
set {
foreColor = value;
if (brush != null) {
brush.Dispose();
} // if (brush != null)
brush = new SolidBrush( foreColor );
} // set
} // public Color ForeColor

public Point Location {
get {
return location;
} // get
set {
location = value;
} // set
} // public Point Location

public Font Font {
get {
return font;
} // get
set {
font = value;
} // set
} // public Font Font

public string Text {
get {
return text;
} // get
set {
text = value;
} // set
} // public string Text

public void DrawString( Graphics grfx ) {
// Sicherheitsabfrage wäre nötig
grfx.DrawString( text, font, brush, (float) location.X,
(float) location.Y );
} // public void DrawString( Graphics grfx, Font font, Brush
brush, float x, float y )

// in Dispose ggf. brush freigeben

} // public class PseudoLabel


Wäre das nun besser?

Gruß,
Heiner.


.


Quantcast