Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.list = new List<Point>(); //Liste für Koordinaten instanziieren
this.bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.Image = bmp;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
mouseDown = true;
list.Add(new Point(e.X, e.Y));
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (mouseDown)
{
mouseDown = false;
using (Graphics g = Graphics.FromImage(bmp))
{
Draw(g);
g.Flush();
}
list.Clear();
pictureBox1.Invalidate();
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (mouseDown)
{
list.Add(new Point(e.X, e.Y));
pictureBox1.Invalidate();
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (mouseDown)
Draw(e.Graphics);
}
/// <summary>
/// zeichnen
/// </summary>
private void Draw(Graphics g)
{
using (SolidBrush sb = new SolidBrush(Color.Black))
{
foreach (Point pt in list)
{
if (g.VisibleClipBounds.Contains(pt))
g.FillRectangle(sb, new Rectangle(pt.X, pt.Y, 2, 2));
}
}
}
private bool mouseDown; //ob Maustaste gedrückt wird (zur Speicherung der Maus koordinaten)
private readonly List<Point> list; //Mauskoordinaten
private readonly Bitmap bmp; //Bitmap zum speichern des gezeichneten
}
/// <summary>
/// zeichnen
/// </summary>
private void Draw(Graphics g)
{
if (list.Count > 0)
{
byte[] bs = new byte[list.Count];
bs[0] = (byte)PathPointType.Start;
for (int i = 1; i < list.Count; i++)
bs[i] = (byte)PathPointType.Line;
using (Pen p = new Pen(Color.Black, 2))
g.DrawPath(p, new System.Drawing.Drawing2D.GraphicsPath(list.ToArray(), bs));
}
}
using (Graphics g = Graphics.FromImage(bmp))
{
Draw(g);
g.Flush();
}
using (Graphics g = Graphics.FromImage(bmp))
{
Draw(g);
g.Flush();
}
pictureBox1.Image = bmp;
try
{
pictureBox1.Load("c:/Dokumente und Einstellungen/All Users/Anwendungsdaten/tmp.bmp");
}
catch (Exception x)
{
MessageBox.Show("Exception " +x.Message);
}
this.bmp = new Bitmap("c:/Dokumente und Einstellungen/All Users/Anwendungsdaten/tmp.bmp");
pictureBox1.Image = bmp;