示例#1
0
 public BoxWidget(Control control, int margin)
     : base()
 {
     Control = control;
     Screen = CreateScreen(1, 1);
     LayoutData = new LayoutData(Control);
     Margin = margin;
     LayoutData.X = Offset;
     LayoutData.Y = Offset;
 }
示例#2
0
 public LayoutData(LayoutData src)
 {
     this.ClientRectangle = src.ClientRectangle;
     this.TopLeftHeader = src.TopLeftHeader;
     this.ColumnHeaders = src.ColumnHeaders;
     this.RowHeaders = src.RowHeaders;
     this.Inside = src.Inside;
     this.Data = src.Data;
     this.ResizeBoxRect = src.ResizeBoxRect;
     this.ColumnHeadersVisible = src.ColumnHeadersVisible;
     this.RowHeadersVisible = src.RowHeadersVisible;
 }
        protected void DrawCheckFlat(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, Color checkBorder, ColorData colors) {
            Rectangle bounds = layout.checkBounds;
            // Removed subtracting one for Width and Height. In Everett we needed to do this,
            // since we were using GDI+ to draw the border. Now that we are using GDI,
            // we should not do before drawing the border.

            if (!layout.options.everettButtonCompat) {
                bounds.Width--;
                bounds.Height--;                
            }
            using (WindowsGraphics wg = WindowsGraphics.FromGraphics( e.Graphics )) {
                using(WindowsPen pen = new WindowsPen(wg.DeviceContext, checkBorder)){
                    wg.DrawRectangle(pen, bounds);
                }

                // Now subtract, since the rest of the code is like Everett.
                if (layout.options.everettButtonCompat) {
                    bounds.Width--;
                    bounds.Height--;                
                }                
                bounds.Inflate(-1, -1);
            }
            if (Control.CheckState == CheckState.Indeterminate) {
                bounds.Width++;
                bounds.Height++;
                DrawDitheredFill(e.Graphics, colors.buttonFace, checkBackground, bounds);
            }
            else {
                using( WindowsGraphics wg = WindowsGraphics.FromGraphics( e.Graphics )) {
                    using (WindowsBrush brush = new WindowsSolidBrush(wg.DeviceContext, checkBackground)) {
                        // Even though we are using GDI here as opposed to GDI+ in Everett, we still need to add 1.
                        bounds.Width++;
                        bounds.Height++;
                        wg.FillRectangle(brush, bounds);
                    }
                }
            }
            DrawCheckOnly(e, layout, colors, checkColor, checkBackground, true);
    
        }
示例#4
0
        protected override void OnInitialized()
        {
            base.OnInitialized();

            LayoutData.Title = "Custom link";
            LayoutData.Info  = "Creating your own custom links is very easy!";
            LayoutData.DataChanged();

            _diagramManager.RegisterModelComponent <ThickLink, ThickLinkWidget>();
            // Also usable: _diagramManager.Options.Links.DefaultLinkComponent = typeof(ThickLink);

            var node1 = NewNode(50, 50);
            var node2 = NewNode(300, 300);
            var node3 = NewNode(500, 50);

            _diagramManager.AddNode(node1);
            _diagramManager.AddNode(node2);
            _diagramManager.AddNode(node3);

            _diagramManager.AddLink <ThickLink>(node1.GetPort(PortAlignment.Right), node2.GetPort(PortAlignment.Left));
            _diagramManager.AddLink <ThickLink>(node2.GetPort(PortAlignment.Right), node3.GetPort(PortAlignment.Left));
        }
示例#5
0
        public int CountRings(LayoutData layout, MultiFileIndexer <Block> Blocks, IEnumerable <ObjectEntry> objects)
        {
            int count = 0;

            int[] blkRings = new int[Blocks.Count];

            for (int blk = 0; blk < Blocks.Count; blk++)
            {
                blkRings[blk] = 0;
                for (int ty = 0; ty < 4; ty++)
                {
                    for (int tx = 0; tx < 4; tx++)
                    {
                        if (Blocks[blk].Tiles[tx, ty].Tile == 0x0001)
                        {
                            blkRings[blk]++;
                        }
                    }
                }
            }
            for (int x = 0; x < layout.BGLayout.GetUpperBound(0); x++)
            {
                for (int y = 0; y < layout.BGLayout.GetUpperBound(1); y++)
                {
                    count += blkRings[layout.BGLayout[x, y]];
                    count += blkRings[layout.FGLayout[x, y]];
                }
            }

            if (objects != null)
            {
                // TODO: make this not hardcoded
                // Sky Chase Ring
                count += objects.Count(a => a.ID == 0x67);
                // Ring Item
                count += objects.Count(a => a.ID == 0x0C && a.SubType == 0x02) * 10;
            }
            return(count);
        }
        static TableLayout()
        {
            // set up port candidates for edges (edges should be attached to the left/right side of the corresponding node
            var candidates = new List <PortCandidate>
            {
                PortCandidate.CreateCandidate(PortDirections.West),
                PortCandidate.CreateCandidate(PortDirections.East)
            };

            // configure layout algorithms
            var rowLayout = new RowLayout(); // used for laying out the nodes (rows) within the group nodes (tables)

            layoutData = new RecursiveGroupLayoutData
            {
                SourcePortCandidates = { Constant = candidates },
                TargetPortCandidates = { Constant = candidates },

                // map each group node to its corresponding layout algorithm;
                // in this case each group node shall be laid out using the RowLayout
                GroupNodeLayouts = { Constant = rowLayout }
            };
        }
示例#7
0
        internal override void PaintDown(PaintEventArgs e, CheckState state)
        {
            ColorData  colors = PaintPopupRender(e).Calculate();
            LayoutData layout = PaintPopupLayout(e, false, SystemInformation.HighContrast ? 2 : 1).Layout();

            Rectangle r = Control.ClientRectangle;

            PaintButtonBackground(e, r, null);
            if (Control.IsDefault)
            {
                r.Inflate(-1, -1);
            }

            r.Inflate(-1, -1);

            PaintImage(e, layout);
            PaintField(e, layout, colors, colors.WindowText, true);

            r.Inflate(1, 1);
            DrawDefaultBorder(e, r, colors.Options.HighContrast ? colors.WindowText : colors.WindowFrame, Control.IsDefault);
            ControlPaint.DrawBorderSimple(e, r, colors.Options.HighContrast ? colors.WindowText : colors.ButtonShadow);
        }
示例#8
0
        void DrawCheckOnly(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, bool disabledColors)
        {
            // check
            //
            if (Checked)
            {
                if (!Enabled && disabledColors)
                {
                    checkColor = SystemColors.ControlDark;
                }

                using (Brush brush = new SolidBrush(checkColor)) {
                    // circle drawing doesn't work at this size
                    int offset = 5;

                    Rectangle vCross = new Rectangle(layout.checkBounds.X + offset, layout.checkBounds.Y + offset - 1, 2, 4);
                    e.Graphics.FillRectangle(brush, vCross);
                    Rectangle hCross = new Rectangle(layout.checkBounds.X + offset - 1, layout.checkBounds.Y + offset, 4, 2);
                    e.Graphics.FillRectangle(brush, hCross);
                }
            }
        }
示例#9
0
        /// <include file='doc\CheckBox.uex' path='docs/doc[@for="CheckBox.PaintPopupDown"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    Paints a popup checkbox in the down state.
        /// </devdoc>
        internal override void PaintPopupDown(PaintEventArgs e, CheckState state)
        {
            System.Drawing.Graphics g = e.Graphics;
            if (appearance == Appearance.Button)
            {
                base.PaintPopupDown(e, Checked ? CheckState.Checked : CheckState.Unchecked);
            }
            else
            {
                ColorData  colors = PaintPopupRender(e.Graphics).Calculate();
                LayoutData layout = PaintFlatLayout(e).Layout();

                PaintButtonBackground(e, ClientRectangle, null);

                PaintImage(e, layout);

                DrawCheckBackground3DLite(e, layout.checkBounds, colors.windowText, colors.highlight, colors, true);
                DrawCheckOnly(e, layout, colors.buttonShadow, colors.highlight, true);

                PaintField(e, layout, colors, colors.windowText, true);
            }
        }
        protected void DrawCheckBox(PaintEventArgs e, LayoutData layout)
        {
            Graphics g = e.Graphics;

            Rectangle check = layout.checkBounds;

            if (!Application.RenderWithVisualStyles)
            {
                check.X--;      // compensate for Windows drawing slightly offset to right
            }

            ButtonState style = GetState();

            if (Application.RenderWithVisualStyles)
            {
                RadioButtonRenderer.DrawRadioButton(g, new Point(check.Left, check.Top), RadioButtonRenderer.ConvertFromButtonState(style, Control.MouseIsOver));
            }
            else
            {
                ControlPaint.DrawRadioButton(g, check, style);
            }
        }
示例#11
0
        internal override void PaintUp(PaintEventArgs e, CheckState state)
        {
            if (Control.Appearance == Appearance.Button)
            {
                ButtonAdapter.PaintUp(e, Control.CheckState);
            }
            else
            {
                ColorData  colors = PaintRender(e.Graphics).Calculate();
                LayoutData layout = Layout(e).Layout();
                PaintButtonBackground(e, Control.ClientRectangle, null);

                //minor adjustment to make sure the appearance is exactly the same as Win32 app.
                int focusRectFixup = layout.focus.X & 0x1; // if it's odd, subtract one pixel for fixup.
                if (!Application.RenderWithVisualStyles)
                {
                    focusRectFixup = 1 - focusRectFixup;
                }

                if (!layout.options.everettButtonCompat)
                {
                    layout.textBounds.Offset(-1, -1);
                }
                layout.imageBounds.Offset(-1, -1);
                layout.focus.Offset(-(focusRectFixup + 1), -2);
                layout.focus.Width = layout.textBounds.Width + layout.imageBounds.Width - 1;
                layout.focus.Intersect(layout.textBounds);

                if (layout.options.textAlign != LayoutUtils.AnyLeft && layout.options.useCompatibleTextRendering && layout.options.font.Italic)
                {
                    // fixup for GDI+ text rendering.  VSW#515164
                    layout.focus.Width += 2;
                }

                PaintImage(e, layout);
                DrawCheckBox(e, layout);
                PaintField(e, layout, colors, colors.windowText, true);
            }
        }
示例#12
0
        internal override void PaintDown(PaintEventArgs e, CheckState state) {
            if (Control.Appearance == Appearance.Button) {
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control);
                adapter.PaintDown(e, Control.CheckState);
            }
            else {
                System.Drawing.Graphics g = e.Graphics;
                ColorData colors = PaintPopupRender(e.Graphics).Calculate();
                LayoutData layout = PaintPopupLayout(e, true).Layout();

                Region original = e.Graphics.Clip;
                PaintButtonBackground(e, Control.ClientRectangle, null);

                PaintImage(e, layout);
                
                DrawCheckBackground(e, layout.checkBounds, colors.windowText, colors.buttonFace, true, colors);
                DrawPopupBorder(g, layout.checkBounds, colors);
                DrawCheckOnly(e, layout, colors, colors.windowText, colors.buttonFace, true);

                PaintField(e, layout, colors, colors.windowText, true);
            }
        }
示例#13
0
        /// <summary>
        /// 渲染文本和图片
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderTextAndImage(Rectangle rect)
        {
            this.m_TextImageRect = rect;

            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_TextImageRect) || ((this.m_Text == null || this.m_Text.Length <= 0) && this.m_Image == null))
            {
                return;
            }

            using (LayoutData layout = new LayoutData())
            {
                layout.Graphics = this.m_Graphics;

                layout.ClientRectangle   = this.CurrentTextImageClientRect;
                layout.Padding           = this.m_Padding;
                layout.TextImageRelation = this.m_TextImageRelation;
                layout.RightToLeft       = this.m_RightToLeft;

                layout.ImageSize   = (this.CurrentImage == null ? Size.Empty : this.m_ImageSize);
                layout.ImageAlign  = this.m_ImageAlign;
                layout.ImageOffset = this.m_ImageOffset;

                layout.Text       = this.m_Text;
                layout.Font       = this.m_Font;
                layout.TextAlign  = this.m_TextAlign;
                layout.TextOffset = this.m_TextOffset;

                if (this.CurrentImage != null)
                {
                    this.RenderImageCore(layout);
                }

                if (this.Text != null && this.Text.Length > 0)
                {
                    this.RenderTextCore(layout);
                }
            }
        }
示例#14
0
        internal override void PaintOver(PaintEventArgs e, CheckState state)
        {
            if (Control.Appearance == Appearance.Button)
            {
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control);
                adapter.PaintOver(e, Control.CheckState);
            }
            else
            {
                ColorData  colors = PaintPopupRender(e).Calculate();
                LayoutData layout = PaintPopupLayout(show3D: true).Layout();

                Region original = e.Graphics.Clip;
                PaintButtonBackground(e, Control.ClientRectangle, null);

                PaintImage(e, layout);

                DrawCheckBackground(
                    e,
                    layout.checkBounds,
                    colors.windowText,
                    colors.options.HighContrast ? colors.buttonFace : colors.highlight,
                    disabledColors: true,
                    colors);

                DrawPopupBorder(e, layout.checkBounds, colors);
                DrawCheckOnly(e, layout, colors, colors.windowText, colors.highlight);

                if (!string.IsNullOrEmpty(Control.Text))
                {
                    e.Graphics.Clip = original;
                    e.Graphics.ExcludeClip(layout.checkArea);
                }

                AdjustFocusRectangle(layout);
                PaintField(e, layout, colors, colors.windowText, true);
            }
        }
示例#15
0
        internal override void PaintOver(PaintEventArgs e, CheckState state)
        {
            System.Drawing.Graphics g = e.Graphics;
            if (Control.Appearance == Appearance.Button)
            {
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control);
                adapter.PaintOver(e, Control.Checked ? CheckState.Checked : CheckState.Unchecked);
            }
            else
            {
                ColorData  colors = PaintPopupRender(e.Graphics).Calculate();
                LayoutData layout = Layout(e).Layout();

                PaintButtonBackground(e, Control.ClientRectangle, null);

                PaintImage(e, layout);

                DrawCheckBackground3DLite(e, layout.checkBounds, colors.windowText, colors.options.highContrast ? colors.buttonFace : colors.highlight, colors, true);
                DrawCheckOnly(e, layout, colors.windowText, colors.highlight, true);

                PaintField(e, layout, colors, colors.windowText, true);
            }
        }
示例#16
0
        internal override void PaintDown(PaintEventArgs e, CheckState state)
        {
            if (Control.Appearance == Appearance.Button)
            {
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control);
                adapter.PaintDown(e, Control.Checked ? CheckState.Checked : CheckState.Unchecked);
            }
            else
            {
                ColorData  colors = PaintPopupRender(e).Calculate();
                LayoutData layout = Layout(e).Layout();

                PaintButtonBackground(e, Control.ClientRectangle, null);

                PaintImage(e, layout);

                DrawCheckBackground3DLite(e, layout.CheckBounds, colors.Highlight, colors, true);
                DrawCheckOnly(e, layout, colors.ButtonShadow, colors.Highlight, true);

                AdjustFocusRectangle(layout);
                PaintField(e, layout, colors, colors.WindowText, true);
            }
        }
示例#17
0
        public override bool Layout(object container, LayoutEventArgs layoutEventArgs)
        {
            Control parent = container as Control;

            if (parent == null)
            {
                return(base.Layout(container, layoutEventArgs));
            }

            IList <Control> childControls = GetVisibleChildControls(parent).ToList();

            if (childControls.Count == 0)
            {
                return(base.Layout(container, layoutEventArgs));
            }


            Rectangle parentDisplayRectangle = parent.DisplayRectangle;
            Point     nextControlLocation    = parentDisplayRectangle.Location;

            LayoutData layoutData = GetLayoutData(childControls, parentDisplayRectangle);

            nextControlLocation.Offset(0, layoutData.LargestTopMargin);

            foreach (Control childControl in childControls)
            {
                nextControlLocation.Offset(childControl.Margin.Left, 0);

                childControl.Height   = layoutData.ChildHeight;
                childControl.Width    = layoutData.ChildWidth;
                childControl.Location = nextControlLocation;

                nextControlLocation.Offset(childControl.Margin.Right + layoutData.ChildWidth, 0);
            }

            return(false);
        }
示例#18
0
        public MyImage()
        {
            StretchModel.Add(Stretch.Fill);
            StretchModel.Add(Stretch.Uniform);
            StretchModel.Add(Stretch.None);
            //StretchModel.Add(Stretch.UniformToFill);


            rotateTransform            = new RotateTransform();
            layoutData                 = new LayoutData();
            layoutData.tag             = "Image";
            layoutData.text            = "";
            layoutData.imageSwitch     = 0;
            layoutData.stretchModel    = 0;
            layoutData.sceneTime       = 0;
            layoutData.backgroundColor = 0;
            layoutData.textSize        = 0;
            layoutData.textColor       = 0;
            layoutData.textBackground  = 0;
            border = new Border();
            image  = new Image();
            BitmapImage bi3 = new BitmapImage();

            bi3.BeginInit();
            bi3.UriSource = new Uri("pack://Application:,,,/Images/Image.png", UriKind.Absolute);
            bi3.EndInit();
            image.Source      = bi3;
            image.Stretch     = Stretch.Fill;
            this.Width        = this.MinWidth;
            this.Height       = this.MinHeight;
            this.image.Width  = this.Width;
            this.image.Height = this.Height;
            this.border.Child = image;
            this.Tag          = "Image";
            this.AddChild(this.border);
            AddHandler(FrameworkElement.MouseDownEvent, new MouseButtonEventHandler(Control_MouseDown), true);
        }
示例#19
0
        /// <include file='doc\CheckBox.uex' path='docs/doc[@for="CheckBox.PaintPopupUp"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    Paints a popup checkbox in the up state.
        /// </devdoc>
        internal override void PaintPopupUp(PaintEventArgs e, CheckState state)
        {
            if (appearance == Appearance.Button)
            {
                base.PaintPopupUp(e, CheckState);
            }
            else
            {
                System.Drawing.Graphics g = e.Graphics;
                ColorData  colors         = PaintPopupRender(e.Graphics).Calculate();
                LayoutData layout         = PaintPopupLayout(e, false).Layout();

                Region original = e.Graphics.Clip;
                PaintButtonBackground(e, ClientRectangle, null);

                PaintImage(e, layout);

                DrawCheckBackground(e, layout.checkBounds, colors.windowText, colors.options.highContrast ? colors.buttonFace : colors.highlight, true, colors);
                DrawFlatBorder(e.Graphics, layout.checkBounds, colors.buttonShadow);
                DrawCheckOnly(e, layout, colors, colors.windowText, colors.highlight, true);

                PaintField(e, layout, colors, colors.windowText, true);
            }
        }
示例#20
0
        internal override void PaintDown(PaintEventArgs e, CheckState state)
        {
            if (Control.Appearance == Appearance.Button)
            {
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control);
                adapter.PaintDown(e, Control.CheckState);
            }
            else
            {
                ColorData  colors = PaintPopupRender(e).Calculate();
                LayoutData layout = PaintPopupLayout(show3D: true).Layout();

                PaintButtonBackground(e, Control.ClientRectangle, null);

                PaintImage(e, layout);

                DrawCheckBackground(e, layout.checkBounds, colors.buttonFace, true, colors);
                DrawPopupBorder(e, layout.checkBounds, colors);
                DrawCheckOnly(e, layout, colors, colors.windowText);

                AdjustFocusRectangle(layout);
                PaintField(e, layout, colors, colors.windowText, true);
            }
        }
示例#21
0
        protected override void LayoutChildren(double x, double y, double width, double height)
        {
            LayoutData layoutData = GetLayoutData(width, height);

            if (layoutData.VisibleChildCount == 0)
            {
                return;
            }

            double xChild = x;
            double yChild = y;
            int    row    = 0;
            int    column = 0;

            foreach (View child in Children)
            {
                if (!child.IsVisible)
                {
                    continue;
                }

                LayoutChildIntoBoundingRegion(child, new Rectangle(new Point(xChild, yChild), layoutData.CellSize));

                if (++column == layoutData.Columns)
                {
                    column = 0;
                    row++;
                    xChild  = x;
                    yChild += RowSpacing + layoutData.CellSize.Height;
                }
                else
                {
                    xChild += ColumnSpacing + layoutData.CellSize.Width;
                }
            }
        }
示例#22
0
        internal override void PaintDown(PaintEventArgs e, CheckState state)
        {
            ColorData  colors = PaintPopupRender(e.Graphics).Calculate();
            LayoutData layout = PaintPopupLayout(e, false, SystemInformation.HighContrast ? 2 : 1).Layout();

            Graphics g = e.Graphics;
            //Region original = g.Clip;

            Rectangle r = Control.ClientRectangle;

            PaintButtonBackground(e, r, null);
            if (Control.IsDefault)
            {
                r.Inflate(-1, -1);
            }
            r.Inflate(-1, -1);

            PaintImage(e, layout);
            PaintField(e, layout, colors, colors.windowText, true);

            r.Inflate(1, 1);
            DrawDefaultBorder(g, r, colors.options.highContrast ? colors.windowText : colors.windowFrame, Control.IsDefault);
            ControlPaint.DrawBorder(g, r, colors.options.highContrast ? colors.windowText : colors.buttonShadow, ButtonBorderStyle.Solid);
        }
示例#23
0
        public static void RenameLayout(LayoutData layout, string newName)
        {
            if (layout != null)
            {
                LayoutData existing = FindLayout(newName);
                if (existing == null)
                {
                    Log.InfoFormat("Renaming layout: {0} -> {1}", layout.Name, newName);
                    // rename layout and file
                    string fileOld = layout.FilePath;
                    string fileNew = Path.Combine(Path.GetDirectoryName(layout.FilePath), newName) + ".xml";
                    File.Move(fileOld, fileNew);
                    layout.Name     = newName;
                    layout.FilePath = fileNew;

                    // Notify
                    layouts.ResetItem(layouts.IndexOf(layout));
                }
                else
                {
                    throw new ArgumentException("Layout with the same name exists: " + newName);
                }
            }
        }
        protected void DrawCheckOnly(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, bool disabledColors)
        {
            if (!Control.Checked)
            {
                return;
            }

            if (!Control.Enabled && disabledColors)
            {
                checkColor = SystemColors.ControlDark;
            }

            double scale = GetDpiScaleRatio();

            using var paintScope = new PaintEventHdcScope(e);
            Gdi32.HDC hdc = paintScope.HDC;
            using var brush = new Gdi32.CreateBrushScope(checkColor);

            // Circle drawing doesn't work at this size
            int offset = 5;

            Rectangle vCross = new Rectangle(
                layout.checkBounds.X + GetScaledNumber(offset, scale),
                layout.checkBounds.Y + GetScaledNumber(offset - 1, scale),
                GetScaledNumber(2, scale),
                GetScaledNumber(4, scale));

            hdc.FillRectangle(vCross, brush);

            Rectangle hCross = new Rectangle(
                layout.checkBounds.X + GetScaledNumber(offset - 1, scale),
                layout.checkBounds.Y + GetScaledNumber(offset, scale),
                GetScaledNumber(4, scale), GetScaledNumber(2, scale));

            hdc.FillRectangle(hCross, brush);
        }
示例#25
0
        protected void DrawCheckOnly(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, bool disabledColors)
        {
            // check
            //
            if (Control.Checked)
            {
                if (!Control.Enabled && disabledColors)
                {
                    checkColor = SystemColors.ControlDark;
                }

                double scale = GetDpiScaleRatio(e.Graphics);
                using (WindowsGraphics wg = WindowsGraphics.FromGraphics(e.Graphics)) {
                    using (WindowsBrush brush = new WindowsSolidBrush(wg.DeviceContext, checkColor)) {
                        // circle drawing doesn't work at this size
                        int       offset = 5;
                        Rectangle vCross = new Rectangle(layout.checkBounds.X + GetScaledNumber(offset, scale), layout.checkBounds.Y + GetScaledNumber(offset - 1, scale), GetScaledNumber(2, scale), GetScaledNumber(4, scale));
                        wg.FillRectangle(brush, vCross);
                        Rectangle hCross = new Rectangle(layout.checkBounds.X + GetScaledNumber(offset - 1, scale), layout.checkBounds.Y + GetScaledNumber(offset, scale), GetScaledNumber(4, scale), GetScaledNumber(2, scale));
                        wg.FillRectangle(brush, hCross);
                    }
                }
            }
        }
 internal void PaintImage(PaintEventArgs e, LayoutData layout)
 {
     Graphics graphics = e.Graphics;
     this.DrawImage(graphics, layout);
 }
 public DataGridView()
 {
     base.SetStyle(ControlStyles.UserMouse | ControlStyles.Opaque | ControlStyles.UserPaint, true);
     base.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
     base.SetState2(0x800, true);
     this.dataGridViewState1 = new BitVector32(0);
     this.dataGridViewState2 = new BitVector32(0);
     this.dataGridViewOper = new BitVector32(0);
     this.dataGridViewState1[0x80001b] = true;
     this.dataGridViewState2[0x60003e7] = true;
     this.displayedBandsInfo = new DisplayedBandsData();
     this.lstRows = new ArrayList();
     this.converters = new Hashtable(8);
     this.pens = new Hashtable(8);
     this.brushes = new Hashtable(10);
     this.gridPen = new Pen(DefaultGridColor);
     this.selectedBandIndexes = new DataGridViewIntLinkedList();
     this.individualSelectedCells = new DataGridViewCellLinkedList();
     this.individualReadOnlyCells = new DataGridViewCellLinkedList();
     this.advancedCellBorderStyle = new DataGridViewAdvancedBorderStyle(this, DataGridViewAdvancedCellBorderStyle.OutsetDouble, DataGridViewAdvancedCellBorderStyle.OutsetPartial, DataGridViewAdvancedCellBorderStyle.InsetDouble);
     this.advancedRowHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this);
     this.advancedColumnHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this);
     this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
     this.advancedRowHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
     this.advancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
     this.borderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     this.dataGridViewState1[0x80] = true;
     this.selectionMode = DataGridViewSelectionMode.RowHeaderSelect;
     this.editMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
     this.autoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
     this.autoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
     this.columnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
     this.rowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;
     this.clipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText;
     this.layout = new LayoutData();
     this.layout.TopLeftHeader = Rectangle.Empty;
     this.layout.ColumnHeaders = Rectangle.Empty;
     this.layout.RowHeaders = Rectangle.Empty;
     this.layout.ColumnHeadersVisible = true;
     this.layout.RowHeadersVisible = true;
     this.layout.ClientRectangle = base.ClientRectangle;
     this.scrollBars = System.Windows.Forms.ScrollBars.Both;
     this.horizScrollBar.RightToLeft = RightToLeft.Inherit;
     this.horizScrollBar.AccessibleName = System.Windows.Forms.SR.GetString("DataGridView_AccHorizontalScrollBarAccName");
     this.horizScrollBar.Top = base.ClientRectangle.Height - this.horizScrollBar.Height;
     this.horizScrollBar.Left = 0;
     this.horizScrollBar.Visible = false;
     this.horizScrollBar.Scroll += new ScrollEventHandler(this.DataGridViewHScrolled);
     base.Controls.Add(this.horizScrollBar);
     this.vertScrollBar.Top = 0;
     this.vertScrollBar.AccessibleName = System.Windows.Forms.SR.GetString("DataGridView_AccVerticalScrollBarAccName");
     this.vertScrollBar.Left = base.ClientRectangle.Width - this.vertScrollBar.Width;
     this.vertScrollBar.Visible = false;
     this.vertScrollBar.Scroll += new ScrollEventHandler(this.DataGridViewVScrolled);
     base.Controls.Add(this.vertScrollBar);
     this.ptCurrentCell = new Point(-1, -1);
     this.ptAnchorCell = new Point(-1, -1);
     this.ptMouseDownCell = new Point(-2, -2);
     this.ptMouseEnteredCell = new Point(-2, -2);
     this.ptToolTipCell = new Point(-1, -1);
     this.ptMouseDownGridCoord = new Point(-1, -1);
     this.sortOrder = System.Windows.Forms.SortOrder.None;
     this.lastMouseClickInfo.timeStamp = 0L;
     this.WireScrollBarsEvents();
     base.PerformLayout();
     this.toolTipControl = new DataGridViewToolTip(this);
     base.Invalidate();
 }
示例#28
0
        internal void PaintImage(PaintEventArgs e, LayoutData layout) {
            Graphics g = e.Graphics;

            DrawImage(g, layout);
        }
示例#29
0
        internal void PaintField(PaintEventArgs e, 
                                 LayoutData layout, 
                                 ColorData colors,
                                 Color foreColor, 
                                 bool drawFocus) {

            Graphics g = e.Graphics;

            Rectangle maxFocus = layout.focus;

            DrawText(g, layout, foreColor, colors);

            if (drawFocus) {
                DrawFocus(g, maxFocus);
            }
        }
 private bool ComputeLayout()
 {
     this.ClearRegionCache();
     LayoutData data = new LayoutData(this.layout);
     Rectangle resizeBoxRect = this.layout.ResizeBoxRect;
     if ((this.normalClientRectangle.Width > 0) || (this.normalClientRectangle.Height > 0))
     {
         data.Inside = this.normalClientRectangle;
     }
     else
     {
         data.Inside = base.ClientRectangle;
     }
     Rectangle inside = data.Inside;
     int borderWidth = this.BorderWidth;
     inside.Inflate(-borderWidth, -borderWidth);
     if (inside.Height < 0)
     {
         inside.Height = 0;
     }
     if (inside.Width < 0)
     {
         inside.Width = 0;
     }
     Rectangle rectangle3 = inside;
     if (this.layout.ColumnHeadersVisible)
     {
         Rectangle rectangle4 = rectangle3;
         rectangle4.Height = Math.Min(this.columnHeadersHeight, rectangle4.Height);
         rectangle3.Y += rectangle4.Height;
         rectangle3.Height -= rectangle4.Height;
         data.ColumnHeaders = rectangle4;
     }
     else
     {
         data.ColumnHeaders = Rectangle.Empty;
     }
     if (this.layout.RowHeadersVisible)
     {
         Rectangle rectangle5 = rectangle3;
         rectangle5.Width = Math.Min(this.rowHeadersWidth, rectangle5.Width);
         if (this.RightToLeftInternal)
         {
             rectangle5.X += rectangle3.Width - rectangle5.Width;
         }
         else
         {
             rectangle3.X += rectangle5.Width;
         }
         rectangle3.Width -= rectangle5.Width;
         data.RowHeaders = rectangle5;
         if (this.layout.ColumnHeadersVisible)
         {
             Rectangle columnHeaders = data.ColumnHeaders;
             Rectangle rectangle6 = columnHeaders;
             rectangle6.Width = Math.Min(this.rowHeadersWidth, rectangle6.Width);
             columnHeaders.Width -= rectangle6.Width;
             if (this.RightToLeftInternal)
             {
                 rectangle6.X += rectangle3.Width;
             }
             else
             {
                 columnHeaders.X += rectangle6.Width;
             }
             data.TopLeftHeader = rectangle6;
             data.ColumnHeaders = columnHeaders;
         }
         else
         {
             data.TopLeftHeader = Rectangle.Empty;
         }
     }
     else
     {
         data.RowHeaders = Rectangle.Empty;
         data.TopLeftHeader = Rectangle.Empty;
     }
     if (this.SingleVerticalBorderAdded)
     {
         if (!this.RightToLeftInternal)
         {
             rectangle3.X++;
         }
         if (rectangle3.Width > 0)
         {
             rectangle3.Width--;
         }
     }
     if (this.SingleHorizontalBorderAdded)
     {
         rectangle3.Y++;
         if (rectangle3.Height > 0)
         {
             rectangle3.Height--;
         }
     }
     data.Data = rectangle3;
     data.Inside = inside;
     this.layout = data;
     this.layout.dirty = false;
     bool flag = this.AdjustFillingColumns();
     this.layout = data;
     this.LayoutScrollBars();
     if (!resizeBoxRect.Equals(this.layout.ResizeBoxRect) && !this.layout.ResizeBoxRect.IsEmpty)
     {
         base.Invalidate(this.layout.ResizeBoxRect);
     }
     return flag;
 }
 public DataGrid()
 {
     base.SetStyle(ControlStyles.UserPaint, true);
     base.SetStyle(ControlStyles.Opaque, false);
     base.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
     base.SetStyle(ControlStyles.UserMouse, true);
     this.gridState = new BitVector32(0x42827);
     this.dataGridTables = new GridTableStylesCollection(this);
     this.layout = this.CreateInitialLayoutState();
     this.parentRows = new DataGridParentRows(this);
     this.horizScrollBar.Top = base.ClientRectangle.Height - this.horizScrollBar.Height;
     this.horizScrollBar.Left = 0;
     this.horizScrollBar.Visible = false;
     this.horizScrollBar.Scroll += new ScrollEventHandler(this.GridHScrolled);
     base.Controls.Add(this.horizScrollBar);
     this.vertScrollBar.Top = 0;
     this.vertScrollBar.Left = base.ClientRectangle.Width - this.vertScrollBar.Width;
     this.vertScrollBar.Visible = false;
     this.vertScrollBar.Scroll += new ScrollEventHandler(this.GridVScrolled);
     base.Controls.Add(this.vertScrollBar);
     this.BackColor = DefaultBackBrush.Color;
     this.ForeColor = DefaultForeBrush.Color;
     this.borderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
     this.currentChangedHandler = new EventHandler(this.DataSource_RowChanged);
     this.positionChangedHandler = new EventHandler(this.DataSource_PositionChanged);
     this.itemChangedHandler = new ItemChangedEventHandler(this.DataSource_ItemChanged);
     this.metaDataChangedHandler = new EventHandler(this.DataSource_MetaDataChanged);
     this.dataGridTableStylesCollectionChanged = new CollectionChangeEventHandler(this.TableStylesCollectionChanged);
     this.dataGridTables.CollectionChanged += this.dataGridTableStylesCollectionChanged;
     this.SetDataGridTable(this.defaultTableStyle, true);
     this.backButtonHandler = new EventHandler(this.OnBackButtonClicked);
     this.downButtonHandler = new EventHandler(this.OnShowParentDetailsButtonClicked);
     this.caption = new DataGridCaption(this);
     this.caption.BackwardClicked += this.backButtonHandler;
     this.caption.DownClicked += this.downButtonHandler;
     this.RecalculateFonts();
     base.Size = new Size(130, 80);
     base.Invalidate();
     base.PerformLayout();
 }
 private void ComputeLayout()
 {
     bool flag = !this.isRightToLeft();
     Rectangle resizeBoxRect = this.layout.ResizeBoxRect;
     this.EndEdit();
     this.ClearRegionCache();
     LayoutData data = new LayoutData(this.layout) {
         Inside = base.ClientRectangle
     };
     Rectangle inside = data.Inside;
     int borderWidth = this.BorderWidth;
     inside.Inflate(-borderWidth, -borderWidth);
     Rectangle rectangle3 = inside;
     if (this.layout.CaptionVisible)
     {
         int num2 = this.captionFontHeight + 6;
         Rectangle caption = data.Caption;
         caption = rectangle3;
         caption.Height = num2;
         rectangle3.Y += num2;
         rectangle3.Height -= num2;
         data.Caption = caption;
     }
     else
     {
         data.Caption = Rectangle.Empty;
     }
     if (this.layout.ParentRowsVisible)
     {
         Rectangle parentRows = data.ParentRows;
         int height = this.parentRows.Height;
         parentRows = rectangle3;
         parentRows.Height = height;
         rectangle3.Y += height;
         rectangle3.Height -= height;
         data.ParentRows = parentRows;
     }
     else
     {
         data.ParentRows = Rectangle.Empty;
     }
     int num4 = this.headerFontHeight + 6;
     if (this.layout.ColumnHeadersVisible)
     {
         Rectangle columnHeaders = data.ColumnHeaders;
         columnHeaders = rectangle3;
         columnHeaders.Height = num4;
         rectangle3.Y += num4;
         rectangle3.Height -= num4;
         data.ColumnHeaders = columnHeaders;
     }
     else
     {
         data.ColumnHeaders = Rectangle.Empty;
     }
     bool flag2 = this.myGridTable.IsDefault ? this.RowHeadersVisible : this.myGridTable.RowHeadersVisible;
     int num5 = this.myGridTable.IsDefault ? this.RowHeaderWidth : this.myGridTable.RowHeaderWidth;
     data.RowHeadersVisible = flag2;
     if ((this.myGridTable != null) && flag2)
     {
         Rectangle rowHeaders = data.RowHeaders;
         if (flag)
         {
             rowHeaders = rectangle3;
             rowHeaders.Width = num5;
             rectangle3.X += num5;
             rectangle3.Width -= num5;
         }
         else
         {
             rowHeaders = rectangle3;
             rowHeaders.Width = num5;
             rowHeaders.X = rectangle3.Right - num5;
             rectangle3.Width -= num5;
         }
         data.RowHeaders = rowHeaders;
         if (this.layout.ColumnHeadersVisible)
         {
             Rectangle topLeftHeader = data.TopLeftHeader;
             Rectangle rectangle9 = data.ColumnHeaders;
             if (flag)
             {
                 topLeftHeader = rectangle9;
                 topLeftHeader.Width = num5;
                 rectangle9.Width -= num5;
                 rectangle9.X += num5;
             }
             else
             {
                 topLeftHeader = rectangle9;
                 topLeftHeader.Width = num5;
                 topLeftHeader.X = rectangle9.Right - num5;
                 rectangle9.Width -= num5;
             }
             data.TopLeftHeader = topLeftHeader;
             data.ColumnHeaders = rectangle9;
         }
         else
         {
             data.TopLeftHeader = Rectangle.Empty;
         }
     }
     else
     {
         data.RowHeaders = Rectangle.Empty;
         data.TopLeftHeader = Rectangle.Empty;
     }
     data.Data = rectangle3;
     data.Inside = inside;
     this.layout = data;
     this.LayoutScrollBars();
     if (!resizeBoxRect.Equals(this.layout.ResizeBoxRect) && !this.layout.ResizeBoxRect.IsEmpty)
     {
         base.Invalidate(this.layout.ResizeBoxRect);
     }
     this.layout.dirty = false;
 }
 internal virtual void DrawImageCore(Graphics graphics, Image image, Rectangle imageBounds, Point imageStart, LayoutData layout)
 {
     Region clip = graphics.Clip;
     if (!layout.options.everettButtonCompat)
     {
         Rectangle rect = new Rectangle(buttonBorderSize, buttonBorderSize, this.Control.Width - (2 * buttonBorderSize), this.Control.Height - (2 * buttonBorderSize));
         Region region2 = clip.Clone();
         region2.Intersect(rect);
         region2.Intersect(imageBounds);
         graphics.Clip = region2;
     }
     else
     {
         imageBounds.Width++;
         imageBounds.Height++;
         imageBounds.X = imageStart.X + 1;
         imageBounds.Y = imageStart.Y + 1;
     }
     try
     {
         if (!this.Control.Enabled)
         {
             ControlPaint.DrawImageDisabled(graphics, image, imageBounds, this.Control.BackColor, true);
         }
         else
         {
             graphics.DrawImage(image, imageBounds.X, imageBounds.Y, image.Width, image.Height);
         }
     }
     finally
     {
         if (!layout.options.everettButtonCompat)
         {
             graphics.Clip = clip;
         }
     }
 }
示例#34
0
        private void LoadDetailsPanel(int lID)
        {
            ObjectOrEntityVisible(false);

            LayoutData ld = new LayoutData(lID);

            bool IsTopic   = (Page as SkinBase).IsTopicPage;
            bool IsEntity  = (Page as SkinBase).IsEntityPage;
            bool IsProduct = (Page as SkinBase).IsProductPage;

            int ID = (Page as SkinBase).PageID;

            ltselectedid.Text   = ld.LayoutID.ToString();
            ltselectedname.Text = ld.Name;

            ltcurrentpage.Text = CommonLogic.GetThisPageName(false);

            if (IsTopic)
            {
                ObjectOrEntityVisible(true);
                ltobjecttype.Text = AppLogic.GetString("layouts.map.topic", m_skinID, LocaleSetting);
                ltobjectid.Text   = ID.ToString();
            }

            if (IsProduct)
            {
                ObjectOrEntityVisible(true);
                ltobjecttype.Text = AppLogic.GetString("common.cs.Product", m_skinID, LocaleSetting);
                ltobjectid.Text   = ID.ToString();
            }

            if (IsEntity)
            {
                ObjectOrEntityVisible(true);
                string EType = (Page as SkinBase).EntityType;

                switch (EType.ToLowerInvariant())
                {
                case "category":
                    ltobjecttype.Text = AppLogic.GetString("AppConfig.CategoryPromptSingular", m_skinID, LocaleSetting);
                    break;

                case "manufacturer":
                    ltobjecttype.Text = AppLogic.GetString("AppConfig.ManufacturerPromptSingular", m_skinID, LocaleSetting);
                    break;

                case "distributor":
                    ltobjecttype.Text = AppLogic.GetString("AppConfig.DistributorPromptSingular", m_skinID, LocaleSetting);
                    break;

                case "section":
                    ltobjecttype.Text = AppLogic.GetString("AppConfig.SectionPromptSingular", m_skinID, LocaleSetting);
                    break;

                case "genre":
                    ltobjecttype.Text = AppLogic.GetString("AppConfig.GenrePromptSingular", m_skinID, LocaleSetting);
                    break;

                case "vector":
                    ltobjecttype.Text = AppLogic.GetString("AppConfig.VectorPromptSingular", m_skinID, LocaleSetting);
                    break;

                case "library":
                    ltobjecttype.Text = AppLogic.GetString("AppConfig.LibraryPromptSingular", m_skinID, LocaleSetting);
                    break;

                case "affiliate":
                    ltobjecttype.Text = AppLogic.GetString("AppConfig.AffiliatePromptSingular", m_skinID, LocaleSetting);
                    break;

                default:
                    ltobjecttype.Text = AppLogic.GetString("common.cs.NA", m_skinID, LocaleSetting);
                    break;
                }

                ltobjectid.Text = ID.ToString();
            }
        }
示例#35
0
 protected void DrawCheckOnly(PaintEventArgs e, LayoutData layout, ColorData colors, Color checkColor, Color checkBackground)
 {
     DrawCheckOnly(flatCheckSize, Control.Checked, Control.Enabled, Control.CheckState, e.Graphics, layout, colors, checkColor, checkBackground);
 }
 private void DrawText(Graphics g, LayoutData layout, Color c, ColorData colors)
 {
     Rectangle textBounds = layout.textBounds;
     bool shadowedText = layout.options.shadowedText;
     if (this.Control.UseCompatibleTextRendering)
     {
         using (StringFormat format = this.CreateStringFormat())
         {
             Brush brush2;
             if ((this.Control.TextAlign & (ContentAlignment.BottomCenter | ContentAlignment.MiddleCenter | ContentAlignment.TopCenter)) == ((ContentAlignment) 0))
             {
                 textBounds.X--;
             }
             textBounds.Width++;
             if (shadowedText && !this.Control.Enabled)
             {
                 textBounds.Offset(1, 1);
                 using (SolidBrush brush = new SolidBrush(colors.highlight))
                 {
                     g.DrawString(this.Control.Text, this.Control.Font, brush, textBounds, format);
                     textBounds.Offset(-1, -1);
                     brush.Color = colors.buttonShadow;
                     g.DrawString(this.Control.Text, this.Control.Font, brush, textBounds, format);
                     return;
                 }
             }
             if (c.IsSystemColor)
             {
                 brush2 = SystemBrushes.FromSystemColor(c);
             }
             else
             {
                 brush2 = new SolidBrush(c);
             }
             g.DrawString(this.Control.Text, this.Control.Font, brush2, textBounds, format);
             if (!c.IsSystemColor)
             {
                 brush2.Dispose();
             }
             return;
         }
     }
     TextFormatFlags flags = this.CreateTextFormatFlags();
     if (shadowedText && !this.Control.Enabled)
     {
         if (Application.RenderWithVisualStyles)
         {
             TextRenderer.DrawText(g, this.Control.Text, this.Control.Font, textBounds, colors.buttonShadow, flags);
         }
         else
         {
             textBounds.Offset(1, 1);
             TextRenderer.DrawText(g, this.Control.Text, this.Control.Font, textBounds, colors.highlight, flags);
             textBounds.Offset(-1, -1);
             TextRenderer.DrawText(g, this.Control.Text, this.Control.Font, textBounds, colors.buttonShadow, flags);
         }
     }
     else
     {
         TextRenderer.DrawText(g, this.Control.Text, this.Control.Font, textBounds, c, flags);
     }
 }
#pragma warning restore 0414
#endif
        /// <include file='doc\DataGridView.uex' path='docs/doc[@for="DataGridView.DataGridView"]/*' />
        /// <devdoc>
        /// <para>Initializes a new instance of the <see cref='System.Windows.Forms.DataGridView'/> class.</para>
        /// </devdoc>
        public DataGridView()
        {
            SetStyle(ControlStyles.UserPaint | 
                     ControlStyles.Opaque | 
                     ControlStyles.UserMouse, true);
            
            SetStyle(ControlStyles.SupportsTransparentBackColor, false);

            // this class overrides GetPreferredSizeCore, let Control automatically cache the result
            SetState2(STATE2_USEPREFERREDSIZECACHE, true);  

            this.dataGridViewState1 = new System.Collections.Specialized.BitVector32(0x00000000);
            this.dataGridViewState2 = new System.Collections.Specialized.BitVector32(0x00000000);
            this.dataGridViewOper   = new System.Collections.Specialized.BitVector32(0x00000000);

            this.dataGridViewState1[  DATAGRIDVIEWSTATE1_columnHeadersVisible 
                                    | DATAGRIDVIEWSTATE1_rowHeadersVisible 
                                    | DATAGRIDVIEWSTATE1_autoGenerateColumns
                                    | DATAGRIDVIEWSTATE1_allowUserToAddRows
                                    | DATAGRIDVIEWSTATE1_allowUserToDeleteRows ] = true;



            this.dataGridViewState2[  DATAGRIDVIEWSTATE2_showEditingIcon
                                    | DATAGRIDVIEWSTATE2_enableHeadersVisualStyles
                                    | DATAGRIDVIEWSTATE2_mouseEnterExpected
                                    | DATAGRIDVIEWSTATE2_allowUserToResizeColumns
                                    | DATAGRIDVIEWSTATE2_allowUserToResizeRows
                                    | DATAGRIDVIEWSTATE2_showCellToolTips
                                    | DATAGRIDVIEWSTATE2_showCellErrors
                                    | DATAGRIDVIEWSTATE2_showRowErrors
                                    | DATAGRIDVIEWSTATE2_allowHorizontalScrollbar
                                    | DATAGRIDVIEWSTATE2_usedFillWeightsDirty ] = true;


            this.displayedBandsInfo = new DisplayedBandsData();
            this.lstRows = new ArrayList();

            this.converters = new Hashtable(8);
            this.pens = new Hashtable(8);
            this.brushes = new Hashtable(10);
            this.gridPen = new Pen(DefaultGridColor);

            this.selectedBandIndexes = new DataGridViewIntLinkedList();
            this.individualSelectedCells = new DataGridViewCellLinkedList();
            this.individualReadOnlyCells = new DataGridViewCellLinkedList();

            this.advancedCellBorderStyle = new DataGridViewAdvancedBorderStyle(this, 
                DataGridViewAdvancedCellBorderStyle.OutsetDouble, 
                DataGridViewAdvancedCellBorderStyle.OutsetPartial, 
                DataGridViewAdvancedCellBorderStyle.InsetDouble);
            this.advancedRowHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this);
            this.advancedColumnHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this);
            this.advancedCellBorderStyle.All = defaultAdvancedCellBorderStyle;
            this.advancedRowHeadersBorderStyle.All = defaultAdvancedRowHeadersBorderStyle;
            this.advancedColumnHeadersBorderStyle.All = defaultAdvancedColumnHeadersBorderStyle;
            this.borderStyle = defaultBorderStyle;
            this.dataGridViewState1[DATAGRIDVIEWSTATE1_multiSelect] = true;
            this.selectionMode = defaultSelectionMode;
            this.editMode = defaultEditMode;
            this.autoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
            this.autoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            this.columnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
            this.rowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;

            this.clipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText;

            this.layout = new LayoutData();
            this.layout.TopLeftHeader        = Rectangle.Empty;
            this.layout.ColumnHeaders        = Rectangle.Empty;
            this.layout.RowHeaders           = Rectangle.Empty;
            this.layout.ColumnHeadersVisible = true;
            this.layout.RowHeadersVisible    = true;
            this.layout.ClientRectangle      = this.ClientRectangle;

            this.scrollBars = ScrollBars.Both;

            this.horizScrollBar.RightToLeft = RightToLeft.Inherit;
            this.horizScrollBar.AccessibleName = SR.GetString(SR.DataGridView_AccHorizontalScrollBarAccName);
            this.horizScrollBar.Top = this.ClientRectangle.Height - horizScrollBar.Height;
            this.horizScrollBar.Left = 0;
            this.horizScrollBar.Visible = false;
            this.horizScrollBar.Scroll += new ScrollEventHandler(DataGridViewHScrolled);
            this.Controls.Add(this.horizScrollBar);

            this.vertScrollBar.Top = 0;
            this.vertScrollBar.AccessibleName = SR.GetString(SR.DataGridView_AccVerticalScrollBarAccName);
            this.vertScrollBar.Left = this.ClientRectangle.Width - vertScrollBar.Width;
            this.vertScrollBar.Visible = false;
            this.vertScrollBar.Scroll += new ScrollEventHandler(DataGridViewVScrolled);
            this.Controls.Add(this.vertScrollBar);

            this.ptCurrentCell = new Point(-1, -1);
            this.ptAnchorCell = new Point(-1, -1);
            this.ptMouseDownCell = new Point(-2, -2);
            this.ptMouseEnteredCell = new Point(-2, -2);
            this.ptToolTipCell = new Point(-1, -1);
            this.ptMouseDownGridCoord = new Point(-1, -1);

            this.sortOrder = SortOrder.None;

            this.lastMouseClickInfo.timeStamp = 0;

            WireScrollBarsEvents();
            PerformLayout();

            this.toolTipControl = new DataGridViewToolTip(this);
            
            Invalidate();
        }
 /// <summary>
 /// Creates a LayoutData object containing the saved results of a serializerService
 /// </summary>
 private static LayoutData SaveLayout( ILayoutSerializerService serializerService )
 {
     using ( MemoryStream ms = new MemoryStream( ) )
     {
         if ( !serializerService.Save( ms ) )
         {
             return null;
         }
         LayoutData layout = new LayoutData( );
         layout.Data = ms.ToArray( );
         layout.LayoutServiceType = serializerService.GetType( );
         return layout;
     }
 }
        private bool ComputeLayout() 
        {
            ClearRegionCache();

            LayoutData newLayout = new LayoutData(this.layout);
            Rectangle oldResizeRect = this.layout.ResizeBoxRect;

            // Inside region
            if (this.normalClientRectangle.Width > 0 || this.normalClientRectangle.Height > 0)
            {
                newLayout.Inside = this.normalClientRectangle;
            }
            else
            {
                newLayout.Inside = this.ClientRectangle;
            }
            Rectangle inside = newLayout.Inside;
            int borderWidth = this.BorderWidth;
            inside.Inflate(-borderWidth, -borderWidth);
            if (inside.Height < 0)
            {
                inside.Height = 0;
            }
            if (inside.Width < 0)
            {
                inside.Width = 0;
            }

            Rectangle insideLeft = inside;

            // Headers
            if (this.layout.ColumnHeadersVisible) 
            {
                Rectangle colHeaders = insideLeft;
                colHeaders.Height = Math.Min(this.columnHeadersHeight, colHeaders.Height);
                insideLeft.Y += colHeaders.Height;
                insideLeft.Height -= colHeaders.Height;
                Debug.Assert(insideLeft.Height >= 0);
                newLayout.ColumnHeaders = colHeaders;
            }
            else 
            {
                newLayout.ColumnHeaders = Rectangle.Empty;
            }

            if (this.layout.RowHeadersVisible) 
            {
                Rectangle rowHeaders = insideLeft;
                rowHeaders.Width = Math.Min(this.rowHeadersWidth, rowHeaders.Width);
                if (this.RightToLeftInternal)
                {
                    rowHeaders.X += insideLeft.Width - rowHeaders.Width;
                }
                else
                {
                    insideLeft.X += rowHeaders.Width;
                }
                insideLeft.Width -= rowHeaders.Width;
                Debug.Assert(insideLeft.Width >= 0);
                newLayout.RowHeaders = rowHeaders;

                if (this.layout.ColumnHeadersVisible) 
                {
                    Rectangle topLeft;
                    Rectangle colHeaders = newLayout.ColumnHeaders;
                    topLeft = colHeaders;
                    topLeft.Width = Math.Min(this.rowHeadersWidth, topLeft.Width);
                    colHeaders.Width -= topLeft.Width;
                    if (this.RightToLeftInternal)
                    {
                        topLeft.X += insideLeft.Width;
                    }
                    else
                    {
                        colHeaders.X += topLeft.Width;
                    }
                    Debug.Assert(colHeaders.Width >= 0);
                    newLayout.TopLeftHeader = topLeft;
                    newLayout.ColumnHeaders = colHeaders;
                }
                else
                {
                    newLayout.TopLeftHeader = Rectangle.Empty;
                }
            }
            else 
            {
                newLayout.RowHeaders = Rectangle.Empty;
                newLayout.TopLeftHeader = Rectangle.Empty;
            }

            // Adjust insideLeft in case static top / left edge needs to be painted
            if (this.SingleVerticalBorderAdded)
            {
                if (!this.RightToLeftInternal)
                {
                    insideLeft.X++;
                }
                if (insideLeft.Width > 0)
                {
                    insideLeft.Width--;
                }
            }
            if (this.SingleHorizontalBorderAdded)
            {
                insideLeft.Y++;
                if (insideLeft.Height > 0)
                {
                    insideLeft.Height--;
                }
            }
            
            // Data region
            newLayout.Data = insideLeft;
            newLayout.Inside = inside;

            Debug.Assert(newLayout.Data.X >= 0);
            Debug.Assert(newLayout.Data.Y >= 0);
            Debug.Assert(newLayout.Data.Width >= 0);
            Debug.Assert(newLayout.Data.Height >= 0);

            this.layout = newLayout;
            this.layout.dirty = false;

            bool columnsAdjusted = AdjustFillingColumns();

            this.layout = newLayout;
            Debug.Assert(!this.layout.dirty);
            LayoutScrollBars();

            // if the user shrank the grid client area, then OnResize invalidated the old
            // resize area. however, we need to invalidate the left upper corner in the new ResizeArea
            // note that we can't take the Invalidate call from the OnResize method, because if the
            // user enlarges the form then the old area will not be invalidated.
            // 
            if (!oldResizeRect.Equals(this.layout.ResizeBoxRect) && !this.layout.ResizeBoxRect.IsEmpty)
            {
                Invalidate(this.layout.ResizeBoxRect);
            }

            return columnsAdjusted;
        }
        protected LayoutData DoCellLayout(Graphics g, Rectangle bounds)
        {
            LayoutData layoutData = new LayoutData();
            layoutData.cellBounds = bounds;
            layoutData.faceBounds = bounds;
            layoutData.faceBounds.Inflate(-2, -2);//deflate for boarders

            Size textSize = g.MeasureString(this.Text, this.Font).ToSize();
            layoutData.textBounds = layoutData.faceBounds;
            layoutData.textBounds.Inflate(-1, -1);//pad the text area
            layoutData.textBounds = AlignContentWithinCell(textSize, layoutData.textBounds, this.TextAllign);

            return layoutData;
        }
 /// <summary>
 /// Loads a layout
 /// </summary>
 private void LoadLayout( LayoutData layout )
 {
     foreach ( object service in m_Services.Services )
     {
         if ( service.GetType( ) == layout.LayoutServiceType )
         {
             using ( MemoryStream ms = new MemoryStream( layout.Data ) )
             {
                 ( ( ILayoutSerializerService )service ).Load( ms );
                 return;
             }
         }
     }
     m_Log.Error( "Could not find service that could load layout intended for a " + layout.LayoutServiceType );
 }
 protected void PaintButtonBackground(Graphics g, Brush background, LayoutData layout)
 {
     g.FillRectangle(background, layout.cellBounds);
 }
 protected void PaintField(Graphics g, string text, LayoutData layout, ColorData colors, bool drawFocus)
 {
     using (Brush foreBrush = new SolidBrush(colors.foreColor))
     {
         g.DrawString(text, this.Font, foreBrush, layout.textBounds);
     }
 }
        private void DrawButton(Graphics g, ColorData colorData, LayoutData layout, bool up)
        {
            Image img = this.GetImage();
            if (img != null)
            {
                if (this.Enabled)
                {
                    this.DrawImage(g, ref layout.faceBounds, img, layout.faceBounds.X, layout.faceBounds.Y);
                }
                else
                {
                    this.DrawImageDisabled(g, ref layout.faceBounds, img, layout.faceBounds.X, layout.faceBounds.Y);
                }
            }

            string text = this.Text;
            //MatchCollection matches = Regex.Matches(this.Text, @"<\w*>", RegexOptions.Compiled);
            //if (matches.Count > 0)
            //{
            //    Rectangle[] rectangles = new Rectangle[matches.Count];
            //    int recW = layout.textBounds.Width / matches.Count;
            //    for (int i = 0; i < matches.Count; i++)
            //    {
            //        Match m = matches[i];
            //        rectangles[i] = new Rectangle(recW * i + layout.textBounds.X, layout.textBounds.Y, recW, layout.textBounds.Height);
            //        string val = m.Value.Trim().Trim('<', '>');

            //        Image mImg = GetImage(Convert.ToInt32(val));
            //        this.DrawImage(g, ref rectangles[i], mImg, rectangles[i].X, rectangles[i].Y);
            //        text = text.Replace(m.Value, string.Empty);
            //    }
            //}

            this.PaintField(g, text, layout, colorData, true);

            this.DrawBorder(g, layout.cellBounds, colorData, up);
            //else
            //  ControlPaint.DrawBorder(graphics, clientRectangle, colors.buttonShadow, ButtonBorderStyle.Solid);
        }
 protected void DrawCheckFlat(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, Color checkBorder)
 {
     DrawCheckBackgroundFlat(e, layout.checkBounds, checkBorder, checkBackground);
     DrawCheckOnly(e, layout, checkColor, checkBackground, true);
 }
示例#46
0
            internal LayoutData Layout() {
                LayoutData layout = new LayoutData(this);
                layout.client = this.client;

                // subtract border size from layout area
                int fullBorderSize = FullBorderSize;
                layout.face = Rectangle.Inflate(layout.client, -fullBorderSize, -fullBorderSize);
                
                // checkBounds, checkArea, field
                //
                CalcCheckmarkRectangle(layout);

                // imageBounds, imageLocation, textBounds
                LayoutTextAndImage(layout);

                // focus
                //
                if (maxFocus) {
                    layout.focus = layout.field;
                    layout.focus.Inflate(-1, -1);

                    // Adjust for padding. VSWhidbey #387208
                    layout.focus = LayoutUtils.InflateRect(layout.focus, this.padding);
                }
                else {
                    Rectangle textAdjusted = new Rectangle(layout.textBounds.X - 1, layout.textBounds.Y - 1,
                                                           layout.textBounds.Width + 2, layout.textBounds.Height + 3);
                    if (imageSize != Size.Empty) {
                        layout.focus = Rectangle.Union(textAdjusted, layout.imageBounds);
                    }
                    else {
                        layout.focus = textAdjusted;
                    }
                }
                if (focusOddEvenFixup) {
                    if (layout.focus.Height % 2 == 0) {
                        layout.focus.Y++;
                        layout.focus.Height--;
                    }
                    if (layout.focus.Width % 2 == 0) {
                        layout.focus.X++;
                        layout.focus.Width--;
                    }
                }


                return layout;
            }
示例#47
0
        // used by DataGridViewCheckBoxCell
        internal static void DrawCheckOnly(int checkSize, bool controlChecked, bool controlEnabled, CheckState controlCheckState, Graphics g, LayoutData layout, ColorData colors, Color checkColor, Color checkBackground)
        {
            // check
            //
            if (controlChecked)
            {
                if (!controlEnabled)
                {
                    checkColor = colors.buttonShadow;
                }
                else if (controlCheckState == CheckState.Indeterminate)
                {
                    checkColor = SystemInformation.HighContrast ? colors.highlight :
                                 colors.buttonShadow;
                }

                Rectangle fullSize = layout.checkBounds;

                if (fullSize.Width == checkSize)
                {
                    fullSize.Width++;
                    fullSize.Height++;
                }

                fullSize.Width++;

                fullSize.Height++;
                Bitmap checkImage = null;
                if (controlCheckState == CheckState.Checked)
                {
                    checkImage = GetCheckBoxImage(checkColor, fullSize, ref checkImageCheckedBackColor, ref checkImageChecked);
                }
                else
                {
                    Debug.Assert(controlCheckState == CheckState.Indeterminate, "we want to paint the check box only if the item is checked or indeterminate");
                    checkImage = GetCheckBoxImage(checkColor, fullSize, ref checkImageIndeterminateBackColor, ref checkImageIndeterminate);
                }

                if (layout.options.everettButtonCompat)
                {
                    fullSize.Y -= 1;
                }
                else
                {
                    fullSize.Y -= 2;
                }

                ControlPaint.DrawImageColorized(g, checkImage, fullSize, checkColor);
            }
        }
示例#48
0
        internal override void PaintOver(PaintEventArgs e, CheckState state)
        {
            if (SystemInformation.HighContrast)
            {
                PaintUp(e, state);
            }
            else
            {
                bool hasCustomBorder = (Control.FlatAppearance.BorderSize != BORDERSIZE || !Control.FlatAppearance.BorderColor.IsEmpty);

                ColorData  colors = PaintFlatRender(e.Graphics).Calculate();
                LayoutData layout = PaintFlatLayout(e,
                                                    !Control.FlatAppearance.CheckedBackColor.IsEmpty || state == CheckState.Unchecked,
                                                    false,
                                                    Control.FlatAppearance.BorderSize).Layout();

                // Paint with the BorderColor if Set.
                if (!Control.FlatAppearance.BorderColor.IsEmpty)
                {
                    colors.windowFrame = Control.FlatAppearance.BorderColor;
                }

                Graphics g = e.Graphics;

                Rectangle r = Control.ClientRectangle;

                Color backColor = Control.BackColor;

                if (!Control.FlatAppearance.MouseOverBackColor.IsEmpty)
                {
                    backColor = Control.FlatAppearance.MouseOverBackColor;
                }
                else if (!Control.FlatAppearance.CheckedBackColor.IsEmpty)
                {
                    if (state == CheckState.Checked || state == CheckState.Indeterminate)
                    {
                        backColor = MixedColor(Control.FlatAppearance.CheckedBackColor, colors.lowButtonFace);
                    }
                    else
                    {
                        backColor = colors.lowButtonFace;
                    }
                }
                else
                {
                    if (state == CheckState.Indeterminate)
                    {
                        backColor = MixedColor(colors.buttonFace, colors.lowButtonFace);
                    }
                    else
                    {
                        backColor = colors.lowButtonFace;
                    }
                }

                PaintBackground(e, r, IsHighContrastHighlighted() ? SystemColors.Highlight : backColor);

                if (Control.IsDefault)
                {
                    r.Inflate(-1, -1);
                }

                PaintImage(e, layout);
                PaintField(e, layout, colors, IsHighContrastHighlighted() ? SystemColors.HighlightText : colors.windowText, false);

                if (Control.Focused && Control.ShowFocusCues)
                {
                    DrawFlatFocus(g, layout.focus, colors.constrastButtonShadow);
                }

                if (!(Control.IsDefault && Control.Focused && (Control.FlatAppearance.BorderSize == 0)))
                {
                    DrawDefaultBorder(g, r, colors.windowFrame, Control.IsDefault);
                }

                //Always check if the BorderSize is not the default.If not, we need to paint with the BorderSize set by the user.
                if (hasCustomBorder)
                {
                    if (Control.FlatAppearance.BorderSize != BORDERSIZE)
                    {
                        DrawFlatBorderWithSize(g, r, colors.windowFrame, Control.FlatAppearance.BorderSize);
                    }
                    else
                    {
                        DrawFlatBorder(g, r, colors.windowFrame);
                    }
                }
                else if (state == CheckState.Unchecked)
                {
                    DrawFlatBorder(g, r, colors.windowFrame);
                }
                else
                {
                    Draw3DLiteBorder(g, r, colors, false);
                }
            }
        }
示例#49
0
        internal override void PaintOver(PaintEventArgs e, CheckState state)
        {
            ColorData  colors = PaintPopupRender(e.Graphics).Calculate();
            LayoutData layout = PaintPopupLayout(e, state == CheckState.Unchecked, SystemInformation.HighContrast ? 2 : 1).Layout();

            Graphics g = e.Graphics;
            //Region original = g.Clip;

            Rectangle r = Control.ClientRectangle;

            if (state == CheckState.Indeterminate)
            {
                Brush backbrush = CreateDitherBrush(colors.highlight, colors.buttonFace);
                try
                {
                    PaintButtonBackground(e, r, backbrush);
                }
                finally
                {
                    backbrush.Dispose();
                    backbrush = null;
                }
            }
            else
            {
                Control.PaintBackground(e, r, IsHighContrastHighlighted() ? SystemColors.Highlight : Control.BackColor, r.Location);
            }

            if (Control.IsDefault)
            {
                r.Inflate(-1, -1);
            }

            PaintImage(e, layout);
            PaintField(e, layout, colors, IsHighContrastHighlighted() ? SystemColors.HighlightText : colors.windowText, true);

            DrawDefaultBorder(g, r, colors.options.highContrast ? colors.windowText : colors.buttonShadow, Control.IsDefault);

            if (SystemInformation.HighContrast)
            {
                using (Pen windowFrame = new Pen(colors.windowFrame),
                       highlight = new Pen(colors.highlight),
                       buttonShadow = new Pen(colors.buttonShadow))
                {
                    // top, left white
                    g.DrawLine(windowFrame, r.Left + 1, r.Top + 1, r.Right - 2, r.Top + 1);
                    g.DrawLine(windowFrame, r.Left + 1, r.Top + 1, r.Left + 1, r.Bottom - 2);

                    // bottom, right white
                    g.DrawLine(windowFrame, r.Left, r.Bottom - 1, r.Right, r.Bottom - 1);
                    g.DrawLine(windowFrame, r.Right - 1, r.Top, r.Right - 1, r.Bottom);

                    // top, left gray
                    g.DrawLine(highlight, r.Left, r.Top, r.Right, r.Top);
                    g.DrawLine(highlight, r.Left, r.Top, r.Left, r.Bottom);

                    // bottom, right gray
                    g.DrawLine(buttonShadow, r.Left + 1, r.Bottom - 2, r.Right - 2, r.Bottom - 2);
                    g.DrawLine(buttonShadow, r.Right - 2, r.Top + 1, r.Right - 2, r.Bottom - 2);
                }

                r.Inflate(-2, -2);
            }
            else
            {
                Draw3DLiteBorder(g, r, colors, true);
            }
        }
示例#50
0
        protected void DrawCheckBox(PaintEventArgs e, LayoutData layout) {
            Graphics g = e.Graphics;
            
            Rectangle check = layout.checkBounds;
            if (!Application.RenderWithVisualStyles) {
                check.X--;      // compensate for Windows drawing slightly offset to right
            }

            ButtonState style = GetState();
            
            if (Application.RenderWithVisualStyles) {
                RadioButtonRenderer.DrawRadioButton(g, new Point(check.Left, check.Top), RadioButtonRenderer.ConvertFromButtonState(style, Control.MouseIsOver));
            }
            else {
                ControlPaint.DrawRadioButton(g, check, style);
            }
        }
示例#51
0
            void CalcCheckmarkRectangle(LayoutData layout) {
                int checkSizeFull = FullCheckSize;
                layout.checkBounds = new Rectangle(client.X, client.Y, checkSizeFull, checkSizeFull);

                // Translate checkAlign for Rtl applications
                ContentAlignment align = RtlTranslateContent(checkAlign);

                Rectangle field = Rectangle.Inflate(layout.face, -paddingSize, -paddingSize);

                layout.field = field;

                if (checkSizeFull > 0) {
                    if ((align & LayoutUtils.AnyRight) != 0) {
                        layout.checkBounds.X = (field.X+field.Width) - layout.checkBounds.Width;
                    }
                    else if ((align & LayoutUtils.AnyCenter) != 0) {
                        layout.checkBounds.X = field.X + (field.Width - layout.checkBounds.Width)/2;
                    }

                    if ((align & LayoutUtils.AnyBottom) != 0) {
                        layout.checkBounds.Y = (field.Y+field.Height)-layout.checkBounds.Height;
                    }
                    else if ((align & LayoutUtils.AnyTop) != 0) {
                        layout.checkBounds.Y = field.Y + 2; // + 2: this needs to be aligned to the text (bug 87483)
                    }
                    else {
                        layout.checkBounds.Y = field.Y + (field.Height - layout.checkBounds.Height)/2;
                    }

                    switch (align) {
                        case ContentAlignment.TopLeft:
                        case ContentAlignment.MiddleLeft:
                        case ContentAlignment.BottomLeft:
                            layout.checkArea.X = field.X;
                            layout.checkArea.Width = checkSizeFull + 1;

                            layout.checkArea.Y = field.Y;
                            layout.checkArea.Height = field.Height;

                            layout.field.X += checkSizeFull + 1;
                            layout.field.Width -= checkSizeFull + 1;
                            break;
                        case ContentAlignment.TopRight:
                        case ContentAlignment.MiddleRight:
                        case ContentAlignment.BottomRight:
                            layout.checkArea.X = field.X + field.Width - checkSizeFull;
                            layout.checkArea.Width = checkSizeFull + 1;

                            layout.checkArea.Y = field.Y;
                            layout.checkArea.Height = field.Height;

                            layout.field.Width -= checkSizeFull + 1;
                            break;
                        case ContentAlignment.TopCenter:
                            layout.checkArea.X = field.X;
                            layout.checkArea.Width = field.Width;

                            layout.checkArea.Y = field.Y;
                            layout.checkArea.Height = checkSizeFull;

                            layout.field.Y += checkSizeFull;
                            layout.field.Height -= checkSizeFull;
                            break;

                        case ContentAlignment.BottomCenter:
                            layout.checkArea.X = field.X;
                            layout.checkArea.Width = field.Width;

                            layout.checkArea.Y = field.Y + field.Height - checkSizeFull;
                            layout.checkArea.Height = checkSizeFull;

                            layout.field.Height -= checkSizeFull;
                            break;

                        case ContentAlignment.MiddleCenter:
                            layout.checkArea = layout.checkBounds;
                            break;
                    }

                    layout.checkBounds.Width -= checkPaddingSize;
                    layout.checkBounds.Height -= checkPaddingSize;
                }
            }
 private void DrawImage(Graphics graphics, LayoutData layout)
 {
     if (this.Control.Image != null)
     {
         this.DrawImageCore(graphics, this.Control.Image, layout.imageBounds, layout.imageStart, layout);
     }
 }
示例#53
0
        protected void DrawCheckOnly(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, bool disabledColors) {

            // check
            //
            if (Control.Checked) {
                if (!Control.Enabled && disabledColors) {
                    checkColor = SystemColors.ControlDark;
                }

		float scale = GetDpiScaleRatio(e.Graphics);
                using( WindowsGraphics wg = WindowsGraphics.FromGraphics(e.Graphics) ) {
                    using (WindowsBrush brush = new WindowsSolidBrush(wg.DeviceContext, checkColor)) {
                        // circle drawing doesn't work at this size
                        int offset = 5;                                                                   
                        Rectangle vCross = new Rectangle (layout.checkBounds.X + GetScaledNumber(offset, scale), layout.checkBounds.Y + GetScaledNumber(offset - 1, scale), GetScaledNumber(2, scale), GetScaledNumber(4, scale));
                        wg.FillRectangle(brush, vCross);
                        Rectangle hCross = new Rectangle (layout.checkBounds.X + GetScaledNumber(offset - 1, scale), layout.checkBounds.Y + GetScaledNumber(offset, scale), GetScaledNumber(4, scale), GetScaledNumber(2, scale));
                        wg.FillRectangle(brush, hCross);
                    }
                }
            }
        }
示例#54
0
            internal void LayoutTextAndImage(LayoutData layout) {
                // Translate for Rtl applications.  This intentially shadows the member variables.
                ContentAlignment imageAlign = RtlTranslateContent(this.imageAlign);
                ContentAlignment textAlign = RtlTranslateContent(this.textAlign);
                TextImageRelation textImageRelation = RtlTranslateRelation(this.textImageRelation);

                // Figure out the maximum bounds for text & image
                Rectangle maxBounds = Rectangle.Inflate(layout.field, -textImageInset, -textImageInset);
                if(OnePixExtraBorder) {
                    maxBounds.Inflate(1, 1);
                }

                // Compute the final image and text bounds.
                if(imageSize == Size.Empty || text == null || text.Length == 0 || textImageRelation == TextImageRelation.Overlay) {
                    // Do not worry about text/image overlaying
                    Size textSize = GetTextSize(maxBounds.Size);

                    // FOR EVERETT COMPATIBILITY - DO NOT CHANGE
                    Size size = imageSize;
                    if (layout.options.everettButtonCompat && imageSize != Size.Empty) {
                        size = new Size(size.Width + 1, size.Height + 1);
                    }
                    
                    layout.imageBounds = LayoutUtils.Align(size, maxBounds, imageAlign);
                    layout.textBounds = LayoutUtils.Align(textSize, maxBounds, textAlign);

                } else {
                    // Rearrage text/image to prevent overlay.  Pack text into maxBounds - space reserved for image
                    Size maxTextSize = LayoutUtils.SubAlignedRegion(maxBounds.Size, imageSize, textImageRelation);
                    Size textSize = GetTextSize(maxTextSize);
                    Rectangle maxCombinedBounds = maxBounds;

                    // Combine text & image into one rectangle that we center within maxBounds.
                    Size combinedSize = LayoutUtils.AddAlignedRegion(textSize, imageSize, textImageRelation);
                    maxCombinedBounds.Size = LayoutUtils.UnionSizes(maxCombinedBounds.Size, combinedSize);
                    Rectangle combinedBounds = LayoutUtils.Align(combinedSize, maxCombinedBounds, ContentAlignment.MiddleCenter);

                    // imageEdge indicates whether the combination of imageAlign and textImageRelation place
                    // the image along the edge of the control.  If so, we can increase the space for text.
                    bool imageEdge = (AnchorStyles)(ImageAlignToRelation(imageAlign) & textImageRelation) != AnchorStyles.None;

                    // textEdge indicates whether the combination of textAlign and textImageRelation place
                    // the text along the edge of the control.  If so, we can increase the space for image.
                    bool textEdge = (AnchorStyles)(TextAlignToRelation(textAlign) & textImageRelation) != AnchorStyles.None;

                    if(imageEdge) {
                        // If imageEdge, just split imageSize off of maxCombinedBounds.
                        LayoutUtils.SplitRegion(maxCombinedBounds, imageSize, (AnchorStyles) textImageRelation, out layout.imageBounds, out layout.textBounds);
                    } else if(textEdge) {
                        // Else if textEdge, just split textSize off of maxCombinedBounds.
                        LayoutUtils.SplitRegion(maxCombinedBounds, textSize, (AnchorStyles) LayoutUtils.GetOppositeTextImageRelation(textImageRelation), out layout.textBounds, out layout.imageBounds);
                    } else {                        
                        // Expand the adjacent regions to maxCombinedBounds (centered) and split the rectangle into imageBounds and textBounds.
                        LayoutUtils.SplitRegion(combinedBounds, imageSize, (AnchorStyles) textImageRelation, out layout.imageBounds, out layout.textBounds);
                        LayoutUtils.ExpandRegionsToFillBounds(maxCombinedBounds, (AnchorStyles) textImageRelation, ref layout.imageBounds, ref layout.textBounds);
                    }

                    // align text/image within their regions.
                    layout.imageBounds = LayoutUtils.Align(imageSize, layout.imageBounds, imageAlign);
                    layout.textBounds = LayoutUtils.Align(textSize, layout.textBounds, textAlign);
                }
                 
                //Don't call "layout.imageBounds = Rectangle.Intersect(layout.imageBounds, maxBounds);"
                // because that is a breaking change that causes images to be scaled to the dimensions of the control.
                //adjust textBounds so that the text is still visible even if the image is larger than the button's size
                //fixes Whidbey 234985
                //why do we intersect with layout.field for textBounds while we intersect with maxBounds for imageBounds?
                //this is because there are some legacy code which squeezes the button so small that text will get clipped
                //if we intersect with maxBounds. Have to do this for backward compatibility.
                //See Whidbey 341480
                if (textImageRelation == TextImageRelation.TextBeforeImage || textImageRelation == TextImageRelation.ImageBeforeText) {
                    //adjust the vertical position of textBounds so that the text doesn't fall off the boundary of the button
                    int textBottom = Math.Min(layout.textBounds.Bottom, layout.field.Bottom);
                    layout.textBounds.Y = Math.Max(Math.Min(layout.textBounds.Y, layout.field.Y + (layout.field.Height - layout.textBounds.Height)/2), layout.field.Y);
                    layout.textBounds.Height = textBottom - layout.textBounds.Y;
                }
                if (textImageRelation == TextImageRelation.TextAboveImage || textImageRelation == TextImageRelation.ImageAboveText) {
                    //adjust the horizontal position of textBounds so that the text doesn't fall off the boundary of the button
                    int textRight = Math.Min(layout.textBounds.Right, layout.field.Right);
                    layout.textBounds.X = Math.Max(Math.Min(layout.textBounds.X, layout.field.X + (layout.field.Width - layout.textBounds.Width)/2), layout.field.X);
                    layout.textBounds.Width = textRight - layout.textBounds.X;
                }
                if (textImageRelation == TextImageRelation.ImageBeforeText && layout.imageBounds.Size.Width != 0) {
                    //squeezes imageBounds.Width so that text is visible
                    layout.imageBounds.Width = Math.Max(0, Math.Min(maxBounds.Width - layout.textBounds.Width, layout.imageBounds.Width));
                    layout.textBounds.X = layout.imageBounds.X + layout.imageBounds.Width;
                }
                if (textImageRelation == TextImageRelation.ImageAboveText && layout.imageBounds.Size.Height != 0) {
                    //squeezes imageBounds.Height so that the text is visible
                    layout.imageBounds.Height = Math.Max(0, Math.Min(maxBounds.Height - layout.textBounds.Height, layout.imageBounds.Height));
                    layout.textBounds.Y = layout.imageBounds.Y + layout.imageBounds.Height;
                }
                //make sure that textBound is contained in layout.field
                layout.textBounds = Rectangle.Intersect(layout.textBounds, layout.field);
                if (hintTextUp) {
                    layout.textBounds.Y--;
                }
                if (textOffset) {
                    layout.textBounds.Offset(1, 1);
                }
                
                // FOR EVERETT COMPATIBILITY - DO NOT CHANGE
                if (layout.options.everettButtonCompat) {
                    layout.imageStart = layout.imageBounds.Location;
                    layout.imageBounds = Rectangle.Intersect(layout.imageBounds, layout.field);
                }
                else if (!Application.RenderWithVisualStyles) {
                    // Not sure why this is here, but we can't remove it, since it might break
                    // ToolStrips on non-themed machines
                    layout.textBounds.X++;
                }

                // clip
                //
                int bottom;
                // If we are using GDI to measure text, then we can get into a situation, where
                // the proposed height is ignore. In this case, we want to clip it against
                // maxbounds. VSWhidbey #480670
                if (!useCompatibleTextRendering) {
                    bottom = Math.Min(layout.textBounds.Bottom, maxBounds.Bottom);
                    layout.textBounds.Y = Math.Max(layout.textBounds.Y, maxBounds.Y);
                }
                else {
                    // If we are using GDI+ (like Everett), then use the old Everett code
                    // This ensures that we have pixel-level rendering compatibility
                    bottom = Math.Min(layout.textBounds.Bottom, layout.field.Bottom);
                    layout.textBounds.Y = Math.Max(layout.textBounds.Y, layout.field.Y);
                }
                layout.textBounds.Height = bottom - layout.textBounds.Y;                
                
                //This causes a breaking change because images get shrunk to the new clipped size instead of clipped.
                //********** bottom = Math.Min(layout.imageBounds.Bottom, maxBounds.Bottom);
                //********** layout.imageBounds.Y = Math.Max(layout.imageBounds.Y, maxBounds.Y);
                //********** layout.imageBounds.Height = bottom - layout.imageBounds.Y;                

            }
示例#55
0
 protected void DrawCheckFlat(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, Color checkBorder) {
     DrawCheckBackgroundFlat(e, layout.checkBounds, checkBorder, checkBackground, true);
     DrawCheckOnly(e, layout, checkColor, checkBackground, true);
 }
示例#56
0
 /// <devdoc>
 ///     Draws the button's image.
 /// </devdoc>
 void DrawImage(Graphics graphics, LayoutData layout) {
     if (Control.Image != null) {
         //setup new clip region & draw
         DrawImageCore(graphics, Control.Image, layout.imageBounds, layout.imageStart, layout);
     }
 }
示例#57
0
        internal override void PaintUp(PaintEventArgs e, CheckState state)
        {
            bool hasCustomBorder = Control.FlatAppearance.BorderSize != BorderSize || !Control.FlatAppearance.BorderColor.IsEmpty;

            ColorData  colors = PaintFlatRender(e).Calculate();
            LayoutData layout = PaintFlatLayout(
                up: !Control.FlatAppearance.CheckedBackColor.IsEmpty ||
                (SystemInformation.HighContrast ? state != CheckState.Indeterminate : state == CheckState.Unchecked),
                check: !hasCustomBorder && SystemInformation.HighContrast && state == CheckState.Checked,
                Control.FlatAppearance.BorderSize).Layout();

            // Paint with the BorderColor if set.
            if (!Control.FlatAppearance.BorderColor.IsEmpty)
            {
                colors.WindowFrame = Control.FlatAppearance.BorderColor;
            }

            Rectangle r = Control.ClientRectangle;

            Color backColor = Control.BackColor;

            if (!Control.FlatAppearance.CheckedBackColor.IsEmpty)
            {
                switch (state)
                {
                case CheckState.Checked:
                    backColor = Control.FlatAppearance.CheckedBackColor;
                    break;

                case CheckState.Indeterminate:
                    backColor = Control.FlatAppearance.CheckedBackColor.MixColor(colors.ButtonFace);
                    break;
                }
            }
            else
            {
                switch (state)
                {
                case CheckState.Checked:
                    backColor = colors.Highlight;
                    break;

                case CheckState.Indeterminate:
                    backColor = colors.Highlight.MixColor(colors.ButtonFace);
                    break;
                }
            }

            PaintBackground(e, r, IsHighContrastHighlighted() ? SystemColors.Highlight : backColor);

            if (Control.IsDefault)
            {
                r.Inflate(-1, -1);
            }

            PaintImage(e, layout);
            PaintField(e, layout, colors, IsHighContrastHighlighted() ? SystemColors.HighlightText : colors.WindowText, false);

            if (Control.Focused && Control.ShowFocusCues)
            {
                DrawFlatFocus(e, layout.Focus, colors.Options.HighContrast ? colors.WindowText : colors.ConstrastButtonShadow);
            }

            if (!(Control.IsDefault && Control.Focused && (Control.FlatAppearance.BorderSize == 0)))
            {
                DrawDefaultBorder(e, r, colors.WindowFrame, Control.IsDefault);
            }

            // Always check if the BorderSize is not the default.If not, we need to paint with the BorderSize set by the user.
            if (hasCustomBorder)
            {
                if (Control.FlatAppearance.BorderSize != BorderSize)
                {
                    DrawFlatBorderWithSize(e, r, colors.WindowFrame, Control.FlatAppearance.BorderSize);
                }
                else
                {
                    ControlPaint.DrawBorderSimple(e, r, colors.WindowFrame);
                }
            }
            else if (state == CheckState.Checked && SystemInformation.HighContrast)
            {
                ControlPaint.DrawBorderSimple(e, r, colors.WindowFrame);
                ControlPaint.DrawBorderSimple(e, r, colors.ButtonShadow);
            }
            else if (state == CheckState.Indeterminate)
            {
                Draw3DLiteBorder(e, r, colors, false);
            }
            else
            {
                ControlPaint.DrawBorderSimple(e, r, colors.WindowFrame);
            }
        }
示例#58
0
        // here for DropDownButton
        internal virtual void DrawImageCore(Graphics graphics, Image image, Rectangle imageBounds, Point imageStart, LayoutData layout) {
            Region oldClip = graphics.Clip;
            
            if (!layout.options.everettButtonCompat) { // FOR EVERETT COMPATIBILITY - DO NOT CHANGE
                Rectangle bounds = new Rectangle(buttonBorderSize, buttonBorderSize, this.Control.Width - (2 * buttonBorderSize), this.Control.Height - (2 * buttonBorderSize));

                Region newClip = oldClip.Clone();
                newClip.Intersect(bounds);

                // If we don't do this, DrawImageUnscaled will happily draw the entire image, even though imageBounds
                // is smaller than the image size.
                newClip.Intersect(imageBounds);
                graphics.Clip = newClip;
            }
            else {
                // FOR EVERETT COMPATIBILITY - DO NOT CHANGE
                imageBounds.Width += 1;
                imageBounds.Height +=1;
                imageBounds.X = imageStart.X + 1;
                imageBounds.Y = imageStart.Y + 1;
            }


            try {
                if (!Control.Enabled)
                    // need to specify width and height
                    ControlPaint.DrawImageDisabled(graphics, image, imageBounds, Control.BackColor, true /* unscaled image*/);
                else {
                    graphics.DrawImage(image, imageBounds.X, imageBounds.Y, image.Width, image.Height);
                }
            }

            finally {
                if (!layout.options.everettButtonCompat) {// FOR EVERETT COMPATIBILITY - DO NOT CHANGE                              
                    graphics.Clip = oldClip;
                }
            }
        }
示例#59
0
 internal override void DrawImageCore(Graphics graphics, Image image, Rectangle imageBounds, Point imageStart, LayoutData layout)
 {
     ControlPaint.DrawImageReplaceColor(graphics, image, imageBounds, Color.Black, IsHighContrastHighlighted() && !Control.MouseIsDown ? SystemColors.HighlightText : Control.ForeColor);
 }
示例#60
0
        /// <devdoc>
        ///     Draws the button's text.
        /// </devdoc>
        void DrawText(Graphics g, LayoutData layout, Color c, ColorData colors)
        {
            Rectangle r = layout.textBounds;
            bool disabledText3D = layout.options.shadowedText;

            if (Control.UseCompatibleTextRendering) { // Draw text using GDI+
                using (StringFormat stringFormat = CreateStringFormat()) {
                    // DrawString doesn't seem to draw where it says it does
                    if ((Control.TextAlign & LayoutUtils.AnyCenter) == 0) {
                        r.X -= 1;
                    }
                    r.Width += 1;

                    if (disabledText3D && !Control.Enabled) {
                        r.Offset(1, 1);
                        using (SolidBrush brush = new SolidBrush(colors.highlight)) {
                            g.DrawString(Control.Text, Control.Font, brush, r, stringFormat);

                            r.Offset(-1, -1);
                            brush.Color = colors.buttonShadow;
                            g.DrawString(Control.Text, Control.Font, brush, r, stringFormat);
                        }
                    }
                    else {
                        Brush brush;

                        if (c.IsSystemColor) {
                            brush = SystemBrushes.FromSystemColor(c);
                        }
                        else {
                            brush = new SolidBrush(c);
                        }
                        g.DrawString(Control.Text, Control.Font, brush, r, stringFormat);

                        if (!c.IsSystemColor) {
                            brush.Dispose();
                        }
                    }
                }
            }
            else { // Draw text using GDI (Whidbey feature).
                TextFormatFlags formatFlags = CreateTextFormatFlags();

                if (disabledText3D && !Control.Enabled) {
                    if (Application.RenderWithVisualStyles) {
                        //don't draw chiseled text if themed as win32 app does.
                        TextRenderer.DrawText(g, Control.Text, Control.Font, r, colors.buttonShadow, formatFlags);
                    }
                    else {
                        r.Offset(1, 1);
                        TextRenderer.DrawText(g, Control.Text, Control.Font, r, colors.highlight, formatFlags);

                        r.Offset(-1, -1);
                        TextRenderer.DrawText(g, Control.Text, Control.Font, r, colors.buttonShadow, formatFlags);
                    }
                }
                else {
                    TextRenderer.DrawText(g, Control.Text, Control.Font, r, c, formatFlags);
                }
            }
        }