2016-11-15 4 views
0

Ich habe eine Klasse CircularButton, die von Knopf und Knopf erstreckt, die den Text nicht angezeigt wird, mit oder ohne Backcolor. Kann nicht herausfinden, was passiert:Warum zeigt meine Schaltfläche den Text nicht an?

public class CircularButton : Button { 


    public CircularButton(Color c, String text){ 
     Font = new Font("Arial", 20f, FontStyle.Bold); 
     BackColor = c; 
     Text = text; 
    } 
    public Action<PaintEventArgs> DoPaint { get; set; } 
    protected override void OnPaint(PaintEventArgs e) { 
     if (DoPaint != null) { DoPaint(e); } 
    } 
} 

//make a new circular button, the text is just a letter. 
CircularButton btn = new CircularButton(Color.Red,"A"); 
    btn.Bounds = new Rectangle(0, 0, 50, 50); 
    btn.Enabled = false;       
    btn.DoPaint = delegate(PaintEventArgs p){ 
     Graphics graphics = p.Graphics; 
     SolidBrush brush1 = new SolidBrush(SystemColors.ButtonFace); 
     graphics.FillRectangle(brush1, 0, 0, btn.Width, btn.Height); 
     SolidBrush brush2 = new SolidBrush(btn.BackColor); 
     graphics.FillEllipse(brush2, 0, 0, btn.Width, btn.Height); 
};    
+2

Ihre Farbe jeden Text tut schreiben .. – BugFinder

+0

Ich vermute, dies WinForms ist, warum nicht nur die Region Eigenschaft einer Standard-Taste, um es zu einem Kreis Clip verwenden? –

+0

@ZoharPeled Da ich aus Java komme, benutze ich die .net-Bibliotheken, kenne die meisten noch immer nicht. – tomyforever

Antwort

0

Sie OnPaint überschreiben, die den Text in der Basis-Taste ziehen würde. So müssen Sie den Text selbst schreiben:

graphics.DrawString(btn.Text, btn.Font, new SolidBrush(btn.ForeColor), x, y); 
+0

Danke, es funktioniert. – tomyforever

Verwandte Themen