[Zedgraph] Grundgerüst für die Verwendung von Zedgraph

private void InitGraph()
{
    GraphPane myPane = zedGraph.GraphPane;
    zedGraph.IsShowPointValues = true;

    myPane.CurveList.Clear();
    myPane.GraphObjList.Clear();

    myPane.Legend.IsVisible = true;

    myPane.XAxis.Title.Text = "x";
    myPane.XAxis.MinorGrid.IsVisible = false;
    myPane.XAxis.MajorGrid.IsVisible = false;
    myPane.XAxis.Scale.MajorStep = 1.0;

    myPane.YAxis.Title.Text = "y'";
    myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
    myPane.YAxis.MajorGrid.IsVisible = true;
    myPane.YAxis.MinorGrid.IsVisible = false;
    myPane.YAxis.MajorTic.IsOpposite = false;
    myPane.YAxis.MinorTic.IsOpposite = false;
    myPane.YAxis.Scale.Align = AlignP.Inside;
    myPane.YAxis.Scale.Min = 0.0;
    myPane.YAxis.Scale.MajorStep = 10.0;

    myPane.Title.Text = "x/y'";

    myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);
    myPane.Fill = new Fill(Color.White, Color.AliceBlue, 45.0f);

    zedGraph.AxisChange();
}

private void ClearGraph()
{
    zedGraph.GraphPane.CurveList.Clear();
    zedGraph.AxisChange();
    zedGraph.Refresh();
}

private void FillGraph()
{
    this.ClearGraph();

    GraphPane myPane = zedGraph.GraphPane;

    ...
    
    zedGraph.AxisChange();
    zedGraph.Refresh();
}

[C#] Bild mittels HttpWebRequest und HttpWebResponse herunterladen

using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;

private long DownloadImage(string url)
{
    HttpWebRequest request = null;
    HttpWebResponse response = null;
    long contentlength = 0;
    
    try
    {
        request = (HttpWebRequest)WebRequest.Create(url);
        response = (HttpWebResponse)request.GetResponse();

        if ((response.StatusCode == HttpStatusCode.OK ||
             response.StatusCode == HttpStatusCode.Moved ||
             response.StatusCode == HttpStatusCode.Redirect) &&
             response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
        {
            Bitmap b = new Bitmap(response.GetResponseStream());

            // do something here
            ...

            b.Dispose();
            b = null;
        }
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }
    finally
    {
        if (response != null)
        {
            contentlength = response.ContentLength;
            response.Close();
            response = null;
        }

        if (request != null)
        {
            request = null;
        }
    }
    
    // returns bytes read
    return contentlength;
}

[Zedgraph] Achsentitel per Event anpassen

public void InitGraph()
{
        zedGraph.GraphPane.XAxis.ScaleTitleEvent += new Axis.ScaleTitleEventHandler(XAxis_ScaleTitleEvent);
}

private string XAxis_ScaleTitleEvent(Axis axis)
{
        // immer Datum zw. x-Min und x-Max anzeigen
        double d = (axis.Scale.Min + axis.Scale.Max) / 2.0;
        return DateTime.FromOADate(d).ToString("dd.MM.yyyy");
}

[C#] Farbmodelle umwandeln (HSV, RGB)

using System;
using System.Drawing;

/// <summary>
/// freeware helper class for converting color schemes
/// (W) 2011 by admin of codezentrale.6x.to
/// </summary>
public static class ColorConvert
{
    public struct HSV
    {
        /// <summary>
        /// Hue, Farbton [0.0° .. 360.0°]
        /// </summary>
        public double hue;
        /// <summary>
        /// Saturation, Sättigung [0.0 .. 1.0]
        /// </summary>
        public double saturation;
        /// <summary>
        /// Value, Helligkeit [0.0 .. 1.0]
        /// </summary>
        public double value;

        public HSV(double h, double s, double v)
        {
            hue = h;
            saturation = s;
            value = v;
        }
    }
    public struct RGB
    {
        /// <summary>
        /// red, Rot [0 .. 255]
        /// </summary>
        public int red;
        /// <summary>
        /// green, Grün [0 .. 255]
        /// </summary>
        public int green;
        /// <summary>
        /// blue, Blau [0 .. 255]
        /// </summary>
        public int blue;

        public RGB(int r, int g, int b)
        {
            red = r;
            green = g;
            blue = b;
        }
    }
    /// <summary>
    /// converts Color to HSV
    /// </summary>
    /// <param name="c">Color</param>
    /// <returns>HSV struct</returns>
    public static HSV ColorToHSV(Color c)
    {
        int max = Math.Max(c.R, Math.Max(c.G, c.B));
        int min = Math.Min(c.R, Math.Min(c.G, c.B));

        double h = c.GetHue();
        double s = (max == 0) ? 0.0 : 1.0 - (1.0 * (double)min / (double)max);
        double v = (double)max / 255.0;

        return new HSV(h, s, v);
    }
    /// <summary>
    /// converts HSV to Color
    /// </summary>
    /// <param name="hsv">HSV struct to convert</param>
    /// <returns>Color</returns>
    public static Color HSVToColor(HSV hsv)
    {
        Color c = Color.Black;

        int hi = (int)(Math.Floor(hsv.hue / 60.0)) % 6;
        double f = hsv.hue / 60.0 - Math.Floor(hsv.hue / 60.0);

        hsv.value = hsv.value * 255.0;

        int v = (int)hsv.value;
        int p = (int)(hsv.value * (1.0 - hsv.saturation));
        int q = (int)(hsv.value * (1.0 - f * hsv.saturation));
        int t = (int)(hsv.value * (1.0 - (1.0 - f) * hsv.saturation));

        switch (hi)
        {
            case 0: c = Color.FromArgb(255, v, t, p); break;
            case 1: c = Color.FromArgb(255, q, v, p); break;
            case 2: c = Color.FromArgb(255, p, v, t); break;
            case 3: c = Color.FromArgb(255, p, q, v); break;
            case 4: c = Color.FromArgb(255, t, p, v); break;
            default: c = Color.FromArgb(255, v, p, q); break;
        }

        return c;
    }
    /// <summary>
    /// converts Color to RGB
    /// </summary>
    /// <param name="c">Color</param>
    /// <returns>RGB struct</returns>
    public static RGB ColorToRGB(Color c)
    {
        return new RGB(c.R, c.G, c.B);
    }
    /// <summary>
    /// converts RGB to Color
    /// </summary>
    /// <param name="rgb">RGB struct</param>
    /// <returns>Color</returns>
    public static Color RGBToColor(RGB rgb)
    {
        return Color.FromArgb(rgb.red, rgb.green, rgb.blue);
    }
}

Vergleich zweier Bitmaps

/// <summary>
/// Funktion zum schnellen Vergleich zweier Bitmaps per unsafe-Code
/// im Projekt muss "Erstellen->unsicheren Code zulassen" angewählt sein
/// </summary>
/// <param name="b1"->1. Bitmap</param>
/// <param name="b2"->2. Bitmap</param>
/// <returns>true, wenn gleich, sonst false</returns>
private bool BitmapsAreEqual(Bitmap b1, Bitmap b2)
{
    bool bRetVal = true;

    if ((b1 != null) && (b2 != null))
    {
        BitmapData bmd1 = b1.LockBits(new Rectangle(0, 0, b1.Width, b1.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
        BitmapData bmd2 = b2.LockBits(new Rectangle(0, 0, b2.Width, b2.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

        int cnt_px = b1.Width * b2.Height;

        unsafe
        {
            byte* p1 = (byte*)bmd1.Scan0;
            byte* p2 = (byte*)bmd2.Scan0;

            for (int i = 0; i < cnt_px; i++)
            {
                if (p1[i] != p2[i])
                {
                    bRetVal = false;
                    break;
                }
            }
        }

        b1.UnlockBits(bmd1);
        b2.UnlockBits(bmd2);
    }
    else
    {
        bRetVal = false;
    }

    return bRetVal;
}

Mit TextRenderer die Breite eines stringbasierten Textes messen

using System.Windows.Forms;

/// <summary>
/// prüft, ob übergebener Text eine best. Länge in Pixeln nicht Überschreitet
/// </summary>
/// <param name="sText">der zur prüfende Text</param>
/// <param name="iLength">max. Textlänge in Pixeln</param>
/// <param name="ftTextFont">angewendete Schriftart</param>
/// <returns>true, else false</returns>
public bool FitsLength(string sText, int iLength, Font ftTextFont)
{
    return (TextRenderer.MeasureText(sText, ftTextFont).Width <= iLength);
}

Weiterführende Informationen zur Klasse TextRenderer: MSDN

Bild (IHTMLImgElement) mittels WebClient herunterladen

// für "mshtml.IHTMLImgElement" unter Projekt->Verweise->Verweis hinzufügen->COM->Microsoft HTML Object Library hinzufügen
// benötigt wird außerdem ein WebBrowser-Steuerelement
//
// Aufruf:
// HtmlElement el = webBrowser.Document.All[0];
// mshtml.IHTMLImgElement htmImg = el.DomElement as mshtml.IHTMLImgElement;
// if (htmImg != null)
// {
//     if (DownloadImage(htmImg, @"c:\Bilder\12345.png", ImageFormat.Png)
//     {
//         // irgendwas machen
//     }
// }

private bool DownloadImage(mshtml.IHTMLImgElement el, string sFileName, ImageFormat format)
{
    bool bRetVal = false;

    try
    {
        // WebClient für Download erzeugen
        WebClient client = new WebClient();
        // Stream an der Adresse "el.href" herunterladen
        Stream stream = client.OpenRead(el.href);

        // Stream an Bitmap übergeben und im übergebenen Format speichern
        Bitmap bitmap = new Bitmap(stream);
        bitmap.Save(sFileName, format);
        bitmap.Dispose();

        // aufräumen
        stream.Flush();
        stream.Close();
        stream.Dispose();

        client.Dispose();

        bRetVal = true;
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }

    return bRetVal;
}