private void OnPanelsClearing() { // Do nothing until we are created if (IsHandleCreated && !IsDisposed) { int count = _panels.Count; // Unhook from all items for (int i = 0; i < count; i++) { _panels[i].RequestedWidthChanged -= new EventHandler(OnRepositionPanels); _panels[i].PanelBorderChanged -= new EventHandler(OnRepositionPanels); _panels[i].AlignmentChanged -= new EventHandler(OnRepositionPanels); _panels[i].TextChanged -= new EventHandler(OnRepositionPanels); _panels[i].ImageChanged -= new EventHandler(OnRepositionPanels); _panels[i].VisibleChanged -= new EventHandler(OnRepositionPanels); _panels[i].AutoSizingChanged -= new EventHandler(OnRepositionPanels); _panels[i].PaintBackground -= new PaintEventHandler(OnPanelPaintBackground); // Get hosting control from indexed position StatusPanelBorder host = Controls[i] as StatusPanelBorder; host.PaintBackground += new PaintEventHandler(OnPanelPaintBackground); } } }
private void InitializePanel(int index, StatusPanel panel) { // Create a hosting panel for the new panel StatusPanelBorder host = new StatusPanelBorder(this); host.PaintBackground += new PaintEventHandler(OnPanelPaintBackground); // Assign across the panel host.StatusPanel = panel; // Set correct default border panel (for those defauled) if (host.StatusPanel.DefaultPanelBorder) { host.StatusPanel.PanelBorder = (_style != VisualStyle.Plain) ? PanelBorder.Solid : PanelBorder.Sunken; } // Add host to the collection of control Controls.Add(host); // Move to correct index Controls.SetChildIndex(host, index); // Hook into panel events panel.RequestedWidthChanged += new EventHandler(OnRepositionPanels); panel.PanelBorderChanged += new EventHandler(OnRepositionPanels); panel.AlignmentChanged += new EventHandler(OnRepositionPanels); panel.TextChanged += new EventHandler(OnRepositionPanels); panel.ImageChanged += new EventHandler(OnRepositionPanels); panel.VisibleChanged += new EventHandler(OnRepositionPanels); panel.AutoSizingChanged += new EventHandler(OnRepositionPanels); panel.PaintBackground += new PaintEventHandler(OnPanelPaintBackground); }
private void OnPanelRemoved(int index, object value) { // Do nothing until we are created if (IsHandleCreated && !IsDisposed) { // Cast to correct type StatusPanel panel = value as StatusPanel; // Unhook from panel events panel.RequestedWidthChanged -= new EventHandler(OnRepositionPanels); panel.PanelBorderChanged -= new EventHandler(OnRepositionPanels); panel.AlignmentChanged -= new EventHandler(OnRepositionPanels); panel.TextChanged -= new EventHandler(OnRepositionPanels); panel.ImageChanged -= new EventHandler(OnRepositionPanels); panel.VisibleChanged -= new EventHandler(OnRepositionPanels); panel.AutoSizingChanged -= new EventHandler(OnRepositionPanels); panel.PaintBackground -= new PaintEventHandler(OnPanelPaintBackground); // Get hosting control from indexed position StatusPanelBorder host = Controls[index] as StatusPanelBorder; host.PaintBackground -= new PaintEventHandler(OnPanelPaintBackground); // Remove it from the collection of children Controls.Remove(host); // Ask for all panels to be repositioned OnRepositionPanels(this, EventArgs.Empty); } }