private void GenerateImage()
        {
            if (_backgroundColorTSB.SelectedItem != null && _textRenderingHintTSCB.SelectedItem != null)
            {
                var backgroundColor = Color.FromName(_backgroundColorTSB.SelectedItem.ToString());
                TextRenderingHint textRenderingHint = (TextRenderingHint)Enum.Parse(typeof(TextRenderingHint), _textRenderingHintTSCB.SelectedItem.ToString());

                Image img;
                if (_useGdiPlusTSB.Checked || HtmlRenderingHelper.IsRunningOnMono())
                {
                    img = HtmlRender.RenderToImageGdiPlus(_html, _pictureBox.ClientSize, textRenderingHint, null, DemoUtils.OnStylesheetLoad, HtmlRenderingHelper.OnImageLoad);
                }
                else
                {
                    EventHandler <HtmlStylesheetLoadEventArgs> stylesheetLoad = DemoUtils.OnStylesheetLoad;
                    EventHandler <HtmlImageLoadEventArgs>      imageLoad      = HtmlRenderingHelper.OnImageLoad;
                    var objects = new object[] { _html, _pictureBox.ClientSize, backgroundColor, null, stylesheetLoad, imageLoad };

                    var types = new[] { typeof(String), typeof(Size), typeof(Color), typeof(CssData), typeof(EventHandler <HtmlStylesheetLoadEventArgs>), typeof(EventHandler <HtmlImageLoadEventArgs>) };
                    var m     = typeof(HtmlRender).GetMethod("RenderToImage", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, types, null);
                    img = (Image)m.Invoke(null, objects);
                }
                _pictureBox.Image = img;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Init.
        /// </summary>
        public DemoForm()
        {
            SamplesLoader.Init(HtmlRenderingHelper.IsRunningOnMono() ? "Mono" : "WinForms", typeof(HtmlRender).Assembly.GetName().Version.ToString());

            InitializeComponent();

            Icon = GetIcon();
            _openSampleFormTSB.Image     = Common.Properties.Resources.form;
            _showIEViewTSSB.Image        = Common.Properties.Resources.browser;
            _openInExternalViewTSB.Image = Common.Properties.Resources.chrome;
            _useGeneratedHtmlTSB.Image   = Common.Properties.Resources.code;
            _generateImageSTB.Image      = Common.Properties.Resources.image;
            _generatePdfTSB.Image        = Common.Properties.Resources.pdf;
            _runPerformanceTSB.Image     = Common.Properties.Resources.stopwatch;

            StartPosition = FormStartPosition.CenterScreen;
            var size = Screen.GetWorkingArea(Point.Empty);

            Size = new Size((int)(size.Width * 0.7), (int)(size.Height * 0.8));

            LoadCustomFonts();

            _showIEViewTSSB.Enabled = !HtmlRenderingHelper.IsRunningOnMono();
            _generatePdfTSB.Enabled = !HtmlRenderingHelper.IsRunningOnMono();
        }
        public GenerateImageForm(string html)
        {
            _html = html;
            InitializeComponent();

            Icon = DemoForm.GetIcon();

            _background = HtmlRenderingHelper.CreateImageForTransparentBackground();

            foreach (var color in GetColors())
            {
                if (color != Color.Transparent)
                {
                    _backgroundColorTSB.Items.Add(color.Name);
                }
            }
            _backgroundColorTSB.SelectedItem = Color.White.Name;

            foreach (var hint in Enum.GetNames(typeof(TextRenderingHint)))
            {
                _textRenderingHintTSCB.Items.Add(hint);
            }
            _textRenderingHintTSCB.SelectedItem = TextRenderingHint.AntiAlias.ToString();

            _useGdiPlusTSB.Enabled      = !HtmlRenderingHelper.IsRunningOnMono();
            _backgroundColorTSB.Enabled = !HtmlRenderingHelper.IsRunningOnMono();
        }
        /// <summary>
        /// On tree view node click load the html to the html panel and html editor.
        /// </summary>
        private void OnSamplesTreeViewAfterSelect(object sender, TreeViewEventArgs e)
        {
            var sample = e.Node.Tag as HtmlSample;

            if (sample != null)
            {
                _updateLock = true;

                if (!HtmlRenderingHelper.IsRunningOnMono() && e.Node.Parent.Text != PerformanceSamplesTreeNodeName)
                {
                    SetColoredText(sample.Html);
                }
                else
                {
                    _htmlEditor.Text = sample.Html;
                }

                Application.UseWaitCursor = true;

                try
                {
                    _htmlPanel.AvoidImagesLateLoading = !sample.FullName.Contains("Many images");

                    _htmlPanel.Text = sample.Html;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Failed to render HTML");
                }

                Application.UseWaitCursor = false;
                _updateLock = false;

                UpdateWebBrowserHtml();
            }
        }