コード例 #1
0
        private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            Graphics g = e.Graphics;

            if ((e.State & DrawItemState.ComboBoxEdit) > 0)
            {
                TextRenderer.DrawText(g, ComboBoxEx.Text, e.Font, e.Bounds.Location, e.ForeColor, e.BackColor);
            }
            else if (e.Index >= 0)
            {
                string name = (string)Items[e.Index];
                using (TextObject sample = new TextObject())
                {
                    sample.Bounds    = new RectangleF(e.Bounds.Left + 2, e.Bounds.Top + 2, e.Bounds.Width - 4, e.Bounds.Height - 4);
                    sample.Text      = name;
                    sample.HorzAlign = HorzAlign.Center;
                    sample.VertAlign = VertAlign.Center;
                    if (FReport != null)
                    {
                        int index = FReport.Styles.IndexOf(name);
                        if (index != -1)
                        {
                            sample.ApplyStyle(FReport.Styles[index]);
                        }
                    }
                    using (GraphicCache cache = new GraphicCache())
                    {
                        sample.Draw(new FRPaintEventArgs(g, 1, 1, cache));
                    }
                }
            }
        }
コード例 #2
0
ファイル: StyleListBox.cs プロジェクト: zixing131/LAEACC
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();
            Graphics g = e.Graphics;

            if (e.Index >= 0)
            {
                string name = (string)Items[e.Index];
                using (TextObject sample = new TextObject())
                {
                    sample.Bounds    = new RectangleF(e.Bounds.Left + 2, e.Bounds.Top + 2, e.Bounds.Width - 4, e.Bounds.Height - 4);
                    sample.Text      = name;
                    sample.HorzAlign = HorzAlign.Center;
                    sample.VertAlign = VertAlign.Center;
                    if (FStyles != null)
                    {
                        int index = FStyles.IndexOf(name);
                        if (index != -1)
                        {
                            sample.ApplyStyle(FStyles[index]);
                        }
                    }
                    using (GraphicCache cache = new GraphicCache())
                    {
                        sample.Draw(new FRPaintEventArgs(g, 1, 1, cache));
                    }
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <b>FRPaintEventArgs</b> class with specified settings.
 /// </summary>
 /// <param name="g"><b>IGraphicsRenderer</b> object to draw on.</param>
 /// <param name="scaleX">X scale factor.</param>
 /// <param name="scaleY">Y scale factor.</param>
 /// <param name="cache">Cache that contains graphics objects.</param>
 public FRPaintEventArgs(IGraphics g, float scaleX, float scaleY, GraphicCache cache)
 {
     graphics    = g;
     this.scaleX = scaleX;
     this.scaleY = scaleY;
     this.cache  = cache;
 }
コード例 #4
0
        private Bitmap GetImage(HighlightCondition c)
        {
            Bitmap bmp = new Bitmap(16, 16);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.FillRectangle(Brushes.White, 0, 0, 16, 16);

                using (TextObject sample = new TextObject())
                {
                    sample.Bounds = new RectangleF(0, 0, 15, 15);
                    sample.ApplyCondition(c);
                    sample.Font      = new Font("Times New Roman", 12, FontStyle.Bold);
                    sample.Text      = "A";
                    sample.HorzAlign = HorzAlign.Center;
                    sample.VertAlign = VertAlign.Center;

                    using (GraphicCache cache = new GraphicCache())
                    {
                        sample.Draw(new FRPaintEventArgs(g, 1, 1, cache));
                    }
                }
            }

            return(bmp);
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <b>FRPaintEventArgs</b> class with specified settings.
 /// </summary>
 /// <param name="g"><b>Graphics</b> object to draw on.</param>
 /// <param name="scaleX">X scale factor.</param>
 /// <param name="scaleY">Y scale factor.</param>
 /// <param name="cache">Cache that contains graphics objects.</param>
 public FRPaintEventArgs(Graphics g, float scaleX, float scaleY, GraphicCache cache)
 {
     FGraphics = g;
     FScaleX   = scaleX;
     FScaleY   = scaleY;
     FCache    = cache;
 }
コード例 #6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            // draw control frame
            Pen p = new Pen(Color.FromArgb(127, 157, 185));

            g.DrawRectangle(p, 0, 0, Width - 1, Height - 1);
            p.Dispose();
            // draw corners
            p = SystemPens.ControlDark;
            g.DrawLine(p, 10, 10, 10, 5);
            g.DrawLine(p, 10, 10, 5, 10);
            g.DrawLine(p, 10, Height - 11, 10, Height - 6);
            g.DrawLine(p, 10, Height - 11, 5, Height - 11);
            g.DrawLine(p, Width - 11, 10, Width - 11, 5);
            g.DrawLine(p, Width - 11, 10, Width - 6, 10);
            g.DrawLine(p, Width - 11, Height - 11, Width - 11, Height - 6);
            g.DrawLine(p, Width - 11, Height - 11, Width - 6, Height - 11);
            // draw text
            StringFormat sf = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(Res.Get("Misc,Sample"), Font, SystemBrushes.WindowText, DisplayRectangle, sf);
            sf.Dispose();
            // draw border
            if (Border != null)
            {
                using (GraphicCache cache = new GraphicCache())
                {
                    Border.Draw(new FRPaintEventArgs(g, 1, 1, cache), new RectangleF(10, 10, Width - 21, Height - 21));
                }
            }
        }
コード例 #7
0
        private Stream CreateBarcodeImageStream(PrintElementBuildContext buildContext, dynamic elementMetadata, PrintElementSize imageSize)
        {
            string textSting = BuildHelper.FormatValue(buildContext, elementMetadata.Text, elementMetadata.SourceFormat);

            textSting = PrepareText(textSting);

            if (textSting != null)
            {
                bool showText;
                showText = !ConvertHelper.TryToBool(elementMetadata.ShowText, out showText) || showText;

                // Для генерации штрих-кода используется функциональность FastReport

                try
                {
                    var barcode = new BarcodeObject
                    {
                        Barcode  = CreateBarcode(elementMetadata),
                        ShowText = showText,
                        Text     = textSting,
                        Height   = 64
                    };

                    // Для получения размеров штрих-кода рисуем его первый раз
                    using (var codeBmp = new Bitmap(1, 1))
                        using (var graphics = Graphics.FromImage(codeBmp))
                            using (var graphicCache = new GraphicCache())
                            {
                                barcode.Draw(new FRPaintEventArgs(graphics, 1, 1, graphicCache));
                            }

                    // Теперь, зная размеры штрих-кода, рисуем его второй раз
                    if (barcode.Width > 0 && barcode.Height > 0)
                    {
                        using (var codeBmp = new Bitmap((int)barcode.Width, (int)barcode.Height))
                            using (var graphics = Graphics.FromImage(codeBmp))
                                using (var graphicCache = new GraphicCache())
                                {
                                    graphics.Clear(Color.White);
                                    barcode.Draw(new FRPaintEventArgs(graphics, 1, 1, graphicCache));

                                    imageSize.Width  = codeBmp.Width;
                                    imageSize.Height = codeBmp.Height;

                                    var codeStream = new MemoryStream();
                                    codeBmp.Save(codeStream, ImageFormat.Png);
                                    codeStream.Seek(0, SeekOrigin.Begin);

                                    return(codeStream);
                                }
                    }
                }
                catch
                {
                }
            }

            return(null);
        }
コード例 #8
0
ファイル: StyleEditorForm.cs プロジェクト: zixing131/LAEACC
 private void pnSample_Paint(object sender, PaintEventArgs e)
 {
     if (CurrentStyle == null)
     {
         return;
     }
     FSample.ApplyStyle(CurrentStyle);
     FSample.Bounds    = new RectangleF(2, 2, pnSample.Width - 4, pnSample.Height - 4);
     FSample.HorzAlign = HorzAlign.Center;
     FSample.VertAlign = VertAlign.Center;
     using (GraphicCache cache = new GraphicCache())
     {
         FSample.Draw(new FRPaintEventArgs(e.Graphics, 1, 1, cache));
     }
 }
コード例 #9
0
        private void DrawPages(Graphics g)
        {
            if (Disabled)
            {
                return;
            }

            // draw visible pages
            int firstVisible = PreviewPages.FindFirstVisiblePage(Offset.Y);
            int lastVisible  = PreviewPages.FindLastVisiblePage(Offset.Y + ClientSize.Height);

            for (int i = firstVisible; i <= lastVisible; i++)
            {
                Rectangle pageBounds = PreviewPages.GetPageBounds(i);
                pageBounds.Offset(-Offset.X, -Offset.Y);
                ReportPage page = PreparedPages.GetCachedPage(i);

                // draw shadow around page
                ShadowPaintInfo pi = new ShadowPaintInfo();
                pi.Graphics  = g;
                pi.Rectangle = new Rectangle(pageBounds.Left - 4, pageBounds.Top - 4, pageBounds.Width + 4, pageBounds.Height + 4);
                pi.Size      = 5;
                ShadowPainter.Paint2(pi);

                // shift the origin because page.Draw draws at 0, 0
                g.TranslateTransform((int)pageBounds.Left, (int)pageBounds.Top);
                FRPaintEventArgs e = new FRPaintEventArgs(g, Zoom, Zoom, GraphicCache);
                // draw page
                page.Draw(e);

                // draw search highlight
                if (SearchInfo != null && SearchInfo.Visible && SearchInfo.PageNo == i + 1)
                {
                    page.DrawSearchHighlight(e, SearchInfo.ObjNo, SearchInfo.Ranges[SearchInfo.RangeNo]);
                }
                g.ResetTransform();

                // draw border around active page
                if (i == PageNo - 1)
                {
                    Pen borderPen = GraphicCache.GetPen(Preview.ActivePageBorderColor, 2, DashStyle.Solid);
                    pageBounds.Inflate(-1, -1);
                    g.DrawRectangle(borderPen, pageBounds);
                }
            }
        }
コード例 #10
0
        private void pnSample_Paint(object sender, PaintEventArgs e)
        {
            if (CurrentCondition == null)
            {
                return;
            }

            TextObject sample = new TextObject();

            sample.Text = Res.Get("Misc,Sample");
            sample.ApplyCondition(CurrentCondition);
            sample.Bounds    = new RectangleF(2, 2, pnSample.Width - 4, pnSample.Height - 4);
            sample.HorzAlign = HorzAlign.Center;
            sample.VertAlign = VertAlign.Center;
            using (GraphicCache cache = new GraphicCache())
            {
                sample.Draw(new FRPaintEventArgs(e.Graphics, 1, 1, cache));
            }
        }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <b>FRPaintEventArgs</b> class with specified settings.
 /// </summary>
 /// <param name="g"><b>Graphics</b> object to draw on.</param>
 /// <param name="scaleX">X scale factor.</param>
 /// <param name="scaleY">Y scale factor.</param>
 /// <param name="cache">Cache that contains graphics objects.</param>
 public FRPaintEventArgs(Graphics g, float scaleX, float scaleY, GraphicCache cache) :
     this(new GdiGraphics(g, false), scaleX, scaleY, cache)
 {
 }