PictureBox mit Benutzerinformationen neu streichenC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 PictureBox mit Benutzerinformationen neu streichen

Post by Anonymous »

Wenn ich meine Bildboxen (von listUC) auf einem Panel neu male, möchte ich auf jeder Bildbox eine Ellipse und eine Zeichenfolge zeichnen. Auf der pictureBox wurde jedoch nichts gezeichnet.
Ich möchte die Zeichenfolge zeichnen, die im uc.Name;
gespeichert ist

Code: Select all

foreach (UseCase uc in listUC)
{
ucNamePaint = uc.Name;
//Create UseCaseBox
PictureBox useCaseBox = new PictureBox();
useCaseBox.Name = uc.Index.ToString();
Graphics g = useCaseBox.CreateGraphics();
useCaseBox.Paint += new PaintEventHandler(OnPaint_picturebox);
}
Onpaint-Methode:

Code: Select all

private void OnPaint_picturebox(object sender, EventArgs e)
{
var pb = sender as PictureBox;
if (null != pb)
{
pb.BackColor = Color.Yellow;
Graphics g = pb.CreateGraphics();
Font drawFont = new Font("Arial", 10);
int stringWidth = (int)g.MeasureString(ucNamePaint, drawFont).Width;
int stringHeight = (int)g.MeasureString(ucNamePaint, drawFont).Height;

if (selectedUC.Count() != 0)
{
Rectangle ee = new Rectangle(0, 0, stringWidth + 10, stringHeight + 10);
using (Pen pen = new Pen(Color.Black, 2))
{
g.DrawEllipse(pen, ee);
}
}
else
{
Rectangle ee = new Rectangle(0, 0, stringWidth + 10, stringHeight + 10);
using (Pen pen = new Pen(Color.Gray, 2))
{
g.DrawEllipse(pen, ee);
}
}

StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;

float emSize = pb.Height;
g.DrawString(ucNamePaint, new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular),
new SolidBrush(Color.Black), 7, 5);
}
}
Dieser Code färbt die Bildbox gelb, aber sonst wird nichts gefärbt.
Bitte erklären Sie mir, wie ich das beheben kann!

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post