namespace System.Windows.Forms { public class ButtonBase : Control { protected new System.Windows.Controls.Primitives.ButtonBase control { get; private set; } public FlatButtonAppearance FlatAppearance { get; } private FlatStyle flatStyle; public FlatStyle FlatStyle { get => flatStyle; set { flatStyle = value; if (value != FlatStyle.Standard) { Padding = Padding.Empty; BackColor = Drawing.Color.Transparent; if (control is CustomControls.ButtonBase btn) btn.IsFlat = true; } } } private System.Drawing.Image image; public System.Drawing.Image Image { get => image; set { if (image != value) { image = value; UpdateControlImage(Helper.GetImage(Image)); } } } private System.Drawing.ContentAlignment imageAlign; public System.Drawing.ContentAlignment ImageAlign { get => imageAlign; set { imageAlign = value; UpdateContentAlignment(); } } private System.Drawing.ContentAlignment textAlign; public System.Drawing.ContentAlignment TextAlign { get => textAlign; set { textAlign = value; UpdateContentAlignment(); } } public TextImageRelation TextImageRelation { get; set; } // TODO? public override string Text { get { if (control.Content is System.Windows.Controls.TextBlock tb) return tb.Text; return control.Content?.ToString(); } set { value = value?.Replace("\t", ""); if (control.Content is System.Windows.Controls.TextBlock tb) tb.Text = value; else control.Content = value; base.Text = value; } } public bool UseVisualStyleBackColor { get; set; } public bool UseCompatibleTextRendering { get; set; } protected virtual void UpdateContentAlignment() { if (control == null) return; // we use TextAlign only in FR Helper.GetContentAlignment(TextAlign, out Windows.HorizontalAlignment h, out Windows.VerticalAlignment v); control.HorizontalContentAlignment = h; control.VerticalContentAlignment = v; } protected virtual void UpdateControlImage(System.Windows.Media.ImageSource image) { } protected void SetControl(System.Windows.Controls.Primitives.ButtonBase control) { base.SetControl(control); this.control = control; control.Click += (sender, e) => OnClick(e); UpdateContentAlignment(); } public ButtonBase() { FlatAppearance = new FlatButtonAppearance(this); FlatStyle = FlatStyle.Standard; ImageAlign = System.Drawing.ContentAlignment.MiddleCenter; TextAlign = System.Drawing.ContentAlignment.MiddleCenter; } } }