コード例 #1
0
ファイル: rpmdfgrid.cs プロジェクト: chtheis/reportman.net
        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);
        }
コード例 #2
0
        private DataTable FindDataTable(string tablename, DesignerInterface obj)
        {
            // Table name differen for different secions types
            if (obj.ReportItemObject is Section)
            {
                Section nsec = (Section)obj.ReportItemObject;
                tablename = tablename + nsec.SectionType.ToString();
            }
            Reportman.Drawing.Strings pnames = new Strings();
            DataTable properties             = data.Tables[tablename];

            bool assignproperties = true;

            if (properties == null)
            {
                Reportman.Reporting.Variants pvalues = null;
                if (obj.SelectionList.Count == 1)
                {
                    assignproperties = false;
                    pvalues          = new Variants();
                }
                properties = new DataTable(tablename);
                properties.Columns.Add("NAME", System.Type.GetType("System.String"));
                properties.Columns.Add("TYPE", System.Type.GetType("System.String"));
                properties.Columns.Add("TYPEENUM", System.Type.GetType("System.Int32"));
                properties.Columns.Add("VALUE", System.Type.GetType("System.Object"));
                properties.Columns.Add("VALUELIST", System.Type.GetType("System.Object"));
                properties.Columns.Add("INTERFACE", System.Type.GetType("System.Object"));
                properties.Columns.Add("VALUEBIN", System.Type.GetType("System.Object"));
                DataColumn acol = properties.Columns.Add("TWIPS", System.Type.GetType("System.Boolean"));
                acol.DefaultValue = false;

                properties.Constraints.Add("IPRIMNAME", properties.Columns["NAME"], true);
                Reportman.Drawing.Strings ptypes = new Strings();
                Reportman.Drawing.Strings lhints = new Strings();
                Reportman.Drawing.Strings lcat   = new Strings();
                obj.GetProperties(pnames, ptypes, pvalues, lhints, lcat);
                properties.Rows.Clear();
                for (int i = 0; i < pnames.Count; i++)
                {
                    bool    isbinary = false;
                    DataRow nrow     = properties.NewRow();
                    nrow["NAME"]      = pnames[i];
                    nrow["TYPE"]      = ptypes[i];
                    nrow["INTERFACE"] = obj;
                    nrow["VALUELIST"] = DBNull.Value;
                    nrow["TYPEENUM"]  = System.Convert.ToInt32(ObjectInspectorCellType.Text);
                    if (ptypes[i] == Translator.TranslateStr(571))
                    {
                        nrow["TYPEENUM"] = System.Convert.ToInt32(ObjectInspectorCellType.Expression);
                    }
                    else
                    if (ptypes[i] == Translator.TranslateStr(556))
                    {
                        nrow["TYPEENUM"] = System.Convert.ToInt32(ObjectInspectorCellType.Decimal);
                        nrow["TWIPS"]    = true;
                    }
                    else
                    if (ptypes[i] == Translator.TranslateStr(569))
                    {
                        nrow["TYPEENUM"] = System.Convert.ToInt32(ObjectInspectorCellType.DropDownList);
                        Strings alist = new Strings();
                        obj.GetPropertyValues(pnames[i], alist);
                        nrow["VALUELIST"] = alist;
                    }
                    else if (ptypes[i] == Translator.TranslateStr(961))
                    {
                        nrow["TYPEENUM"] = System.Convert.ToInt32(ObjectInspectorCellType.DropDown);
                        Strings alist = new Strings();
                        obj.GetPropertyValues(pnames[i], alist);
                        nrow["VALUELIST"] = alist;
                    }
                    else
                    if (ptypes[i] == Translator.TranslateStr(568))
                    {
                        nrow["TYPEENUM"] = System.Convert.ToInt32(ObjectInspectorCellType.Boolean);
                    }
                    else
                    if (ptypes[i] == Translator.TranslateStr(558))
                    {
                        nrow["TYPEENUM"] = System.Convert.ToInt32(ObjectInspectorCellType.Color);
                    }
                    else
                    if (ptypes[i] == Translator.TranslateStr(639))
                    {
                        isbinary         = true;
                        nrow["TYPEENUM"] = System.Convert.ToInt32(ObjectInspectorCellType.Image);
                    }
                    else
                    if (ptypes[i] == Translator.TranslateStr(560))
                    {
                        nrow["TYPEENUM"] = System.Convert.ToInt32(ObjectInspectorCellType.FontName);
                    }
                    else
                    if (ptypes[i] == Translator.TranslateStr(566))
                    {
                        nrow["TYPEENUM"] = System.Convert.ToInt32(ObjectInspectorCellType.FontStyle);
                    }
                    else
                    // Font size
                    if (ptypes[i] == Translator.TranslateStr(559))
                    {
                        nrow["TYPEENUM"] = System.Convert.ToInt32(ObjectInspectorCellType.Integer);
                    }
                    if (pvalues != null)
                    {
                        if (isbinary)
                        {
                            nrow["VALUEBIN"] = pvalues[i];
                            System.IO.MemoryStream mstream = pvalues[i].GetStream();
                            nrow["VALUE"] = StringUtil.GetSizeAsString(mstream.Length);
                        }
                        else
                        {
                            if ((bool)nrow["TWIPS"])
                            {
                                nrow["VALUE"] = Twips.UnitsFromTwips(pvalues[i]);
                            }
                            else
                            {
                                nrow["VALUE"] = pvalues[i];
                            }
                        }
                    }
                    properties.Rows.Add(nrow);
                }
                properties.RowChanging += rowchangeevent;
                data.Tables.Add(properties);
            }
            if (assignproperties)
            {
                properties.RowChanging -= rowchangeevent;
                for (int i = 0; i < properties.Rows.Count; i++)
                {
                    DataRow nrow   = properties.Rows[i];
                    Variant nvalue = obj.GetPropertyMulti(nrow["NAME"].ToString());
                    if (nvalue.VarType == VariantType.Binary)
                    {
                        nrow["VALUEBIN"] = nvalue;
                        nrow["VALUE"]    = StringUtil.GetSizeAsString(nvalue.GetStream().Length);
                    }
                    else
                    {
                        if (nvalue.IsNull)
                        {
                            nrow["VALUE"] = DBNull.Value;
                        }
                        else
                        {
                            if ((bool)nrow["TWIPS"])
                            {
                                nrow["VALUE"] = Twips.UnitsFromTwips(nvalue);
                            }
                            else
                            {
                                nrow["VALUE"] = nvalue;
                            }
                            if (nrow["TYPE"].ToString() == Translator.TranslateStr(961))
                            {
                                Strings alist = new Strings();
                                obj.GetPropertyValues(nrow["NAME"].ToString(), alist);
                                nrow["VALUELIST"] = alist;
                            }
                        }
                    }
                }
                properties.RowChanging += rowchangeevent;
            }
            return(properties);
        }
コード例 #3
0
        private void RowChange(object sender, DataRowChangeEventArgs args)
        {
            bool executeonpropchange = false;

            if (args.Row["VALUE"] != DBNull.Value)
            {
                if (CurrentInterface != null)
                {
                    if ((bool)args.Row["TWIPS"])
                    {
                        CurrentInterface.SetPropertyMulti(args.Row["NAME"].ToString(), Twips.TwipsFromUnits(Variant.VariantFromObject(args.Row["VALUE"])));
                        executeonpropchange = true;
                    }
                    else
                    {
                        bool isbinary = false;
                        if ((int)args.Row["TYPEENUM"] == System.Convert.ToInt32(ObjectInspectorCellType.Image))
                        {
                            isbinary = true;
                        }
                        if (!isbinary)
                        {
                            CurrentInterface.SetPropertyMulti(args.Row["NAME"].ToString(), Variant.VariantFromObject(args.Row["VALUE"]));
                            executeonpropchange = true;
                        }
                    }
                }
            }
            if (args.Row["VALUEBIN"] != DBNull.Value)
            {
                if (CurrentInterface != null)
                {
                    bool isbinary = false;
                    if ((int)args.Row["TYPEENUM"] == System.Convert.ToInt32(ObjectInspectorCellType.Image))
                    {
                        isbinary = true;
                    }
                    if (isbinary)
                    {
                        CurrentInterface.SetPropertyMulti(args.Row["NAME"].ToString(), Variant.VariantFromObject(args.Row["VALUEBIN"]));
                        executeonpropchange = true;
                    }
                }
            }
            if ((executeonpropchange) && (OnPropertyChange != null))
            {
                OnPropertyChange(sender, args);
            }
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: rpmdresize.cs プロジェクト: chtheis/reportman.net
        private void DifProc(RuntimeCapture sender, int difx, int dify, bool finish, bool start, bool mouseup)
        {
            if (start)
            {
                return;
            }
            int  newleft     = 0;
            int  newtop      = 0;
            int  newwidth    = 0;
            int  newheight   = 0;
            bool dosetbounds = true;
            bool alignleft   = false;
            bool aligntop    = false;
            bool alignbottom = false;
            bool alignright  = false;


            if (sender == Q1)
            {
                newleft   = FLeft + difx;
                newwidth  = FWidth - difx;
                newtop    = FTop + dify;
                newheight = FHeight - dify;
                alignleft = true;
                aligntop  = true;
            }
            if (sender == Q2)
            {
                newleft    = FLeft;
                newtop     = FTop + dify;
                newwidth   = FWidth + difx;
                newheight  = FHeight - dify;
                aligntop   = true;
                alignright = true;
            }
            if (sender == Q3)
            {
                newleft     = FLeft;
                newtop      = FTop;
                newwidth    = FWidth + difx;
                newheight   = FHeight + dify;
                alignright  = true;
                alignbottom = true;
            }
            if (sender == Q4)
            {
                newleft     = FLeft + difx;
                newtop      = FTop;
                newwidth    = FWidth - difx;
                newheight   = FHeight + dify;
                alignleft   = true;
                alignbottom = true;
            }
            if (newwidth < 0)
            {
                dosetbounds = false;
                newleft     = newleft - newwidth;
                newwidth    = -newwidth;
            }
            if (newheight < 0)
            {
                dosetbounds = false;
                newtop      = newtop + newheight;
                newheight   = -newheight;
            }
            if (dosetbounds)
            {
                // Align to grid
                if (GridEnabled)
                {
                    if (alignleft)
                    {
                        newleft = newleft - GridOffsetX;
                        int nleft = Twips.AlignToGridPixels(newleft, GridWidth, GridHeight, GridScale);
                        newwidth = newwidth + newleft - nleft;
                        newleft  = nleft;
                        newleft  = newleft + GridOffsetX;
                    }
                    if (aligntop)
                    {
                        newtop = newtop - GridOffsetY;
                        int ntop = Twips.AlignToGridPixels(newtop, GridWidth, GridHeight, GridScale);
                        newheight = newheight + newtop - ntop;
                        newtop    = ntop;
                        newtop    = newtop + GridOffsetY;
                    }
                    if (alignright)
                    {
                        newwidth = newwidth - GridOffsetX + newleft;
                        newwidth = Twips.AlignToGridPixels(newwidth, GridWidth, GridHeight, GridScale);
                        newwidth = newwidth + GridOffsetX - newleft;
                    }
                    if (alignbottom)
                    {
                        newheight = newheight - GridOffsetY + newtop;
                        newheight = Twips.AlignToGridPixels(newheight, GridWidth, GridHeight, GridScale);
                        newheight = newheight + GridOffsetY - newtop;
                    }
                }
                SetBounds(newleft, newtop, newwidth, newheight, finish);
                if (mouseup)
                {
                    if (OnNewBounds != null)
                    {
                        OnNewBounds(new Rectangle(newleft, newtop, newwidth, newheight));
                    }
                }
            }
        }