我正在使用WFA和C#,我试图在包含图像的图片框上绘制一个椭圆。这是我的代码,但目前它的背后是PB。
private void Form1_Paint(object sender, PaintEventArgs e)
{
PictureBox pb=new PictureBox();
pb.Location=new Point(10,25);
pb.BackgroundImage = Image.FromFile("fire2_clipped_rev_1.png");
pb.Size = Image.FromFile("fire2_clipped_rev_1.png").Size;
Truck.TruckF(pb.Location, pb.CreateGraphics());
pb.Invalidate();
Controls.Add(pb);
}
static Image truckf = Image.FromFile("fire2_clipped_rev_1.png");
public static void TruckF(Point location, Graphics e)
{
Wheels(truckf.Size,location,e);
}
private static void Wheels(Size simage,Point location,Graphics e)
{
e.FillEllipse(Brushes.Black, location.X / 6F, location.Y / 1.43F, 20, 20);
}
答案 0 :(得分:0)
您需要更改以处理表单上的Load事件。此外,PictureBox
是一个控件,你需要绘制一个图像并将其交给PictureBox以使其工作。试试这个:
private PictureBox pb;
private void Truck_Load(object sender, EventArgs e)
{
pb = new PictureBox();
pb.Location = new Point(10, 25);
Image bg = Image.FromFile("fire2_clipped_rev_1.png");
pb.BackgroundImage = bg;
pb.Size = bg.Size;
Bitmap img = new Bitmap(pb.Size.Width, pb.Size.Height);
pb.Image = img;
using (var g = Graphics.FromImage(img))
{
Truck.TruckF(pb.Location, g);
}
Controls.Add(pb);
}