Example #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            //Simulate Transparency
            if (BackColor == Color.Transparent)
            {
#if !PocketPC
                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = this;
                }

                System.Drawing.Drawing2D.GraphicsContainer g = e.Graphics.BeginContainer();
                Rectangle translateRect = this.Bounds;
                e.Graphics.TranslateTransform(-Left, -Top);
                PaintEventArgs pe = new PaintEventArgs(e.Graphics, translateRect);
                this.InvokePaintBackground(Parent, pe);
                this.InvokePaint(Parent, pe);
                //fixed bug#:796041, the forgound not need to display
                //this.InvokePaint(Parent, pe);
                e.Graphics.ResetTransform();
                e.Graphics.EndContainer(g);
                pe.Dispose();

                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = null;
                }
#endif
            }

            ControlRenderer.FillRectAccordingToGradientStyle(e.Graphics, ClientRectangle, BackColor, LinkColor, 0,
                                                             false, GradientColor, GradientStyle);

            ContentAlignment newTextAlign = ControlUtils.GetOrgContentAligment(RightToLeft, TextAlign);

            FontDescription font = new FontDescription(Font);
            ControlRenderer.PrintText(e.Graphics, ClientRectangle, LinkColor, font, Text, false, newTextAlign,
                                      Enabled, true, !UseMnemonic, false, (RightToLeft == RightToLeft.Yes));

            //fixed bug #:765815 : when parking on hypertext button,focus need to seen on text on the button (not on  entire button)
            if (Focused)
            {
                Size textExt = Utils.GetTextExt(Font, Text, this);
                // get the display the focus on the text of the control
                Rectangle textRect = ControlUtils.GetFocusRect(this, ClientRectangle, newTextAlign, textExt);
                //ass offset, it will look as in online
                textRect.Inflate(2, 2);
                textRect.Width  -= 2;
                textRect.Height -= 1;

                textRect.X      = Math.Max(1, textRect.X);
                textRect.Y      = Math.Max(1, textRect.Y);
                textRect.Width  = Math.Min(textRect.Width, ClientRectangle.Width - textRect.X);
                textRect.Height = Math.Min(textRect.Height, ClientRectangle.Height - textRect.Y);

                ControlPaint.DrawFocusRectangle(e.Graphics, textRect);
            }
        }
Example #2
0
        /// <summary>paint the push button control
        /// Can be called from :
        /// 1. push control with property 'ButtonStyle' = button
        /// 2. CheckBox control with property appearance = button
        /// 3. Radio control with property appearance = button
        /// </summary>
        /// <param name="mgButton"></param>
        /// <param name="e"></param>
        private static void DrawText(Control control, PaintEventArgs e)
        {
            Debug.Assert(control.Visible);
            bool             restoreClip = false;
            Region           r           = e.Graphics.Clip;
            bool             isImage     = false;
            ContentAlignment textAlign   = ContentAlignment.MiddleLeft;
            RightToLeft      rightToLeft = RightToLeft.No;

            String Text = ((IDisplayInfo)control).TextToDisplay;

            if (Text == null)
            {
                return;
            }

            Rectangle displayRect = control.ClientRectangle;

#if PocketPC
            if (control is MgButtonBase)
            {
                isImage     = ((MgButtonBase)control).BackgroundImage != null;
                textAlign   = ((MgButtonBase)control).TextAlign;
                rightToLeft = ((MgButtonBase)control).RightToLeft;
            }
            else if (control is MgCheckBox)
            {
                isImage     = ((MgCheckBox)control).Image != null;
                textAlign   = ((MgCheckBox)control).TextAlign;
                rightToLeft = ((MgCheckBox)control).RightToLeft;
            }
            else
            {
                Debug.Assert(false);
            }
#else
            if (control is ButtonBase)
            {
                if (control is IImageProperty)
                {
                    isImage = ((IImageProperty)control).Image != null;
                }
                else
                {
                    isImage = ((ButtonBase)control).BackgroundImage != null;
                }

                textAlign   = ((ButtonBase)control).TextAlign;
                rightToLeft = ((ButtonBase)control).RightToLeft;
            }
            else
            {
                Debug.Assert(false);
            }
#endif

            // The runtime engine sends the alignment in reverse order if rightToLeft=Yes.
            // This is because the .net framework need it to be in the reverse order when rightToLeft=Yes.
            // So, when we paint the control, we should convert it back to the original alignment.
            textAlign = ControlUtils.GetOrgContentAligment(rightToLeft, textAlign);

            if (!isImage)
            {
                //2. get the display rect
                displayRect = GetTextRect(control);
                if (control is MgPushButton)
                {
                    restoreClip = true;
                    using (Region TextRegion = new Region(displayRect))
                    {
                        e.Graphics.Clip = TextRegion;
                    }
                }
            }

            bool isMultiLine = ControlUtils.GetIsMultiLine(control);
            bool RTL         = rightToLeft == RightToLeft.Yes ? true : false;
            //4. display the text of the control

            FontDescription font = new FontDescription(control.Font);
            ControlRenderer.PrintText(e.Graphics, displayRect, control.ForeColor, font, Text, isMultiLine,
                                      textAlign, control.Enabled, false, false, false, RTL, true);
            if (restoreClip)
            {
                e.Graphics.Clip = r;
            }

            //focus rect should not be drawn for image button.
            if (!ControlUtils.IsImageButton(control))
            {
                if (control.Focused)
                {
                    displayRect.Inflate(-1, -1);
                    ControlPaint.DrawFocusRectangle(e.Graphics, displayRect);
                }
            }
        }