Hallo! Ist wahrscheinlich eine Anfängerfrage, aber: Warum zeichnet er mir das nicht? Lt. OpenBook sollte das so funktionieren, oder? Jedoch sehe ich nichts auf meiner Oberfläche, das Paint-Ereginis wird doch eigentlich auch schon beim Fensterzeichnen ausgelöst, aber im Debugger geht er mir in die Methode nicht rein.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Text;
using System.Windows.Forms;
namespace painter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(new Pen(Color.Blue), 30, 10, 120, 70);
e.Graphics.FillRectangle(new SolidBrush(Color.Red), 20, 110, 35, 69);
}
}
}
Hallo,
Deine Form hat bereits eine virtuelle Funktion namens OnPaint, die kannst du überschreiben:
protected override void OnPaint(PaintEventArgs e){
e.Graphics.DrawEllipse(new Pen(Color.Blue), 30, 10, 120, 70);
e.Graphics.FillRectangle(new SolidBrush(Color.Red), 20, 110, 35, 69);
base.OnPaint(e); // <-- bitte nicht vergessen!
}
oder Du musst deinen Handler für das Paint-Event registrieren
public Form1()
{
InitializeComponent();
this.Paint += new PaintEventHandler(Form1_Paint);
}
Non quia difficilia sunt, non audemus, sed quia non audemus, difficilia sunt! - Seneca
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Text;
using System.Windows.Forms;
namespace painter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawEllipse(new Pen(Color.Blue), 30, 10, 120, 70);
e.Graphics.FillRectangle(new SolidBrush(Color.Red), 20, 110, 35, 69);
}
}
}
Hallo haseluenne,
siehe [Tutorial] Zeichnen in Windows-Programmen (Paint/OnPaint, PictureBox) . Ich schweige in dem Tutorial darüber nicht. 🙂
herbivore