public static Label CreateLabelHeader(Expander expander, string text, Color backColor, Image collapsedImage = null, Image expandedImage = null, int height = 25, Font font = null) { Label headerLabel = new Label(); headerLabel.Text = text; headerLabel.AutoSize = false; headerLabel.Height = height; if (font != null) { headerLabel.Font = font; } headerLabel.TextAlign = ContentAlignment.MiddleLeft; if (collapsedImage != null && expandedImage != null) { headerLabel.Image = collapsedImage; headerLabel.ImageAlign = ContentAlignment.MiddleRight; } headerLabel.BackColor = backColor; if (collapsedImage != null && expandedImage != null) { expander.StateChanged += delegate { headerLabel.Image = expander.Expanded ? collapsedImage : expandedImage; }; } headerLabel.Click += delegate { expander.Toggle(); }; expander.Header = headerLabel; return(headerLabel); }
private void CreateFloatingExpander3() { Expander expander = new Expander(); expander.Size = new Size(250, 120); expander.Left = 350; expander.Top = 230; expander.BorderStyle = BorderStyle.FixedSingle; Label headerLabel = new Label(); headerLabel.Text = "Click me"; headerLabel.AutoSize = false; headerLabel.Font = new Font(headerLabel.Font, FontStyle.Bold); headerLabel.TextAlign = ContentAlignment.MiddleLeft; headerLabel.BackColor = SystemColors.ActiveBorder; headerLabel.Click += delegate { expander.Toggle(); if (expander.Expanded) { headerLabel.BackColor = SystemColors.ActiveBorder; } else { headerLabel.BackColor = SystemColors.ActiveCaption; } }; expander.Header = headerLabel; Label labelContent = new Label(); labelContent.Text = "You are not limited to use the ExpanderHelper to create your header. Here is a example with a custom code and custom click event handler that change the header backcolor when the expander state change."; labelContent.Size = new System.Drawing.Size(expander.Width, 75); expander.Content = labelContent; this.Controls.Add(expander); }
public static Label CreateLabelHeader(Expander expander, string text, Color backColor, Image collapsedImage = null, Image expandedImage = null, int height = 25, Font font = null) { Label headerLabel = new Label(); headerLabel.Text = text; headerLabel.AutoSize = false; headerLabel.Height = height; if (font != null) headerLabel.Font = font; headerLabel.TextAlign = ContentAlignment.MiddleLeft; if (collapsedImage != null && expandedImage != null) { headerLabel.Image = collapsedImage; headerLabel.ImageAlign = ContentAlignment.MiddleRight; } headerLabel.BackColor = backColor; if (collapsedImage != null && expandedImage != null) { expander.StateChanged += delegate { headerLabel.Image = expander.Expanded ? collapsedImage : expandedImage; }; } headerLabel.Click += delegate { expander.Toggle(); }; expander.Header = headerLabel; return headerLabel; }