Flackernde Buttons???



  • Hallo.

    Warum flackern/verschwinden die Buttons beim Button_Click-Ereignis?

    +++++++++++++++++++++++++++++++++++++++++
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    
    namespace WindowsApplication1
    {
    	/// <summary>
    	/// Zusammenfassung für Form1.
    	/// </summary>
    	public class Form1 : System.Windows.Forms.Form
    	{
    		private int AnimationRate = 1;
    		private int y = 24;
    		private System.Windows.Forms.Panel panel4;
    		private System.Windows.Forms.Panel panel5;
    		private System.Windows.Forms.Panel panel6;
    		private System.Windows.Forms.Panel panel13;
    		private System.Windows.Forms.Panel panel14;
    		private System.Windows.Forms.Panel panel15;
    		private System.Windows.Forms.Panel panel19;
    		private System.Windows.Forms.Panel panel20;
    		private System.Windows.Forms.Panel panel21;
    		private System.Windows.Forms.Panel panContainer1;
    		private System.Windows.Forms.Panel panContainer2;
    		private System.Windows.Forms.Panel panContainer3;
    		private System.Windows.Forms.Button btnZRI;
    		private System.Windows.Forms.Button btnZRII;
    		private System.Windows.Forms.Button btnZRIII;
    		private System.Windows.Forms.Panel panContainer4;
    		private System.Windows.Forms.Button btnZRIV;
    		private System.Windows.Forms.Panel panel2;
    		private System.Windows.Forms.Panel panel3;
    		private System.Windows.Forms.Panel panel7;
    		/// <summary>
    		/// Erforderliche Designervariable.
    		/// </summary>
    		private System.ComponentModel.Container components = null;
    
    		public Form1()
    		{
    			//
    			// Erforderlich für die Windows Form-Designerunterstützung
    			//
    			InitializeComponent();
    
    			//
    			// TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
    			//
    		}
    
    		/// <summary>
    		/// Die verwendeten Ressourcen bereinigen.
    		/// </summary>
    		protected override void Dispose( bool disposing )
    		{
    			if( disposing )
    			{
    				if (components != null) 
    				{
    					components.Dispose();
    				}
    			}
    			base.Dispose( disposing );
    		}
    
    		#region Vom Windows Form-Designer generierter Code
    		/// <summary>
    		/// Erforderliche Methode für die Designerunterstützung. 
    		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
    		/// </summary>
    		private void InitializeComponent()
    		{
    			this.panContainer1 = new System.Windows.Forms.Panel();
    			this.panel6 = new System.Windows.Forms.Panel();
    			this.panel5 = new System.Windows.Forms.Panel();
    			this.panel4 = new System.Windows.Forms.Panel();
    			this.btnZRI = new System.Windows.Forms.Button();
    			this.panContainer2 = new System.Windows.Forms.Panel();
    			this.panel13 = new System.Windows.Forms.Panel();
    			this.panel14 = new System.Windows.Forms.Panel();
    			this.panel15 = new System.Windows.Forms.Panel();
    			this.btnZRII = new System.Windows.Forms.Button();
    			this.panContainer3 = new System.Windows.Forms.Panel();
    			this.panel19 = new System.Windows.Forms.Panel();
    			this.panel20 = new System.Windows.Forms.Panel();
    			this.panel21 = new System.Windows.Forms.Panel();
    			this.btnZRIII = new System.Windows.Forms.Button();
    			this.panContainer4 = new System.Windows.Forms.Panel();
    			this.btnZRIV = new System.Windows.Forms.Button();
    			this.panel2 = new System.Windows.Forms.Panel();
    			this.panel3 = new System.Windows.Forms.Panel();
    			this.panel7 = new System.Windows.Forms.Panel();
    			this.panContainer1.SuspendLayout();
    			this.panContainer2.SuspendLayout();
    			this.panContainer3.SuspendLayout();
    			this.panContainer4.SuspendLayout();
    			this.SuspendLayout();
    			// 
    			// panContainer1
    			// 
    			this.panContainer1.BackColor = System.Drawing.SystemColors.ActiveCaption;
    			this.panContainer1.Controls.Add(this.panel6);
    			this.panContainer1.Controls.Add(this.panel5);
    			this.panContainer1.Controls.Add(this.panel4);
    			this.panContainer1.Controls.Add(this.btnZRI);
    			this.panContainer1.Dock = System.Windows.Forms.DockStyle.Top;
    			this.panContainer1.Location = new System.Drawing.Point(0, 0);
    			this.panContainer1.Name = "panContainer1";
    			this.panContainer1.Size = new System.Drawing.Size(344, 120);
    			this.panContainer1.TabIndex = 0;
    			// 
    			// panel6
    			// 
    			this.panel6.BackColor = System.Drawing.Color.Silver;
    			this.panel6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel6.Location = new System.Drawing.Point(232, 40);
    			this.panel6.Name = "panel6";
    			this.panel6.Size = new System.Drawing.Size(88, 64);
    			this.panel6.TabIndex = 3;
    			// 
    			// panel5
    			// 
    			this.panel5.BackColor = System.Drawing.Color.Silver;
    			this.panel5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel5.Location = new System.Drawing.Point(128, 40);
    			this.panel5.Name = "panel5";
    			this.panel5.Size = new System.Drawing.Size(88, 64);
    			this.panel5.TabIndex = 2;
    			// 
    			// panel4
    			// 
    			this.panel4.BackColor = System.Drawing.Color.Silver;
    			this.panel4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel4.Location = new System.Drawing.Point(24, 40);
    			this.panel4.Name = "panel4";
    			this.panel4.Size = new System.Drawing.Size(88, 64);
    			this.panel4.TabIndex = 1;
    			// 
    			// btnZRI
    			// 
    			this.btnZRI.BackColor = System.Drawing.Color.Turquoise;
    			this.btnZRI.Dock = System.Windows.Forms.DockStyle.Top;
    			this.btnZRI.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
    			this.btnZRI.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    			this.btnZRI.ForeColor = System.Drawing.SystemColors.ControlText;
    			this.btnZRI.Location = new System.Drawing.Point(0, 0);
    			this.btnZRI.Name = "btnZRI";
    			this.btnZRI.Size = new System.Drawing.Size(344, 24);
    			this.btnZRI.TabIndex = 0;
    			this.btnZRI.Text = "button1";
    			this.btnZRI.Click += new System.EventHandler(this.btnZRI_Click);
    			// 
    			// panContainer2
    			// 
    			this.panContainer2.BackColor = System.Drawing.Color.Tan;
    			this.panContainer2.Controls.Add(this.panel13);
    			this.panContainer2.Controls.Add(this.panel14);
    			this.panContainer2.Controls.Add(this.panel15);
    			this.panContainer2.Controls.Add(this.btnZRII);
    			this.panContainer2.Dock = System.Windows.Forms.DockStyle.Top;
    			this.panContainer2.Location = new System.Drawing.Point(0, 120);
    			this.panContainer2.Name = "panContainer2";
    			this.panContainer2.Size = new System.Drawing.Size(344, 112);
    			this.panContainer2.TabIndex = 2;
    			// 
    			// panel13
    			// 
    			this.panel13.BackColor = System.Drawing.Color.Silver;
    			this.panel13.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel13.Location = new System.Drawing.Point(232, 32);
    			this.panel13.Name = "panel13";
    			this.panel13.Size = new System.Drawing.Size(88, 64);
    			this.panel13.TabIndex = 9;
    			// 
    			// panel14
    			// 
    			this.panel14.BackColor = System.Drawing.Color.Silver;
    			this.panel14.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel14.Location = new System.Drawing.Point(128, 32);
    			this.panel14.Name = "panel14";
    			this.panel14.Size = new System.Drawing.Size(88, 64);
    			this.panel14.TabIndex = 8;
    			// 
    			// panel15
    			// 
    			this.panel15.BackColor = System.Drawing.Color.Silver;
    			this.panel15.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel15.Location = new System.Drawing.Point(24, 32);
    			this.panel15.Name = "panel15";
    			this.panel15.Size = new System.Drawing.Size(88, 64);
    			this.panel15.TabIndex = 7;
    			// 
    			// btnZRII
    			// 
    			this.btnZRII.BackColor = System.Drawing.Color.Turquoise;
    			this.btnZRII.Dock = System.Windows.Forms.DockStyle.Top;
    			this.btnZRII.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
    			this.btnZRII.Location = new System.Drawing.Point(0, 0);
    			this.btnZRII.Name = "btnZRII";
    			this.btnZRII.Size = new System.Drawing.Size(344, 24);
    			this.btnZRII.TabIndex = 1;
    			this.btnZRII.Text = "button2";
    			this.btnZRII.Click += new System.EventHandler(this.btnZRII_Click);
    			// 
    			// panContainer3
    			// 
    			this.panContainer3.BackColor = System.Drawing.Color.ForestGreen;
    			this.panContainer3.Controls.Add(this.btnZRIII);
    			this.panContainer3.Controls.Add(this.panel19);
    			this.panContainer3.Controls.Add(this.panel20);
    			this.panContainer3.Controls.Add(this.panel21);
    			this.panContainer3.Dock = System.Windows.Forms.DockStyle.Top;
    			this.panContainer3.Location = new System.Drawing.Point(0, 232);
    			this.panContainer3.Name = "panContainer3";
    			this.panContainer3.Size = new System.Drawing.Size(344, 120);
    			this.panContainer3.TabIndex = 4;
    			// 
    			// panel19
    			// 
    			this.panel19.BackColor = System.Drawing.Color.Silver;
    			this.panel19.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel19.Location = new System.Drawing.Point(232, 40);
    			this.panel19.Name = "panel19";
    			this.panel19.Size = new System.Drawing.Size(88, 64);
    			this.panel19.TabIndex = 9;
    			// 
    			// panel20
    			// 
    			this.panel20.BackColor = System.Drawing.Color.Silver;
    			this.panel20.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel20.Location = new System.Drawing.Point(128, 40);
    			this.panel20.Name = "panel20";
    			this.panel20.Size = new System.Drawing.Size(88, 64);
    			this.panel20.TabIndex = 8;
    			// 
    			// panel21
    			// 
    			this.panel21.BackColor = System.Drawing.Color.Silver;
    			this.panel21.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel21.Location = new System.Drawing.Point(24, 40);
    			this.panel21.Name = "panel21";
    			this.panel21.Size = new System.Drawing.Size(88, 64);
    			this.panel21.TabIndex = 7;
    			// 
    			// btnZRIII
    			// 
    			this.btnZRIII.BackColor = System.Drawing.Color.Turquoise;
    			this.btnZRIII.Dock = System.Windows.Forms.DockStyle.Top;
    			this.btnZRIII.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
    			this.btnZRIII.Location = new System.Drawing.Point(0, 0);
    			this.btnZRIII.Name = "btnZRIII";
    			this.btnZRIII.Size = new System.Drawing.Size(344, 24);
    			this.btnZRIII.TabIndex = 13;
    			this.btnZRIII.Text = "button3";
    			this.btnZRIII.Click += new System.EventHandler(this.btnZRIII_Click);
    			// 
    			// panContainer4
    			// 
    			this.panContainer4.BackColor = System.Drawing.Color.DarkKhaki;
    			this.panContainer4.Controls.Add(this.btnZRIV);
    			this.panContainer4.Controls.Add(this.panel2);
    			this.panContainer4.Controls.Add(this.panel3);
    			this.panContainer4.Controls.Add(this.panel7);
    			this.panContainer4.Dock = System.Windows.Forms.DockStyle.Top;
    			this.panContainer4.Location = new System.Drawing.Point(0, 352);
    			this.panContainer4.Name = "panContainer4";
    			this.panContainer4.Size = new System.Drawing.Size(344, 120);
    			this.panContainer4.TabIndex = 5;
    			// 
    			// btnZRIV
    			// 
    			this.btnZRIV.BackColor = System.Drawing.Color.Turquoise;
    			this.btnZRIV.Dock = System.Windows.Forms.DockStyle.Top;
    			this.btnZRIV.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
    			this.btnZRIV.Location = new System.Drawing.Point(0, 0);
    			this.btnZRIV.Name = "btnZRIV";
    			this.btnZRIV.Size = new System.Drawing.Size(344, 24);
    			this.btnZRIV.TabIndex = 13;
    			this.btnZRIV.Text = "button4";
    			this.btnZRIV.Click += new System.EventHandler(this.btnZRIV_Click);
    			// 
    			// panel2
    			// 
    			this.panel2.BackColor = System.Drawing.Color.Silver;
    			this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel2.Location = new System.Drawing.Point(232, 40);
    			this.panel2.Name = "panel2";
    			this.panel2.Size = new System.Drawing.Size(88, 64);
    			this.panel2.TabIndex = 9;
    			// 
    			// panel3
    			// 
    			this.panel3.BackColor = System.Drawing.Color.Silver;
    			this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel3.Location = new System.Drawing.Point(128, 40);
    			this.panel3.Name = "panel3";
    			this.panel3.Size = new System.Drawing.Size(88, 64);
    			this.panel3.TabIndex = 8;
    			// 
    			// panel7
    			// 
    			this.panel7.BackColor = System.Drawing.Color.Silver;
    			this.panel7.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    			this.panel7.Location = new System.Drawing.Point(24, 40);
    			this.panel7.Name = "panel7";
    			this.panel7.Size = new System.Drawing.Size(88, 64);
    			this.panel7.TabIndex = 7;
    			// 
    			// Form1
    			// 
    			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    			this.ClientSize = new System.Drawing.Size(344, 389);
    			this.Controls.Add(this.panContainer4);
    			this.Controls.Add(this.panContainer3);
    			this.Controls.Add(this.panContainer2);
    			this.Controls.Add(this.panContainer1);
    			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
    			this.Name = "Form1";
    			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    			this.Text = "Form1";
    			this.Resize += new System.EventHandler(this.Form1_Resize);
    			this.Load += new System.EventHandler(this.Form1_Load);
    			this.panContainer1.ResumeLayout(false);
    			this.panContainer2.ResumeLayout(false);
    			this.panContainer3.ResumeLayout(false);
    			this.panContainer4.ResumeLayout(false);
    			this.ResumeLayout(false);
    
    		}
    		#endregion
    
    		/// <summary>
    		/// Der Haupteinstiegspunkt für die Anwendung.
    		/// </summary>
    		[STAThread]
    		static void Main() 
    		{
    			Application.Run(new Form1());
    		}
    		public int Animation_Rate
    		{ 
    			get
    			{ 
    				return this.AnimationRate;
    			}
    			set
    			{
    				this.AnimationRate = value;
    			}
    		}
    		private void Form1_Resize(object sender, System.EventArgs e)
    		{
    			if(AnimationRate==1)
    				return;
    		}
    
    		private void Form1_Load(object sender, System.EventArgs e)
    		{
    			this.panContainer1.Height = this.Height-this.btnZRI.Height*4;
    			this.panContainer2.Height = y;
    			this.panContainer3.Height = y;
    			this.panContainer4.Height = y;
    		}
    
    		private void btnZRI_Click(object sender, System.EventArgs e)
    		{
    			if(this.panContainer1.Height==this.btnZRI.Height)//aufmachen
    			{
    				int x = this.Height - this.btnZRI.Height*4;
    				while(panContainer1.Height<=(x))
    				{
    					Application.DoEvents();
    					this.panContainer1.Height +=AnimationRate;
    					this.panContainer2.Height -=AnimationRate;
    					this.panContainer3.Height -=AnimationRate;
    					this.panContainer4.Height -=AnimationRate;
    				}
    				this.panContainer1.Height = x;
    				this.panContainer2.Height = y;
    				this.panContainer3.Height = y;
    				this.panContainer4.Height = y;
    			}
    		}
    
    		private void btnZRII_Click(object sender, System.EventArgs e)
    		{
    			if(this.panContainer2.Height==this.btnZRII.Height)//aufmachen
    			{
    				int x = this.Height - this.btnZRII.Height*4;
    
    				while(panContainer2.Height<=(x))
    				{
    					Application.DoEvents();
    					this.panContainer1.Height -=AnimationRate;
    					this.panContainer2.Height +=AnimationRate;
    					this.panContainer3.Height -=AnimationRate;
    					this.panContainer4.Height -=AnimationRate;
    				}
    				this.panContainer1.Height = y;
    				this.panContainer2.Height = x;
    				this.panContainer3.Height = y;
    				this.panContainer4.Height = y;
    			}
    		}
    
    		private void btnZRIII_Click(object sender, System.EventArgs e)
    		{
    			if(this.panContainer3.Height==this.btnZRIII.Height)//aufmachen
    			{
    				int x = this.Height - this.btnZRIII.Height*4;
    
    				while(panContainer3.Height<=(x))
    				{
    					Application.DoEvents();
    					this.panContainer1.Height -=AnimationRate;
    					this.panContainer2.Height -=AnimationRate;
    					this.panContainer3.Height +=AnimationRate;
    					this.panContainer4.Height -=AnimationRate;
    				}
    
    				this.panContainer1.Height = y;
    				this.panContainer2.Height = y;
    				this.panContainer3.Height = x;
    				this.panContainer4.Height = y;
    			}
    		}
    
    		private void btnZRIV_Click(object sender, System.EventArgs e)
    		{
    			if(this.panContainer4.Height==this.btnZRIV.Height)//aufmachen
    			{
    				int x = this.Height - this.btnZRIV.Height*4;
    
    				while(panContainer4.Height<=(x))
    				{
    					Application.DoEvents();
    					this.panContainer1.Height -=AnimationRate;
    					this.panContainer2.Height -=AnimationRate;
    					this.panContainer3.Height -=AnimationRate;
    					this.panContainer4.Height +=AnimationRate;
    				}
    				this.panContainer1.Height = y;
    				this.panContainer2.Height = y;
    				this.panContainer3.Height = y;
    				this.panContainer4.Height = x;
    			}
    		}
    
    	}
    }
    
    +++++++++++++++++++++++++++++++++++++++++
    


  • bitte beim nächsten mal code tags vewenden (denn dann mach ich es nicht für dich :p )



  • using System.Brain;
    


  • meinung schrieb:

    using System.Brain;
    

    Was meinst Du damit?
    Wie wende ich "System.Brain" an?



  • denke mal scharf nach 😉

    mal im ernst: minimier doch deinen code erstmal auf das nötigste, nimm alle panels und was da sonst noch rumfliegt raus und dann wirst du vielleicht schon den fehler selbst rausfinden.



  • Wird wohl an der Technik liegen wie Windows Fenster zeichnet 😉
    Du kannst (zumindest bei .net 2.0) Double-Buffering für das Fenster aktivieren und hoffen dass die Software ab WinXP eingesetzt wird - vorher kennt Windows kein DoubleBuffering.

    Wenn die Größe eines Panels geändert wird, zeichnet Windows erst den Hintergrund des Panels neu, dann das Panel selbst, dann den Hintergrund eines Buttons der da drauf-liegt und dann den Button an sich. Da das zeichnen allerdings nicht in 0 ms passiert und vor allem wenn das Panel animiert wird, kommt es dann zum Flackern.

    Die WinAPI-Leute fuckeln dann immer mit nem Backbuffer rum. Quasi eine Bitmap im Arbeitsspeicher in der vorher alles reingezeichnet wird und wenn das Zeichnen fertig ist, wird der gesamte Backbuffer gezeichnet. Dadurch wird quasi alles im Hintergrund gezeichnet und dann mit einem Schlag das Ergebnis angezeigt.
    Seit WinXP gibt es in der WinAPI ein Flag WS_EX_COMPOSITED, das DoubleBuffering für ein Fenster einschaltet. Das dürfte dem oben genannten im .net-Framework entsprechen.



  • meinung schrieb:

    denke mal scharf nach 😉

    Ich habe jetzt das

    while(panContainer2.Height<=(x))

    in

    while(panContainer2.Height==(x))

    geändert. Es flackert nicht mehr!

    Aber: Das "AnimationRate" greift jetzt auch nicht mehr.
    Und genau diesen Effekt brauche ich. ?



  • Servus,

    geeky schrieb:

    Du kannst (zumindest bei .net 2.0) Double-Buffering für das Fenster aktivieren und hoffen dass die Software ab WinXP eingesetzt wird - vorher kennt Windows kein DoubleBuffering.

    abgesehen davon das ich das noch nie genutzt habe aber stimmt das wirklich? Dann würde ja folgendene Möglichkeit keinen Sinn machen 😃

    this.SetStyle(ControlStyles.DoubleBuffer, true);
    

    Echt eine dumme Frage von mir: Wenns doch nicht funzt, wofür sollte ich dann SetStyle verwenden? *nixrallt*

    mfg
    Hellsgore

    EDIT: Oder habe ich dich falsch verstanden? Ach ich brauch einen Kaffee.



  • Hmm, probieren geht über studieren.
    Rein-theoretisch kann erst Windows XP DoubleBuffering.
    Zumindest steht da nen Windows XP davor:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/createwindowex.asp

    Mir scheint bisher das ganze Windows.Forms wieder nur ein WinAPI-Wrapper zu sein.
    Beispielsweise kennt die ListView in der WinXP-Version noch das Feature "Groups", in Win2k gibt es das noch nicht.
    Verwendet man nun die ListView des .net 2.0-Frameworks und benutzt da Groups, dann werden unter Win2k keine Groups angezeigt ;/
    Oder hab ich etwas falsch gemacht ?

    Und ich dachte bisher die Controls im .net-Framework wären unabhängig von den bestehenden Controls der jeweiligen Windows-Version implementiert worden.

    Andererseits steht hier:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolstylesclasstopic.asp
    nichts davon, dass das erst ab WinXP funktioniert.
    (Oh, da steht das mit Flicker-Reduzieren nochmal etwas anders!!)

    Naja, hier habe ich gerade keine Win2k-Maschine zwecks testen 😉


Anmelden zum Antworten