示例#1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (mCom != null && e != null && e.Graphics != null)
            {
                e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                RowHeight = Font.Height + 2;

                int queueCount      = mCom.Executed;
                int controlCapacity = Height / RowHeight;

                if (queueCount > controlCapacity)
                {
                    bool keepScrolling = (ScrollBar.Value >= ScrollBar.Maximum - 10);

                    ScrollBar.Minimum = 0;
                    ScrollBar.Maximum = (queueCount - controlCapacity);

                    if (keepScrolling)
                    {
                        ScrollBar.Value = ScrollBar.Maximum;
                    }
                }
                else
                {
                    ScrollBar.Minimum = 0;
                    ScrollBar.Value   = 0;
                    ScrollBar.Maximum = 0;
                }



                int howmany = Math.Min(Height / RowHeight, queueCount);
                int index   = ScrollBar.Value;
                mDraw = mCom.SentCommand(index, howmany);
                if (mDraw != null)
                {
                    using (StringFormat esf = new StringFormat(StringFormat.GenericTypographic))
                    {
                        esf.Trimming = StringTrimming.EllipsisCharacter;

                        for (int i = 0; i < mDraw.Count; i++)
                        {
                            IGrblRow cmd = mDraw[i];
                            if (cmd != null)
                            {
                                float  respectX = 0;
                                string result   = cmd.GetResult(mCom.SupportCSV, mUseImages);
                                string message  = cmd.GetMessage();
                                if (result != null)
                                {
                                    respectX = e.Graphics.MeasureString(result, Font).Width;
                                    using (Brush b = new SolidBrush(cmd.RightColor))
                                        e.Graphics.DrawString(result, Font, b, Width - ScrollBar.Width - 1, RowHeight * i + 2, new StringFormat(StringFormatFlags.DirectionRightToLeft));
                                }
                                if (message != null)
                                {
                                    using (Brush b = new SolidBrush(cmd.LeftColor))
                                        e.Graphics.DrawString(message, Font, b, new RectangleF(mUseImages && cmd.ImageIndex >= 0 ? RowHeight + 1 : 1, RowHeight * i + 1, Width - ScrollBar.Width - (mUseImages ? IL.ImageSize.Width + 2 : 2) - respectX, RowHeight - 2), esf);
                                    //e.Graphics.DrawString(cmd.GetMessage(), Font, b, mUseImages && cmd.ImageIndex >= 0 ? RowHeight + 1 : 1, RowHeight * i + 1);
                                }
                                if (mUseImages && cmd.ImageIndex >= 0 && cmd.ImageIndex < IL.Images.Count)
                                {
                                    Image I = IL.Images[cmd.ImageIndex];
                                    if (I != null)
                                    {
                                        int iW = RowHeight - 2;
                                        int iH = RowHeight - 2;
                                        e.Graphics.DrawImage(I, 1, RowHeight * i + (RowHeight - iH) / 2, iW, iH);
                                    }
                                }

                                e.Graphics.DrawLine(Pens.LightGray, 0, RowHeight * (i + 1), Width, RowHeight * (i + 1));
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (mCom != null)
            {
                e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                RowHeight = Font.Height + 2;

                int queueCount      = mCom.Executed;
                int controlCapacity = Height / RowHeight;

                if (queueCount > controlCapacity)
                {
                    bool keepScrolling = (ScrollBar.Value == ScrollBar.Maximum);

                    ScrollBar.Minimum = 0;
                    ScrollBar.Maximum = (queueCount - controlCapacity);

                    if (keepScrolling)
                    {
                        ScrollBar.Value = ScrollBar.Maximum;
                    }
                }
                else
                {
                    ScrollBar.Minimum = 0;
                    ScrollBar.Value   = 0;
                    ScrollBar.Maximum = 0;
                }



                int howmany = Math.Min(Height / RowHeight, queueCount);
                int index   = ScrollBar.Value;
                mDraw = mCom.SentCommand(index, howmany);

                for (int i = 0; i < mDraw.Count; i++)
                {
                    IGrblRow cmd = mDraw[i];

                    if (cmd.GetMessage() != null)
                    {
                        using (Brush b = new SolidBrush(cmd.LeftColor))
                            e.Graphics.DrawString(cmd.GetMessage(), Font, b, mUseImages && cmd.ImageIndex >= 0 ? RowHeight + 1 : 1, RowHeight * i + 1);
                    }

                    if (mUseImages && cmd.ImageIndex >= 0)
                    {
                        System.Drawing.Image I = IL.Images[cmd.ImageIndex];
                        int iW = RowHeight - 2;
                        int iH = RowHeight - 2;
                        e.Graphics.DrawImage(I, /*Width - ScrollBar.Width - iW - 2*/ 1, RowHeight * i + (RowHeight - iH) / 2, iW, iH);
                    }
                    if (!mUseImages && cmd.GetResult(mCom.SupportCSV) != null)
                    {
                        using (Brush b = new SolidBrush(cmd.RightColor))
                            e.Graphics.DrawString(cmd.GetResult(mCom.SupportCSV), Font, b, Width - ScrollBar.Width - 1, RowHeight * i + 2, new StringFormat(StringFormatFlags.DirectionRightToLeft));
                    }



                    e.Graphics.DrawLine(Pens.LightGray, 0, RowHeight * (i + 1), Width, RowHeight * (i + 1));
                }
            }
        }