Frage zum DoubleBuffering



  • hallo Leuts,
    vor kurzem habe ich mit C# angefangen und soweit gehts auch gut voran, da ich das
    "flackern" verhindern wollte habe ich für jedes meiner Fenster (ist ein MDI projekt)
    folgendes getan:

    this.DoubleBuffered = true;
                this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
    

    hat soweit einiges gebracht nur bleibt das Problem "flackern" an einigen Punkten
    übrig... z.b. habe ich einen TreeView der anfängt zu flackern sobald der Nutzer
    Elemente hinzufügt.

    hätte jemand eine Idee was ich da noch machen müsste damit dies unterbunden wird??



  • cppHoesel schrieb:

    hätte jemand eine Idee was ich da noch machen müsste damit dies unterbunden wird??

    Probier´ mal BeginUpdate/EndUpdate. Bei einigen Controls hilft auch SuspendLayout/ResumeLayout gegen das Flackern.



  • danke für die schnelle Antwort , jedoch ist jetzt nach den ganzen Änderungen das
    Problem schlimmer geworden. Hier einmal die stellen im Code die ich verändert habe:

    FensterKlasse

    public Fenster(string WindowText, string NewName, int width, int height, bool resizeable, bool useopengl, Fenster ParentWnd, WindowInitFunc InitFunc)
       {
                this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                this.ClientSize = new System.Drawing.Size(width, height);
                this.Name = NewName;
                this.Text = WindowText;
    
                if (useopengl)
                {
                    this.view = new OglView();
                    this.view.Parent = this;
                    this.view.Dock = DockStyle.Fill; // Will fill whole form
                    this.hasogl = true;
                }
    
                if (resizeable)
                {
                    this.FormBorderStyle = FormBorderStyle.Sizable;
                }
                else
                {
                    this.ControlBox = false;
                    this.FormBorderStyle = FormBorderStyle.Fixed3D;
                }
                this.DoubleBuffered = true;
                this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
                if (ParentWnd != null)
                {
                    this.MdiParent = ParentWnd;
                }
                this.SuspendLayout();
                if (!InitFunc(this))
                {
                    FensterManager.PushError("Error", "CreateWindow(\"" + this.Name + "\") failed");
    
                }
                this.ResumeLayout();
                this.Show();
       }
            public override void Refresh()
            {
                if (Gamecode != null)
                {
    
                    this.Gamecode(this);
                    if (hasogl)
                    {
                       if (this.view.finished)
                       {
                           this.Close();
                       }
                    }                
                }
    
                base.Refresh();
            }
    

    spezifischer Fenstercode

    static private void ExplorerRefresh(Fenster Wnd)
            {
                if ((Wnd.MdiParent.Width - Wnd.Width - 14) == Wnd.Location.X) return;
                Wnd.MdiParent.SuspendLayout();
                Wnd.SuspendLayout();
                Wnd.Location = new Point(Wnd.MdiParent.Width - Wnd.Width - 14, 0);
                EditorItems.BeginUpdate();
                EditorItems.Width = Wnd.Width;
                EditorItems.Height = Wnd.Height;
                EditorItems.EndUpdate();
                Wnd.ResumeLayout();
                Wnd.MdiParent.ResumeLayout();
            }
    
            static private bool ExplorerInit(Fenster Wnd)
            {
    
                ProjectExplorer = Wnd;
    
                if (ProjectExplorer == null) return false;
                ProjectExplorer.FormBorderStyle = FormBorderStyle.None;
    
                ExplorerContextMenus = new List<ContextMenu>();
                ExplorerContextMenus.Clear();
    
                ExplorerBaseMenu = new ContextMenu();
                ExplorerBaseMenu.MenuItems.Add("Create", new EventHandler(ExplorerCreateNode_Clicked));
    
                EditorItems = new TreeView();
                EditorItems.Anchor = (((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right);
                EditorItems.ImageIndex = -1;
                EditorItems.Location = new Point(0, 0);
                EditorItems.Name = "EditorTree";
                EditorItems.SelectedImageIndex = -1;
                EditorItems.ShowNodeToolTips = true;
                EditorItems.TabIndex = 1;
                EditorItems.MouseDown += new MouseEventHandler(ExplorerTree_MouseDown);
                ProjectExplorer.Controls.AddRange(new Control[] { EditorItems });
    
                ExplorerCreateMenu("M_Doc",true);
                AddEditorItem("Documents", "Edit,Create,Delete Rooms for the Project", ExplorerGetMenu("M_Doc"));
    
                return true;
            }
            static private void ExplorerCreateNode_Clicked(object sender, EventArgs e)
            {
                TreeNode node = EditorItems.SelectedNode;
    
                CurrentDoc = Editor.Docs[Editor.CreateDoc()-1];
    
                EditorItems.BeginUpdate();
                AddEditorItem(node.Name + "/" + CurrentDoc.Name, "test", null);
                EditorItems.EndUpdate();
    
            }
    


  • so sorry für DoppelPost ... wollte nur bescheid geben das ichs behoben hab 🙂


Anmelden zum Antworten