Example #1
0
        public static bool AlterGridOptions(Report nreport)
        {
            bool nresult = false;

            using (GridOptions ndia = new GridOptions())
            {
                ndia.bcolor.BackColor     = GraphicUtils.ColorFromInteger(nreport.GridColor);
                ndia.checkenabled.Checked = nreport.GridEnabled;
                ndia.textwidth.Text       = Twips.TextFromTwips(nreport.GridWidth);
                ndia.textheight.Text      = Twips.TextFromTwips(nreport.GridHeight);
                if (nreport.GridLines)
                {
                    ndia.combostyle.SelectedIndex = 1;
                }
                else
                {
                    ndia.combostyle.SelectedIndex = 0;
                }
                ndia.checkvisible.Checked = nreport.GridVisible;
                if (ndia.ShowDialog() == DialogResult.OK)
                {
                    nreport.GridLines   = (ndia.combostyle.SelectedIndex == 1);
                    nreport.GridEnabled = ndia.checkenabled.Checked;
                    nreport.GridWidth   = Twips.TwipsFromText(ndia.textwidth.Text);
                    nreport.GridHeight  = Twips.TwipsFromText(ndia.textheight.Text);
                    nreport.GridColor   = GraphicUtils.IntegerFromColor(ndia.bcolor.BackColor);
                    nreport.GridVisible = ndia.checkvisible.Checked;
                    nresult             = true;
                }
            }
            return(nresult);
        }
Example #2
0
        override protected void DoPrint(PrintOut adriver, int aposx, int aposy,
                                        int newwidth, int newheight, MetaFile metafile, Point MaxExtent,
                                        ref bool PartialPrint)
        {
            string data;

            base.DoPrint(adriver, aposx, aposy, newwidth, newheight,
                         metafile, MaxExtent, ref PartialPrint);
            CurrentText = GetText();
            try
            {
                if (BarType == BarcodeType.CodeQR)
                {
#if PocketPC
                    throw new Exception("QRCode not implemented in PocketPC");
#else
                    QRCodeEncoder nenc = new QRCodeEncoder();
                    nenc.QRCodeForegroundColor = GraphicUtils.ColorFromInteger(BColor);
                    nenc.QRCodeEncodeMode      = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC;
                    nenc.QRCodeVersion         = System.Convert.ToInt32(Ratio);
                    nenc.EncodeInMetafile(metafile, aposx, aposy, this.Modul, CurrentText, System.Text.Encoding.UTF8);
#endif
                }
                else
                {
                    data = CalculateBarcode();
                    // draw the barcode
                    DoLines(data, aposx, aposy, metafile);
                }
            }
            catch (Exception E)
            {
                throw new ReportException(E.Message + ":" + Translator.TranslateStr(573),
                                          this, "Barcode");
            }
        }
Example #3
0
        public override void DrawChart(Series nseries, MetaFile ametafile, int posx, int posy, object achart)
        {
            System.Windows.Forms.DataVisualization.Charting.Chart nchart = new System.Windows.Forms.DataVisualization.Charting.Chart();

            float afontsize = Convert.ToSingle(Math.Round(nseries.FontSize * nseries.Resolution / 100));

            //achart.BackColor:=clTeeColor;
            nchart.BackColor = Color.White;

            /*achart.LeftAxis.LabelsFont.Name:=nchart.WFontName;
             * achart.BottomAxis.LabelsFont.Name:=nchart.WFontName;
             * achart.Legend.Font.Name:=nchart.WFontName;
             * achart.LeftAxis.LabelsFont.Style:=CLXIntegerToFontStyle(nchart.FontStyle);
             * achart.BottomAxis.LabelsFont.Style:=CLXIntegerToFontStyle(nchart.FontStyle);
             * achart.Legend.Font.Size:=aFontSize;
             * achart.Legend.Font.Style:=CLXIntegerToFontStyle(nchart.FontStyle);*/
            /*achart.Legend.Visible:=nchart.ShowLegend;*/
            // autorange and other ranges

            /*achart.LeftAxis.Maximum:=Series.HighValue;
             * achart.LeftAxis.Minimum:=Series.LowValue;
             * achart.LeftAxis.Automatic:=false;
             * achart.LeftAxis.AutomaticMaximum:=Series.AutoRangeH;
             * achart.LeftAxis.AutomaticMinimum:=Series.AutoRangeL;
             * achart.LeftAxis.LabelsAngle:=nchart.VertFontRotation mod 360;
             * achart.LeftAxis.LabelsFont.Size:=Round(nchart.VertFontSize*nchart.Resolution/100);
             * achart.BottomAxis.LabelsAngle:=nchart.HorzFontRotation mod 360;
             * achart.BottomAxis.LabelsFont.Size:=Round(nchart.HorzFontSize*nchart.Resolution/100);*/
            nchart.ChartAreas.Add("");
            if (nseries.Effect3D)
            {
                nchart.ChartAreas[0].Area3DStyle.Enable3D    = nseries.Effect3D;;
                nchart.ChartAreas[0].Area3DStyle.IsClustered = true;
            }
            //nchart.ChartAreas[0].AxisX.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
            //nchart.ChartAreas[0].AxisY.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
            //nchart.ChartAreas[0].AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
            //nchart.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
            nchart.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
            nchart.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
            if (nseries.Logaritmic)
            {
                nchart.ChartAreas[0].AxisY.IsLogarithmic = true;
                nchart.ChartAreas[0].AxisY.LogarithmBase = nseries.LogBase;
            }
            nchart.ChartAreas[0].AxisY.IsReversed = nseries.Inverted;
            //nchart.ChartAreas[0].AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
            nchart.ChartAreas[0].AxisX.IntervalAutoMode    = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.FixedCount;
            nchart.ChartAreas[0].AxisX.LabelStyle.Interval = 1;

            if (!nseries.AutoRangeH)
            {
                //nchart.ChartAreas[0].AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.
                nchart.ChartAreas[0].AxisY.Maximum = nseries.HighValue;
            }
            if (nseries.VertFontRotation != 0)
            {
                nchart.ChartAreas[0].AxisY.LabelStyle       = new System.Windows.Forms.DataVisualization.Charting.LabelStyle();
                nchart.ChartAreas[0].AxisY.LabelStyle.Angle = nseries.VertFontRotation;
            }
            if (nseries.HorzFontRotation != 0)
            {
                nchart.ChartAreas[0].AxisY.LabelStyle       = new System.Windows.Forms.DataVisualization.Charting.LabelStyle();
                nchart.ChartAreas[0].AxisY.LabelStyle.Angle = nseries.HorzFontRotation;
            }
            if (!nseries.AutoRangeL)
            {
                //nchart.ChartAreas[0].AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.
                nchart.ChartAreas[0].AxisY.Minimum = nseries.LowValue;
            }
            if (nseries.ShowLegend)
            {
                nchart.Legends.Add("");
            }
            // Create series
            int acolor   = 0;
            int idxserie = 0;

            foreach (SeriesItem sitem in nseries.SeriesItems)
            {
                System.Windows.Forms.DataVisualization.Charting.Series chartserie = nchart.Series.Add(sitem.Caption);
                switch (sitem.ChartStyle)
                {
                case ChartType.Area:
                    chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area;
                    break;

                case ChartType.Gantt:
                case ChartType.Arrow:
                    chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                    break;

                case ChartType.Bar:
                    switch (nseries.MultiBar)
                    {
                    case BarType.Stacked:
                        chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
                        break;

                    case BarType.Stacked100:
                        chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn100;
                        break;

                    default:
                        chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
                        break;
                    }
                    break;

                case ChartType.Bubble:
                    chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble;
                    break;

                case ChartType.Horzbar:
                    switch (nseries.MultiBar)
                    {
                    case BarType.Stacked:
                        chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar;
                        break;

                    case BarType.Stacked100:
                        chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar100;
                        break;

                    default:
                        chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
                        break;
                    }
                    break;

                case ChartType.Line:
                    chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                    break;

                case ChartType.Pie:
                    chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                    break;

                case ChartType.Point:
                    chartserie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
                    break;
                }
                chartserie.Label = sitem.Caption;
                if (nseries.ShowHint)
                {
                    chartserie.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Square;
                }
                else
                {
                    chartserie.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.None;
                }
                if (sitem.ChartStyle == ChartType.Pie)
                {
                    // Set these other two properties so that you can see the connecting lines
                    nchart.Series[0].BorderWidth = 1;
                    nchart.Series[0].BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
                    // Set the pie label as well as legend text to be displayed as percentage
                    // The P2 indicates a precision of 2 decimals
                    //nchart.Series[0].Label = "#VALX #PERCENT{P2} #VAL";
                    nchart.Series[0].Label = "#PERCENT{P2}";

                    nchart.Series[0]["PieLabelStyle"] = "Outside";
                    //nchart.Legends[0].CustomItems.Add(npoint.Color, sitem.ValueCaptions[j]);
                    //nchart.Series[0].LegendText = "#VALX  (#PERCENT) #VAL";
                    nchart.Series[0].LegendText = "#VALX #VAL";
                    //this.Chart2.Series[0].LegendText = "#VALX (#PERCENT)"
                    //nchart.Legends[0].= sitem.ValueCaptions[j];

                    //n.Legends.Add("Legend1");
                    nchart.Legends[0].Enabled   = true;
                    nchart.Legends[0].Docking   = System.Windows.Forms.DataVisualization.Charting.Docking.Bottom;
                    nchart.Legends[0].Alignment = System.Drawing.StringAlignment.Center;
                }
                if (sitem.Color > 0)
                {
                    chartserie.Color = GraphicUtils.ColorFromInteger(sitem.Color);
                }
                else
                {
                    chartserie.Color = GraphicUtils.ColorFromInteger(SeriesColors[acolor]);
                }
                double total = 0;
                if (nseries.MarkStyle == 1)
                {
                    for (int j = 0; j < sitem.Values.Count; j++)
                    {
                        object nobj = sitem.Values[j];
                        if (DoubleUtil.IsNumericType(nobj))
                        {
                            total = total + Convert.ToDouble(nobj);
                        }
                    }
                }

                for (int j = 0; j < sitem.Values.Count; j++)
                {
                    string ncaption = sitem.ValueCaptions[j];
                    if (ncaption == null)
                    {
                        ncaption = "";
                    }
                    int idx = chartserie.Points.AddXY(ncaption, sitem.Values[j]);
                    System.Windows.Forms.DataVisualization.Charting.DataPoint npoint = chartserie.Points[idx];

                    if (sitem.ChartStyle != ChartType.Pie)
                    {
                        if (nseries.ShowHint)
                        {
                            switch (nseries.MarkStyle)
                            {
                            case 1:
                                npoint.Label = "";
                                if ((DoubleUtil.IsNumericType(sitem.Values[j])) && (total != 0))
                                {
                                    npoint.Label = (Convert.ToDouble(sitem.Values[j]) / total * 100).ToString("N2") + "%";
                                }
                                break;

                            case 6:
                                npoint.Label = "";
                                if (DoubleUtil.IsNumericType(sitem.Values[j]))
                                {
                                    double nuevo_valor = Convert.ToDouble(sitem.Values[j]);
                                    npoint.Label = nuevo_valor.ToString("N1") + "%";
                                }
                                break;

                            default:
                                npoint.Label = sitem.Values[j].ToString();
                                break;
                            }
                        }
                        else
                        {
                            npoint.Label = "";
                        }
                    }
                    if (nseries.SeriesItems.Count < 2)
                    {
                        if (sitem.Colors[j] >= 0)
                        {
                            npoint.Color = GraphicUtils.ColorFromInteger(sitem.Colors[j]);
                        }
                        else
                        {
                            npoint.Color = GraphicUtils.ColorFromInteger(SeriesColors[acolor]);
                        }
                        if ((sitem.ChartStyle == ChartType.Pie) || nseries.ShowLegend)
                        {
                            if (sitem.ChartStyle == ChartType.Pie)
                            {
                            }
                            else
                            {
                                if (j != 0)
                                {
                                    nchart.Legends[0].CustomItems.Add(npoint.Color, sitem.ValueCaptions[j]);
                                }
                                else
                                {
                                    nchart.Legends.Add(sitem.ValueCaptions[j]);
                                }
                            }

                            acolor = ((acolor + 1) % (MAX_SERIECOLORS));
                        }
                    }
                    else
                    {
                        if (sitem.Colors[j] >= 0)
                        {
                            npoint.Color = GraphicUtils.ColorFromInteger(sitem.Colors[j]);
                        }
                        else
                        {
                            npoint.Color = GraphicUtils.ColorFromInteger(SeriesColors[acolor]);
                        }
                    }
                }
                acolor = ((acolor + 1) % (MAX_SERIECOLORS));
                idxserie++;
            }

            Bitmap nbitmap = new Bitmap(Convert.ToInt32(Convert.ToSingle(Twips.TwipsToInch(nseries.PrintWidth)) * nseries.Resolution),
                                        Convert.ToInt32(Convert.ToSingle(Twips.TwipsToInch(nseries.PrintHeight)) * nseries.Resolution), PixelFormat.Format24bppRgb);
            Rectangle rec = new Rectangle(0, 0, nbitmap.Width, nbitmap.Height);

            nchart.SetBounds(0, 0, nbitmap.Width, nbitmap.Height);
            nchart.Update();
            nchart.DrawToBitmap(nbitmap, rec);
            System.IO.MemoryStream mstream = new MemoryStream();

            nbitmap.Save(mstream, ImageFormat.Bmp);

            MetaObjectImage metaobj = new MetaObjectImage();

            metaobj.MetaType       = MetaObjectType.Image;
            metaobj.Top            = posy; metaobj.Left = posx;
            metaobj.Width          = nseries.PrintWidth;
            metaobj.Height         = nseries.PrintHeight;
            metaobj.CopyMode       = 20;
            metaobj.DrawImageStyle = ImageDrawStyleType.Stretch;
            metaobj.DPIRes         = Convert.ToInt32(nseries.Resolution);
            metaobj.PreviewOnly    = false;
            metaobj.StreamPos      = ametafile.Pages[ametafile.CurrentPage].AddStream(mstream, false);
            metaobj.SharedImage    = false;
            metaobj.StreamSize     = mstream.Length;
            ametafile.Pages[ametafile.CurrentPage].Objects.Add(metaobj);

            base.DrawChart(nseries, ametafile, posx, posy, achart);
        }
        public override void InitializeEditingControl(int rowIndex, object
                                                      initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
        {
            // Set the value of the editing control to the current cell value.
            base.InitializeEditingControl(rowIndex, initialFormattedValue,
                                          dataGridViewCellStyle);
            Reportman.Reporting.Variant nvalue = (Variant)GetColumnValue("VALUE", rowIndex);
            ObjectInspectorCellType     ntype  = (ObjectInspectorCellType)GetColumnValue("TYPEENUM", rowIndex);

            if (ntype == ObjectInspectorCellType.Image)
            {
                nvalue = (Variant)GetColumnValue("VALUEBIN", rowIndex);
            }

            if (DataGridView.EditingControl is DataGridViewComboBoxEditingControl)
            {
                ComboBoxPicker = DataGridView.EditingControl as DataGridViewComboBoxEditingControl;
                Strings list = (Strings)GetColumnValue("VALUELIST", rowIndex);
                ComboBoxPicker.Items.Clear();
                foreach (string s in list)
                {
                    ComboBoxPicker.Items.Add(s);
                }
                if (ntype == ObjectInspectorCellType.DropDown)
                {
                    ComboBoxPicker.DropDownStyle = ComboBoxStyle.DropDown;

                    ComboBoxPicker.Text = nvalue.ToString();
                }
                else
                {
                    ComboBoxPicker.DropDownStyle = ComboBoxStyle.DropDownList;

                    if (!(nvalue.IsNull))
                    {
                        int index = -1;
                        if (nvalue.IsString())
                        {
                            index = ComboBoxPicker.Items.IndexOf(nvalue.ToString());
                        }
                        else
                        {
                            index = nvalue;
                        }

                        if ((index < ComboBoxPicker.Items.Count) && (index >= 0))
                        {
                            ComboBoxPicker.SelectedIndex = index;
                        }
                        else
                        {
                            ComboBoxPicker.SelectedIndex = -1;
                        }
                    }
                    else
                    {
                        ComboBoxPicker.SelectedIndex = -1;
                    }
                }
            }
            else
            if (DataGridView.EditingControl is DataGridViewTextBoxEditingControl)
            {
                TextBoxPicker = DataGridView.EditingControl as DataGridViewTextBoxEditingControl;
                switch (ntype)
                {
                case ObjectInspectorCellType.FontStyle:
                    TextBoxPicker.ReadOnly  = true;
                    TextBoxPicker.BackColor = SystemColors.Info;
                    TextBoxPicker.ForeColor = SystemColors.InfoText;
                    TextBoxPicker.Click    += ClickFontStyleEvent;
                    TextBoxPicker.Text      = GraphicUtils.StringFontStyleFromInteger((int)nvalue);
                    break;

                default:
                    TextBoxPicker.Text = nvalue.ToString();
                    break;
                }
            }
            else
            if (DataGridView.EditingControl is PanelColorPicker)
            {
                ColorPickerc = DataGridView.EditingControl as PanelColorPicker;
                if (nvalue.IsNull)
                {
                    ColorPickerc.TextDisplayed = false;
                    ColorPickerc.Color         = Color.White;
                }
                else
                {
                    ColorPickerc.TextDisplayed = true;
                    ColorPickerc.Color         = GraphicUtils.ColorFromInteger(nvalue);
                }
            }
            else
            if (DataGridView.EditingControl is PanelImagePicker)
            {
                ImagePickerc      = DataGridView.EditingControl as PanelImagePicker;
                ImagePickerc.xrow = ((DataRowView)DataGridView.Rows[rowIndex].DataBoundItem).Row;
                if (nvalue.IsNull)
                {
                    ImagePickerc.MemStream = new System.IO.MemoryStream();
                }
                else
                {
                    ImagePickerc.MemStream = nvalue.GetStream();
                }
            }
            else
            if (DataGridView.EditingControl is CheckBoxPickerControl)
            {
                CheckBoxPicker = DataGridView.EditingControl as CheckBoxPickerControl;
                if (nvalue.IsNull)
                {
                    CheckBoxPicker.CheckState = CheckState.Indeterminate;
                }
                else
                {
                    CheckBoxPicker.Checked = (bool)nvalue;
                }
            }
            else
            if (DataGridView.EditingControl is EllipsisEditingControl)
            {
                EllipsisPicker      = DataGridView.EditingControl as EllipsisEditingControl;
                EllipsisPicker.Text = nvalue.ToString();
                switch (ntype)
                {
                case ObjectInspectorCellType.FontName:
                    EllipsisPicker.ButtonClick += ClickFontNameEvent;
                    break;
                }
            }
            else
            if (DataGridView.EditingControl is NumericUpDownPickerControl)
            {
                NumericPicker = DataGridView.EditingControl as NumericUpDownPickerControl;
                switch (ntype)
                {
                case ObjectInspectorCellType.Decimal:
                    NumericPicker.DataType = TextBoxDataType.Numeric;
                    break;

                case ObjectInspectorCellType.Integer:
                    NumericPicker.DataType = TextBoxDataType.Integer;
                    break;
                }
                if (nvalue.IsNull)
                {
                    NumericPicker.Text = "";
                }
                else
                {
                    switch (ntype)
                    {
                    case ObjectInspectorCellType.Decimal:
                        NumericPicker.Text = ((decimal)nvalue).ToString("##0.0000");
                        break;

                    case ObjectInspectorCellType.Integer:
                        NumericPicker.Text = nvalue.ToString();
                        break;
                    }
                }
            }
        }
        protected override void Paint(Graphics graphics,
                                      Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
                                      DataGridViewElementStates elementState, object value,
                                      object formattedValue, string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            //            formattedValue = null;
            bool    painted = false;
            Variant nvalue  = (Variant)GetColumnValue("VALUE", rowIndex);

            if (!nvalue.IsNull)
            {
                ObjectInspectorCellType celltype = (ObjectInspectorCellType)GetColumnValue("TYPEENUM", rowIndex);
                if (celltype == ObjectInspectorCellType.Image)
                {
                    nvalue = (Variant)GetColumnValue("VALUEBIN", rowIndex);
                }
                switch (celltype)
                {
                case ObjectInspectorCellType.DropDownList:
                case ObjectInspectorCellType.DropDown:
                    Strings list  = (Strings)GetColumnValue("VALUELIST", rowIndex);
                    int     index = -1;
                    if (nvalue.IsString())
                    {
                        index = list.IndexOf(nvalue);
                    }
                    else
                    {
                        index = nvalue;
                    }
                    if (index < list.Count)
                    {
                        if (index >= 0)
                        {
                            formattedValue = list[index];
                        }
                        else
                        {
                            formattedValue = "";
                        }
                    }
                    break;

                case ObjectInspectorCellType.Text:
                    break;

                case ObjectInspectorCellType.Decimal:
                    Decimal dvalue = nvalue;
                    formattedValue = dvalue.ToString("##,##0.000");
                    break;

                case ObjectInspectorCellType.Integer:
                    Decimal ivalue = nvalue;
                    formattedValue = ivalue.ToString("##,##0");
                    break;

                case ObjectInspectorCellType.Color:
                    Color c = GraphicUtils.ColorFromInteger(nvalue);
                    formattedValue      = c.Name;
                    cellStyle.BackColor = c;
                    cellStyle.ForeColor = GraphicUtils.GetInvertedBlackWhite(c);
                    break;

                case ObjectInspectorCellType.Image:
                    System.IO.MemoryStream memstream = nvalue.GetStream();
                    formattedValue = StringUtil.GetSizeAsString(memstream.Length);
                    break;

                case ObjectInspectorCellType.FontStyle:
                    formattedValue      = GraphicUtils.StringFontStyleFromInteger(nvalue);
                    cellStyle.BackColor = SystemColors.Info;
                    cellStyle.ForeColor = SystemColors.InfoText;
                    break;

                case ObjectInspectorCellType.Boolean:
                    bool        boolvalue = (bool)nvalue;
                    ButtonState nstate;
                    if (boolvalue)
                    {
                        nstate = ButtonState.Checked;
                    }
                    else
                    {
                        nstate = ButtonState.Normal;
                    }
                    base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, "", "",
                               "", cellStyle, advancedBorderStyle, paintParts);
                    // Make square cell Bounds
//                        int checkwidth=(int)Math.Round((double)cellStyle.Font.Size*(double)96/(double)72);
                    int checkwidth = 13;
                    int x1         = cellBounds.Left;
                    int y1         = cellBounds.Top;
                    int width1     = cellBounds.Width;
                    int height1    = cellBounds.Height;
                    if (height1 > width1)
                    {
                        y1      = height1 - (checkwidth / 2);
                        height1 = width1;
                    }
                    else
                    {
                        x1     = x1 + width1 / 2 - (checkwidth / 2);
                        y1     = y1 + (height1 - checkwidth) / 2;
                        width1 = height1;
                    }
                    Rectangle nbounds = new Rectangle(x1, y1, checkwidth, checkwidth);
                    ControlPaint.DrawCheckBox(graphics, nbounds, nstate);
                    painted = true;
                    break;
                }
            }
            if (!painted)
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue,
                           errorText, cellStyle, advancedBorderStyle, paintParts);
            }


            /*           Rectangle ColorBoxRect = new Rectangle();
             *         RectangleF TextBoxRect = new RectangleF();
             *         GetDisplayLayout(cellBounds, ref ColorBoxRect, ref TextBoxRect);
             *
             *         //// Draw the cell background, if specified.
             *         if ((paintParts & DataGridViewPaintParts.Background) ==
             *             DataGridViewPaintParts.Background)
             *         {
             *             SolidBrush cellBackground;
             *             if (value != null && value.GetType() == typeof(Color))
             *             {
             *                 cellBackground = new SolidBrush((Color)value);
             *             }
             *             else
             *             {
             *                 cellBackground = new SolidBrush(cellStyle.BackColor);
             *             }
             *             graphics.FillRectangle(cellBackground, ColorBoxRect);
             *             graphics.DrawRectangle(Pens.Black, ColorBoxRect);
             *             Color lclcolor = (Color)value;
             *             graphics.DrawString(lclcolor.Name.ToString(), cellStyle.Font, System.Drawing.Brushes.Black, TextBoxRect);
             *
             *             cellBackground.Dispose();
             *         }*/
        }
Example #6
0
        public static void PrintObject(object sh, MetaPage page, MetaObject obj, int dpix,
                                       int dpiy, SortedList rows, SortedList columns,
                                       string FontName, int FontSize, int rowinit, double Precision)
        {
            const int xlHAlignCenter = -4108;
            const int xlHAlignLeft   = -4131;
            const int xlHAlignRight  = -4152;
            string    atext;
            int       arow;
            int       acolumn;
            bool      isanumber;
            FontStyle astyle;
            Color     acolor;
            bool      isadate;

            string topstring  = ((double)obj.Top / Precision).ToString("0000000000");
            string leftstring = ((double)obj.Left / Precision).ToString("0000000000");

            arow    = rows.IndexOfKey(topstring) + 1 + rowinit;
            acolumn = columns.IndexOfKey(leftstring) + 1;
            if (acolumn < 1)
            {
                acolumn = 1;
            }
            if (arow < 1)
            {
                arow = 1;
            }
            object cells = sh.GetType().InvokeMember("Cells",
                                                     System.Reflection.BindingFlags.GetProperty, null, sh, null);

            object[] param2 = new object[2];
            param2[0] = arow;
            param2[1] = acolumn;
            object[] param1 = new object[1];
            object   cell   = cells.GetType().InvokeMember("Item",
                                                           System.Reflection.BindingFlags.GetProperty, null, cells, param2);

            switch (obj.MetaType)
            {
            case MetaObjectType.Text:
                MetaObjectText objt = (MetaObjectText)obj;
                atext = page.GetText(objt);

                // If it's a number
                bool assigned = false;
                isanumber = DoubleUtil.IsNumeric(atext, System.Globalization.NumberStyles.Any);
                if (isanumber)
                {
                    param1[0] = System.Convert.ToDouble(atext);
                    cell.GetType().InvokeMember("Value",
                                                System.Reflection.BindingFlags.SetProperty,
                                                null, cell, param1);
                    assigned = true;
                }
                else
                {
                    DateTime mydate;
                    isadate = DateUtil.IsDateTime(atext, out mydate);
                    if (isadate)
                    {
                        param1[0] = mydate;
                        cell.GetType().InvokeMember("Value",
                                                    System.Reflection.BindingFlags.SetProperty,
                                                    null, cell, param1);
                        assigned = true;
                    }
                    else
                    if (atext.Length > 0)
                    {
                        if (atext[0] == '=')
                        {
                            atext = "'" + atext;
                        }
                        param1[0] = atext;
                        cell.GetType().InvokeMember("Value",
                                                    System.Reflection.BindingFlags.SetProperty,
                                                    null, cell, param1);
                        assigned = true;
                    }
                }
                if (assigned)
                {
                    object shfont = cell.GetType().InvokeMember("Font",
                                                                System.Reflection.BindingFlags.GetProperty,
                                                                null, cell, null);
                    string nfontname = page.GetWFontNameText(objt);
                    if (FontName != nfontname)
                    {
                        param1[0] = nfontname;
                        shfont.GetType().InvokeMember("Name",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if (objt.FontSize != FontSize)
                    {
                        param1[0] = objt.FontSize;
                        shfont.GetType().InvokeMember("Size",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    acolor = GraphicUtils.ColorFromInteger(objt.FontColor);
                    if (acolor.ToArgb() != Color.Black.ToArgb())
                    {
                        param1[0] = objt.FontColor;
                        shfont.GetType().InvokeMember("Color",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    astyle = GraphicUtils.FontStyleFromInteger(objt.FontStyle);
                    if ((astyle & FontStyle.Italic) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Italic",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if ((astyle & FontStyle.Bold) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Bold",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if ((astyle & FontStyle.Underline) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Underline",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if ((astyle & FontStyle.Strikeout) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Strikethrough",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    // Font rotation not possible
                    if ((objt.Alignment & MetaFile.AlignmentFlags_AlignHCenter) > 0)
                    {
                        param1[0] = xlHAlignCenter;
                        cell.GetType().InvokeMember("HorizontalAlignment",
                                                    System.Reflection.BindingFlags.SetProperty,
                                                    null, cell, param1);
                    }
                    // Multiline not supported
                    //    if (obj.AlignMent AND AlignmentFlags_SingleLine)=0 then
                    //     sh.Cells.item[arow,acolumn].Multiline:=true;
                    if ((objt.Alignment & MetaFile.AlignmentFlags_AlignLeft) > 0)
                    {
                        if (isanumber)
                        {
                            param1[0] = xlHAlignLeft;
                            cell.GetType().InvokeMember("HorizontalAlignment",
                                                        System.Reflection.BindingFlags.SetProperty,
                                                        null, cell, param1);
                        }
                    }
                    if ((objt.Alignment & MetaFile.AlignmentFlags_AlignRight) > 0)
                    {
                        if (!isanumber)
                        {
                            param1[0] = xlHAlignRight;
                            cell.GetType().InvokeMember("HorizontalAlignment",
                                                        System.Reflection.BindingFlags.SetProperty,
                                                        null, cell, param1);
                        }
                    }
                    // Word wrap not supported
                    //    if obj.WordWrap then
                    //     sh.Cells.item[arow,acolumn].WordWrap:=True;
                    //    if Not obj.CutText then
                    //     aalign:=aalign or DT_NOCLIP;
                    //    if obj.RightToLeft then
                    //     aalign:=aalign or DT_RTLREADING;
                    // In office 97, not supported
                    //    if Not obj.Transparent then
                    //     sh.Cells.Item[arow,acolumn].Color:=CLXColorToVCLColor(obj.BackColor);
                }
                break;
            }
        }