Ejemplo n.º 1
0
        //TODO: Kaushal. When the rendering code will be moved from MgUtils to MgControls,
        //the scope of many methods in this class should be changed to private.

        /// <summary>
        /// paint background of control
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rect"></param>
        /// <param name="bgColor"></param>
        /// <param name="fgColor"></param>
        /// <param name="style"></param>
        /// <param name="textBoxBorder"></param>
        /// <param name="gradientColor"></param>
        /// <param name="gradientStyle"></param>
        /// <param name="borderType"></param>
        /// <returns></returns>
        public static Rectangle FillRectAccordingToGradientStyle(Graphics g, Rectangle rect, Color bgColor, Color fgColor,
                                                                 ControlStyle style, bool textBoxBorder, GradientColor gradientColor,
                                                                 GradientStyle gradientStyle, BorderType borderType = BorderType.Thin)
        {
            if (gradientStyle == GradientStyle.None)
            {
                PaintBackGround(g, rect, bgColor, true);
            }
            else
            {
                PaintBackGroundGradient(g, rect, bgColor, fgColor, style, textBoxBorder,
                                        gradientColor, gradientStyle, false, 0);
            }

            BorderRenderer.PaintBorder(g, rect, fgColor, style, textBoxBorder, borderType);

            return(rect);
        }
Ejemplo n.º 2
0
        /// <summary>paint the backround button</summary>
        /// <param name="mgButton"></param>
        /// <param name="e"></param>
        private static void PaintBackground(Control buttonBase, PaintEventArgs e)
        {
            Rectangle displayRect = buttonBase.ClientRectangle;

            // when button is image , the display rect is on all the button, else the display rect is on the tect rect
            if (!ControlUtils.IsImageButton(buttonBase))
            {
                displayRect = GetTextRect(buttonBase);
            }

            ControlRenderer.PaintBackgoundColorAndImage(buttonBase, e.Graphics, false, displayRect);

#if PocketPC
            // Draw the border for the button-appearance checkbox
            if (buttonBase is MgCheckBox)
            {
                Rectangle rect = buttonBase.ClientRectangle;
                rect.Inflate(-1, -1);
                Color        fgColor     = buttonBase.ForeColor;
                ControlStyle borderStyle = (((MgCheckBox)buttonBase).CheckState == CheckState.Unchecked) ? ControlStyle.ThreeD : ControlStyle.TwoD;
                BorderRenderer.PaintBorder(e.Graphics, rect, fgColor, borderStyle, false);
            }
#endif
        }
Ejemplo n.º 3
0
        /// <summary></summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            //For Desktop:
            //Always call base.OnPaint() to let the Framework render the border and the box.
            //Image is always to be rendered by the Framework.
            //If Image is not available, then only...
            //1. Appearance=Normal, just draw the text.
            //2. Appearance=Button, paint the background and text.

            //Since we do not want the Framework to paint the Text, set it to "" (blank) before calling base.OnPaint() and
            //reset it later.
            String orgText = Text;

            TextToDisplay = Text;
            base.Text     = String.Empty;

            if (BackColor == Color.Transparent && Parent is ISupportsTransparentChildRendering)
            {
                ((ISupportsTransparentChildRendering)Parent).TransparentChild = this;
            }

            base.OnPaint(e);

            if (BackColor == Color.Transparent && Parent is ISupportsTransparentChildRendering)
            {
                ((ISupportsTransparentChildRendering)Parent).TransparentChild = null;
            }

            base.Text = orgText;
            //Since we are modifying the Text, we need to Validate the Rect. Otherwise, the paint will go in recursion.
            win32.NativeWindowCommon.ValidateRect(this.Handle, IntPtr.Zero);

            if (Image == null)
            {
                if (Appearance == Appearance.Normal)
                {
                    Rectangle textRect = new Rectangle();
                    textRect = ClientRectangle;
                    //Padding also includes the padding set for the BOX. But it is not needed while rendering the text.
                    //So, ignore it.
                    textRect.Location = new Point(textRect.Left + Padding.Left, textRect.Top + Padding.Top - checkTopPadding);
                    textRect.Size     = new Size(textRect.Width - (Padding.Left + Padding.Right), textRect.Height - (Padding.Top + Padding.Bottom - checkTopPadding));

                    CheckBoxAndRadioButtonRenderer.DrawTextAndFocusRect(this, e, TextToDisplay, textRect, textOffset);
                }
                else
                {
                    ButtonRenderer.DrawButton(this, e, true, true);
                }
            }
            else
            {
                if (Focused && Appearance == Appearance.Normal)
                {
                    CheckBoxAndRadioButtonRenderer.DrawFocusRectOnCheckBoxGlyph(this, e.Graphics);
                }
            }

            // paint the border
            if (BorderType != BorderType.NoBorder)
            {
                BorderRenderer.PaintBorder(e.Graphics, ClientRectangle, ForeColor, ControlStyle.TwoD, false, BorderType);
            }
        }
Ejemplo n.º 4
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == NativeWindowCommon.WM_IME_COMPOSITION)
            {
                switch (CultureInfo.CurrentCulture.LCID)
                {
                case 1041: // Japanese (JPN: ZIMERead function)
                    if (((int)m.LParam & NativeWindowCommon.GCS_RESULTREADSTR) > 0)
                    {
                        int hIMC = NativeWindowCommon.ImmGetContext(this.Handle);

                        try
                        {
                            int size = NativeWindowCommon.ImmGetCompositionString(hIMC, NativeWindowCommon.GCS_RESULTREADSTR, null, 0);

                            StringBuilder buffer = new StringBuilder(size);
                            NativeWindowCommon.ImmGetCompositionString(hIMC, NativeWindowCommon.GCS_RESULTREADSTR, buffer, (uint)size);
                            string str = buffer.ToString().Substring(0, size / 2);
                            ImeReadStrBuilder.Append(str);
                        }
                        finally
                        {
                            NativeWindowCommon.ImmReleaseContext(this.Handle, hIMC);
                        }
                    }
                    break;

                case 1042: // Korean
                    if (KoreanInterimSel < 0)
                    {
                        KoreanInterimSel = NativeWindowCommon.SendMessage(this.Handle, NativeWindowCommon.EM_GETSEL, 0, 0);
                    }
                    break;
                }
            }
            else if (m.Msg == NativeWindowCommon.WM_IME_ENDCOMPOSITION)
            {
                if (CultureInfo.CurrentCulture.LCID == 1042)
                {
                    KoreanInterimSel = -1;
                }
            }
            else if (m.Msg == NativeWindowCommon.WM_PAINT)
            {
                if (isTransparent)
                {
                    NativeWindowCommon.SendMessage(this.Handle, NativeWindowCommon.WM_NCPAINT, 0, 0);
                }

                if (ControlStyle == ControlStyle.ThreeD)
                {
                    base.WndProc(ref m);
                    using (Graphics g = Graphics.FromHwnd(this.Handle))
                    {
                        BorderRenderer.PaintBorder(g, ClientRectangle, ForeColor, ControlStyle.ThreeD, false);
                        return;
                    }
                }
            }
            else if (m.Msg == NativeWindowCommon.WM_NCCALCSIZE)
            {
                if (BorderStyle == BorderStyle.FixedSingle)
                {
                    RecalcNonClientArea(ref m);
                }
            }
            else if (m.Msg == NativeWindowCommon.WM_NCPAINT)
            {
                if (BorderStyle == BorderStyle.FixedSingle)
                {
                    WMNCPaint(ref m);
                }
            }
            base.WndProc(ref m);
        }