예제 #1
0
        private static void doMeasureText(MeasureTextInformation information, MeasureTextResult result)
        {
            if (string.IsNullOrEmpty(information.Text))
            {
                result.Size = new Size();
            }
            else if (information.Font == null)
            {
                throw new ArgumentNullException();
            }
            else if (information.MaxWidth == null)
            {
                throw new ArgumentNullException();
            }
            else if (information.Control == null && information.Graphics == null)
            {
                throw new ArgumentNullException();
            }
            else if (information.Control != null && !information.Control.IsHandleCreated)
            {
                throw new Exception("No control handle (yet).");
            }
            else
            {
                var graphics = information.Graphics ?? information.Control.CreateGraphics();
                try
                {
                    var gc = new GraphicsCache(graphics);

                    if (information.MaxHeight == null)
                    {
                        result.Size =
                            Size.Round(gc.CalcTextSize(information.Text, information.Font,
                                                       information.Format ?? new StringFormat(),
                                                       information.MaxWidth.Value));
                    }
                    else if (information.MaxHeight != null)
                    {
                        bool isCropped;
                        result.Size =
                            Size.Round(gc.CalcTextSize(information.Text, information.Font,
                                                       information.Format ?? new StringFormat(),
                                                       information.MaxWidth.Value, information.MaxHeight.Value, out isCropped));
                        result.IsCropped = isCropped;
                    }
                }
                finally
                {
                    if (information.Graphics == null)
                    {
                        graphics.Dispose();
                    }
                }
            }
        }
예제 #2
0
        protected override void Draw(OverlayWindowCustomDrawContext context)
        {
            //The Handled event parameter should be set to true.
            //to disable the default drawing algorithm.
            context.Handled = true;
            //Provides access to the drawing surface.
            GraphicsCache cache = context.DrawArgs.Cache;

            //Adjust the TextRenderingHint option
            //to improve the image quality.
            cache.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            //Overlapped control bounds.
            Rectangle bounds = context.DrawArgs.Bounds;

            //Draws the default background.
            context.DrawBackground();
            //Specify the string that will be drawn on the Overlay Form instead of the wait indicator.
            String drawString = text;
            //Get the system's black brush.
            Brush drawBrush = Brushes.Black;
            //Calculate the size of the message string.
            SizeF textSize = cache.CalcTextSize(drawString, drawFont);
            //A point that specifies the upper-left corner of the rectangle where the string will be drawn.
            PointF drawPoint = new PointF(
                bounds.Left + bounds.Width / 2 - textSize.Width / 2,
                bounds.Top + bounds.Height / 2 - textSize.Height / 2
                );

            //Draw the string on the screen.
            cache.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);
        }
예제 #3
0
        void DrawLink(CustomDrawCellEventArgs e, GraphicsCache cache, string text)
        {
            e.DrawDefault();
            e.Handled = true;
            var        brush      = cache.GetSolidBrush(Color.FromArgb(5, 111, 206));
            var        font       = cache.GetFont(e.Font, FontStyle.Underline);
            SizeF      size       = cache.CalcTextSize(text, font, StringFormat.GenericDefault, 0);
            float      height     = (float)e.Bounds.Height - size.Height;
            RectangleF textBounds = new RectangleF(e.Bounds.Left + 8, e.Bounds.Top + height / 2, size.Width + 4, size.Height);

            cache.DrawString(text, font, brush, Rectangle.Round(textBounds), StringFormat.GenericDefault);
        }
예제 #4
0
        private int CalcColumnBestWidth(GridView view, GridColumn c)
        {
            var info     = ((GridViewInfo)view.GetViewInfo()).RowsInfo;
            int rowCount = info.Count;

            int maxWidth = 0;

            using (GraphicsCache cache = this.gcTickers.CreateGraphicsCache()) {
                foreach (var row in info)
                {
                    string text  = view.GetRowCellDisplayText(row.RowHandle, c);
                    int    width = (int)(cache.CalcTextSize(text, c.AppearanceCell.Font).Width) + 6;
                    maxWidth = Math.Max(width, maxWidth);
                }
            }
            return(maxWidth);
        }
예제 #5
0
파일: ilabelinfo.cs 프로젝트: iamwsx05/hms
        public static int GetElementWidth(bool editor, string text, GraphicsCache cache, Font font, StringFormat format)
        {
            int width = 0;

            if (LabelInfoHelper.IsActionElement(text))
            {
                width = LabelInfoHelper.ActionElementWidht;
            }
            else
            {
                if (!(cache.Paint is XPaintMixed))
                {
                    cache.Paint = new XPaintMixed();
                }
                width = (int)cache.CalcTextSize(text, font, format, 0).Width;
            }
            return(GetElementWidth(editor, width));
        }
예제 #6
0
 private void DrawString(GraphicsCache cache, Rectangle bounds, string text)
 {
     try
     {
         String drawString = text;
         Font   drawFont   = new Font("Tahoma", 9);
         //Get the system's black brush.
         Brush drawBrush = Brushes.Black;
         //Calculate the size of the message string.
         SizeF textSize = cache.CalcTextSize(drawString, drawFont);
         //A point that specifies the upper-left corner of the rectangle where the string will be drawn.
         PointF drawPoint = new PointF(
             bounds.Left + bounds.Width / 2 - textSize.Width / 2,
             bounds.Top + bounds.Height / 2 - textSize.Height / 2
             );
         //Draw the string on the screen.
         cache.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #7
0
파일: Painters.cs 프로젝트: 5509850/baumax
        public static void DrawWeekDayContent(StoreDay storeday, EmployeeDay epd, GraphicsCache cache, Rectangle rect, IRecordingContext context)
        {
            Font cellfont = _cellFont;
            Rectangle cellBound = Rectangle.Inflate(rect, -1, -1);
            Brush cellbrush = Brushes.Black ;
            StringFormat sformat = null;
            if (epd.HasLongAbsence)
            {
                string s = context.LongAbsences.GetAbbreviation(epd.LongAbsenceId);
                if (String.IsNullOrEmpty(s)) return;
                sformat = new StringFormat ();
                sformat.Alignment = StringAlignment.Center;
                sformat.LineAlignment = StringAlignment.Center;
                cache.DrawString(s, cellfont, cellbrush, cellBound, sformat);
            }
            else
            {
                List<string> lstValues = new List<string>();

                List<EmployeeTimeRange> lst = epd.TimeList;

                if (lst != null && lst.Count > 0)
                {
                    sformat = new StringFormat(StringFormatFlags.MeasureTrailingSpaces |
                                            StringFormatFlags.NoWrap);
                    //sformat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces |
                    //                        StringFormatFlags.NoWrap;

                    //cellbrush = Brushes.Black ;
                    Brush absenceBrush = null;
                    string str = String.Empty;
                    int heightCell = (int)(cellBound.Height);// / 2);
                    foreach (EmployeeTimeRange range in lst)
                    {
                        str = range.ToString();//TextParser.EmployeeTimeToString(range);

                        Size sf = cache.CalcTextSize(str, cellfont, sformat, 10000).ToSize ();

                        if (range.Absence == null)
                        {
                            cache.DrawString(str, cellfont, cellbrush, cellBound, sformat);
                        }
                        else
                        {
                            absenceBrush = cache.GetSolidBrush(Color.FromArgb(range.Absence.Color));
                            cache.DrawString(str, cellfont, absenceBrush, cellBound, sformat);

                        }

                        cellBound.Y += sf.Height + 2;
                        heightCell -= (sf.Height + 2);
                        if ((heightCell < 0)) break;//  - (sf.Height + 2)) < 0) break;
                        //if ((cellBound.Y + sf.Height) > (rect.Y + rect.Width)) break;
                    }

                }
            }
        }
예제 #8
0
        public static void DrawWeekDayContent(StoreDay storeday, EmployeeDay epd, GraphicsCache cache, Rectangle rect, IRecordingContext context)
        {
            Font         cellfont  = _cellFont;
            Rectangle    cellBound = Rectangle.Inflate(rect, -1, -1);
            Brush        cellbrush = Brushes.Black;
            StringFormat sformat   = null;

            if (epd.HasLongAbsence)
            {
                string s = context.LongAbsences.GetAbbreviation(epd.LongAbsenceId);
                if (String.IsNullOrEmpty(s))
                {
                    return;
                }
                sformat               = new StringFormat();
                sformat.Alignment     = StringAlignment.Center;
                sformat.LineAlignment = StringAlignment.Center;
                cache.DrawString(s, cellfont, cellbrush, cellBound, sformat);
            }
            else
            {
                List <string> lstValues = new List <string>();

                List <EmployeeTimeRange> lst = epd.TimeList;

                if (lst != null && lst.Count > 0)
                {
                    sformat = new StringFormat(StringFormatFlags.MeasureTrailingSpaces |
                                               StringFormatFlags.NoWrap);
                    //sformat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces |
                    //                        StringFormatFlags.NoWrap;

                    //cellbrush = Brushes.Black ;
                    Brush  absenceBrush = null;
                    string str          = String.Empty;
                    int    heightCell   = (int)(cellBound.Height);// / 2);
                    foreach (EmployeeTimeRange range in lst)
                    {
                        str = range.ToString();//TextParser.EmployeeTimeToString(range);

                        Size sf = cache.CalcTextSize(str, cellfont, sformat, 10000).ToSize();

                        if (range.Absence == null)
                        {
                            cache.DrawString(str, cellfont, cellbrush, cellBound, sformat);
                        }
                        else
                        {
                            absenceBrush = cache.GetSolidBrush(Color.FromArgb(range.Absence.Color));
                            cache.DrawString(str, cellfont, absenceBrush, cellBound, sformat);
                        }

                        cellBound.Y += sf.Height + 2;
                        heightCell  -= (sf.Height + 2);
                        if ((heightCell < 0))
                        {
                            break;                  //  - (sf.Height + 2)) < 0) break;
                        }
                        //if ((cellBound.Y + sf.Height) > (rect.Y + rect.Width)) break;
                    }
                }
            }
        }