using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
using ChemAxon.NET.Base.Chemistry.Data;
using ChemAxon.NET.Base.Chemistry.Formats;
using ChemAxon.NET.API;

namespace _2013_Developer_training {

    public class MoleculeImage {
        public static void RenderImage() {
            var benzeneData = new MoleculeData("C1=CC=CC=C1", MoleculeFormat.Unknown);            
            var benzeneMolecule = MainFactory.Chemistry.CreateMolecule(benzeneData);

            /////////////////////////////////////////////////////////////////////////////////////////
            // simple benzene rendering with default rendering settings
            var image = benzeneMolecule.Renderer.RenderToImage(ImageFormat.Emf);
            ShowImage(image, "Render a simple EMF image!");
        }

        public static void ChangeImageDrawingSettings() {
            var benzeneData = new MoleculeData("C1=CC=CC=C1", MoleculeFormat.Unknown);
            var benzeneMolecule = MainFactory.Chemistry.CreateMolecule(benzeneData);

            /////////////////////////////////////////////////////////////////////////////////////////
            // changing the settings and reredering of the same molecule
            benzeneMolecule.Renderer.Settings.DrawingInfo.Size = new Size(120, 120);
            benzeneMolecule.Renderer.Settings.DrawingInfo.StructureDrawingSettings.WireThickness = 0.23;
            var image = benzeneMolecule.Renderer.RenderToImage(ImageFormat.Emf);
            ShowImage(image, "Changing image and rendering settings");
        }

        public static void DrawImageInWebApplications() {
            var benzeneData = new MoleculeData("C1=CC=CC=C1", MoleculeFormat.Unknown);
            var benzeneMolecule = MainFactory.Chemistry.CreateMolecule(benzeneData);

            /////////////////////////////////////////////////////////////////////////////////////////
            // changing the background color and rendering the molecule as bitmap
            benzeneMolecule.Renderer.Settings.DrawingInfo.Transparent = false;
            benzeneMolecule.Renderer.Settings.DrawingInfo.BackgroundColor = Color.LightGreen;
            var image = benzeneMolecule.Renderer.RenderToImage(ImageFormat.Bmp);
            ShowImage(image, "Non-transparent iamge for web/browser based applications");
        }

        private static void ShowImage(Image image, string title) {
            var pb = new PictureBox();
            var frm = new Form();
            frm.Text = title;
            frm.Controls.Add(pb);
            pb.Dock = DockStyle.Fill;
            pb.Image = image;
            frm.ShowDialog();
        }
    }

}