protected override void OnPaint(PaintEventArgs e)
		{
			Graphics g = e.Graphics;
			if(g == null) { base.OnPaint(e); return; }

			int nNormalizedPos = m_nPosition - m_nMinimum;
			int nNormalizedMax = m_nMaximum - m_nMinimum;

			Rectangle rectClient = this.ClientRectangle;
			Rectangle rectDraw;
			if(VisualStyleRenderer.IsSupported)
			{
				VisualStyleRenderer vsr = new VisualStyleRenderer(
					VisualStyleElement.ProgressBar.Bar.Normal);
				vsr.DrawBackground(g, rectClient);

				rectDraw = vsr.GetBackgroundContentRectangle(g, rectClient);
			}
			else
			{
				g.FillRectangle(SystemBrushes.Control, rectClient);

				g.DrawLine(Pens.Gray, 0, 0, rectClient.Width - 1, 0);
				g.DrawLine(Pens.Gray, 0, 0, 0, rectClient.Height - 1);
				g.DrawLine(Pens.White, rectClient.Width - 1, 0,
					rectClient.Width - 1, rectClient.Height - 1);
				g.DrawLine(Pens.White, 0, rectClient.Height - 1,
					rectClient.Width - 1, rectClient.Height - 1);

				rectDraw = new Rectangle(rectClient.X + 1, rectClient.Y + 1,
					rectClient.Width - 2, rectClient.Height - 2);
			}

			Rectangle rectGradient = new Rectangle(rectDraw.X, rectDraw.Y,
				rectDraw.Width, rectDraw.Height);
			if((rectGradient.Width & 1) == 0) ++rectGradient.Width;

			int nDrawWidth = (int)((float)rectDraw.Width * ((float)nNormalizedPos /
				(float)nNormalizedMax));

			Color clrStart = Color.FromArgb(255, 128, 0);
			Color clrEnd = Color.FromArgb(0, 255, 0);

			bool bRtl = (this.RightToLeft == RightToLeft.Yes);
			if(bRtl)
			{
				Color clrTemp = clrStart;
				clrStart = clrEnd;
				clrEnd = clrTemp;
			}
			
			using(LinearGradientBrush brush = new LinearGradientBrush(rectGradient,
				clrStart, clrEnd, LinearGradientMode.Horizontal))
			{
				g.FillRectangle(brush, (bRtl ? (rectDraw.Width - nDrawWidth + 1) :
					rectDraw.Left), rectDraw.Top, nDrawWidth, rectDraw.Height);
			}
		}
示例#2
0
        /// <summary>
        /// Paints the background.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            switch (_borderStyle)
            {
                case BorderStyle.Fixed3D:
                    {
                        if (TextBoxRenderer.IsSupported)
                        {
                            VisualStyleElement state = VisualStyleElement.TextBox.TextEdit.Normal;
                            Color backColor = BackColor;

                            if (Enabled)
                            {
                                if (ReadOnly)
                                    state = VisualStyleElement.TextBox.TextEdit.ReadOnly;
                                else if (Focused)
                                    state = VisualStyleElement.TextBox.TextEdit.Focused;
                            }
                            else
                            {
                                state = VisualStyleElement.TextBox.TextEdit.Disabled;
                                backColor = BackColorDisabled;
                            }

                            var vsr = new VisualStyleRenderer(state);
                            vsr.DrawBackground(pevent.Graphics, ClientRectangle);

                            Rectangle rectContent = vsr.GetBackgroundContentRectangle(pevent.Graphics, ClientRectangle);
                            pevent.Graphics.FillRectangle(new SolidBrush(backColor), rectContent);
                        }
                        else
                        {
                            // draw background
                            pevent.Graphics.FillRectangle(new SolidBrush(BackColor), ClientRectangle);

                            // draw default border
                            ControlPaint.DrawBorder3D(pevent.Graphics, ClientRectangle, Border3DStyle.Sunken);
                        }

                        break;
                    }
                case BorderStyle.FixedSingle:
                    {
                        // draw background
                        pevent.Graphics.FillRectangle(new SolidBrush(BackColor), ClientRectangle);

                        // draw fixed single border
                        ControlPaint.DrawBorder(pevent.Graphics, ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
                        break;
                    }
            }
        }
示例#3
0
        /// <summary>
        /// Paints the background.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaintBackground( PaintEventArgs e )
        {
            if( _vertGridPen == null )
                this.SetupGraphics();

            switch( _borderStyle )
            {
                case BorderStyle.Fixed3D:
                    {
                        if( TextBoxRenderer.IsSupported )
                        {
                            VisualStyleElement state = VisualStyleElement.TextBox.TextEdit.Normal;
                            Color backColor = this.BackColor;

                            if( this.Enabled )
                            {
                                if( this.ReadOnly )
                                    state = VisualStyleElement.TextBox.TextEdit.ReadOnly;
                                else if( this.Focused )
                                    state = VisualStyleElement.TextBox.TextEdit.Focused;
                            }
                            else
                            {
                                state = VisualStyleElement.TextBox.TextEdit.Disabled;
                                backColor = this.BackColorDisabled;
                            }

                            VisualStyleRenderer vsr = new VisualStyleRenderer( state );
                            vsr.DrawBackground( e.Graphics, this.ClientRectangle );

                            Rectangle rectContent = vsr.GetBackgroundContentRectangle( e.Graphics, this.ClientRectangle );
                            e.Graphics.FillRectangle( new SolidBrush( backColor ), rectContent );
                            this.DrawShared( e );
                        }
                        else
                        {
                            // draw background
                            e.Graphics.FillRectangle( new SolidBrush( BackColor ), ClientRectangle );
                            this.DrawShared( e );

                            // draw default border
                            ControlPaint.DrawBorder3D( e.Graphics, ClientRectangle, Border3DStyle.Sunken );
                        }

                        break;
                    }
                case BorderStyle.FixedSingle:
                    {
                        // draw background
                        e.Graphics.FillRectangle( new SolidBrush( BackColor ), ClientRectangle );
                        this.DrawShared( e );

                        // draw fixed single border
                        ControlPaint.DrawBorder( e.Graphics, ClientRectangle, Color.Black, ButtonBorderStyle.Solid );
                        break;
                    }
            }
        }
示例#4
0
        protected override void OnPaintBackground( PaintEventArgs e )
        {
            Brush backBrush = ( this.Enabled == true ) ? _instrBrush : _vizBrush;

            if( TextBoxRenderer.IsSupported )
            {
                VisualStyleElement state = ( this.Enabled == true ) ? VisualStyleElement.TextBox.TextEdit.Normal : VisualStyleElement.TextBox.TextEdit.Disabled;
                VisualStyleRenderer vsr = new VisualStyleRenderer( state );
                vsr.DrawBackground( e.Graphics, this.ClientRectangle );

                Rectangle rectContent = vsr.GetBackgroundContentRectangle( e.Graphics, this.ClientRectangle );
                e.Graphics.FillRectangle( backBrush, rectContent );
                this.DrawShared( e );
            }
            else
            {
                e.Graphics.FillRectangle( backBrush, this.ClientRectangle );
                this.DrawShared( e );

                ControlPaint.DrawBorder3D( e.Graphics, this.ClientRectangle, Border3DStyle.Sunken );
            }
        }
		public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
		{
			if (!RenderClientAreas ||
				!VisualStyleRenderer.IsElementDefined (VisualStyleElement.ProgressBar.Bar.Normal) ||
				!VisualStyleRenderer.IsElementDefined (VisualStyleElement.ProgressBar.Chunk.Normal)) {
				base.DrawProgressBar (dc, clip_rect, ctrl);
				return;
			}
			VisualStyleRenderer renderer = new VisualStyleRenderer (VisualStyleElement.ProgressBar.Bar.Normal);
			renderer.DrawBackground (dc, ctrl.ClientRectangle, clip_rect);
			Rectangle client_area = renderer.GetBackgroundContentRectangle (dc, new Rectangle (Point.Empty, ctrl.Size));
			renderer = new VisualStyleRenderer (VisualStyleElement.ProgressBar.Chunk.Normal);
			/* Draw Blocks */
			int draw_mode = 0;
			int max_blocks = int.MaxValue;
			int start_pixel = client_area.X;
#if NET_2_0
			draw_mode = (int)ctrl.Style;
#endif
			switch (draw_mode) {
#if NET_2_0
			case 1: // Continuous
				client_area.Width = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(Math.Max (ctrl.Maximum - ctrl.Minimum, 1))));
				renderer.DrawBackground (dc, client_area, clip_rect);
				break;
			case 2: // Marquee
				int ms_diff = (int)(DateTime.Now - ctrl.start).TotalMilliseconds;
				double percent_done = (double)ms_diff % (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
				max_blocks = 5;
				start_pixel = client_area.X + (int)(client_area.Width * percent_done);
				goto default;
#endif
			default: // Blocks
				int block_width = renderer.GetInteger (IntegerProperty.ProgressChunkSize);
				block_width = Math.Max (block_width, 0); // block_width is used to break out the loop below, it must be >= 0!
				int first_pixel_outside_filled_area = (int)(((double)(ctrl.Value - ctrl.Minimum) * client_area.Width) / (Math.Max (ctrl.Maximum - ctrl.Minimum, 1))) + client_area.X;
				int block_count = 0;
				int increment = block_width + renderer.GetInteger (IntegerProperty.ProgressSpaceSize);
				Rectangle block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height);
				while (true) {
					if (max_blocks != int.MaxValue) {
						if (block_count == max_blocks)
							break;
						if (block_rect.Right >= client_area.Width)
							block_rect.X -= client_area.Width;
					} else {
						if (block_rect.X >= first_pixel_outside_filled_area)
							break;
						if (block_rect.Right >= first_pixel_outside_filled_area)
							if (first_pixel_outside_filled_area == client_area.Right)
								block_rect.Width = first_pixel_outside_filled_area - block_rect.X;
							else
								break;
					}
					if (clip_rect.IntersectsWith (block_rect))
						renderer.DrawBackground (dc, block_rect, clip_rect);
					block_rect.X += increment;
					block_count++;
				}
				break;
			}
		}
示例#6
0
文件: HexBox.cs 项目: kaaLabs15/LoRa
 protected override void OnPaintBackground(PaintEventArgs e)
 {
     switch (_borderStyle)
     {
         case BorderStyle.FixedSingle:
             e.Graphics.FillRectangle((Brush)new SolidBrush(BackColor), ClientRectangle);
             ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
             break;
         case BorderStyle.Fixed3D:
             if (TextBoxRenderer.IsSupported)
             {
                 VisualStyleElement element = VisualStyleElement.TextBox.TextEdit.Normal;
                 Color color = BackColor;
                 if (Enabled)
                 {
                     if (ReadOnly)
                         element = VisualStyleElement.TextBox.TextEdit.ReadOnly;
                     else if (Focused)
                         element = VisualStyleElement.TextBox.TextEdit.Focused;
                 }
                 else
                 {
                     element = VisualStyleElement.TextBox.TextEdit.Disabled;
                     color = BackColorDisabled;
                 }
                 VisualStyleRenderer visualStyleRenderer = new VisualStyleRenderer(element);
                 visualStyleRenderer.DrawBackground((IDeviceContext)e.Graphics, ClientRectangle);
                 Rectangle contentRectangle = visualStyleRenderer.GetBackgroundContentRectangle((IDeviceContext)e.Graphics, ClientRectangle);
                 e.Graphics.FillRectangle((Brush)new SolidBrush(color), contentRectangle);
                 break;
             }
             e.Graphics.FillRectangle((Brush)new SolidBrush(BackColor), ClientRectangle);
             ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Sunken);
             break;
     }
 }
示例#7
0
        private void CalculateNonClientSize(ref Message m)
        {
            NativeMethods.NCCALCSIZE_PARAMS parameters;
            NativeMethods.RECT windowRect;

            ExtractParamsAndWindowRect(ref m, out parameters, out windowRect);
            var renderer = new VisualStyleRenderer(VisualStyleElement.TextBox.TextEdit.Normal);

            using (var deviceContext = new NativeMethods.DeviceContext(Handle))
            {
                var contentRect = new NativeMethods.RECT(
                    renderer.GetBackgroundContentRectangle(deviceContext, windowRect.ToRectangle()));
                contentRect.Inflate(-1, -1);

                _borderRect = new NativeMethods.RECT(
                    contentRect.Left - windowRect.Left,
                    contentRect.Top - windowRect.Top,
                    windowRect.Right - contentRect.Right,
                    windowRect.Bottom - contentRect.Bottom);

                if (m.WParam == IntPtr.Zero)
                    Marshal.StructureToPtr(contentRect, m.LParam, false);
                else
                {
                    parameters.rgrc0 = contentRect;
                    Marshal.StructureToPtr(parameters, m.LParam, false);
                }
            }

            m.Result = new IntPtr(NativeMethods.WVR_REDRAW);
        }
示例#8
0
        private void PaintPriv(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            if(g == null) { base.OnPaint(e); return; }

            int nNormPos = m_nPosition - m_nMinimum;
            int nNormMax = m_nMaximum - m_nMinimum;
            if(nNormMax <= 0) { Debug.Assert(false); nNormMax = 100; }
            if(nNormPos < 0) { Debug.Assert(false); nNormPos = 0; }
            if(nNormPos > nNormMax) { Debug.Assert(false); nNormPos = nNormMax; }

            Rectangle rectClient = this.ClientRectangle;
            Rectangle rectDraw;
            VisualStyleElement vse = VisualStyleElement.ProgressBar.Bar.Normal;
            if(VisualStyleRenderer.IsSupported &&
                VisualStyleRenderer.IsElementDefined(vse))
            {
                VisualStyleRenderer vsr = new VisualStyleRenderer(vse);

                if(vsr.IsBackgroundPartiallyTransparent())
                    vsr.DrawParentBackground(g, rectClient, this);

                vsr.DrawBackground(g, rectClient);

                rectDraw = vsr.GetBackgroundContentRectangle(g, rectClient);
            }
            else
            {
                g.FillRectangle(SystemBrushes.Control, rectClient);

                Pen penGray = SystemPens.ControlDark;
                Pen penWhite = SystemPens.ControlLight;
                g.DrawLine(penGray, 0, 0, rectClient.Width - 1, 0);
                g.DrawLine(penGray, 0, 0, 0, rectClient.Height - 1);
                g.DrawLine(penWhite, rectClient.Width - 1, 0,
                    rectClient.Width - 1, rectClient.Height - 1);
                g.DrawLine(penWhite, 0, rectClient.Height - 1,
                    rectClient.Width - 1, rectClient.Height - 1);

                rectDraw = new Rectangle(rectClient.X + 1, rectClient.Y + 1,
                    rectClient.Width - 2, rectClient.Height - 2);
            }

            int nDrawWidth = (int)((float)rectDraw.Width * (float)nNormPos /
                (float)nNormMax);

            Color clrStart = Color.FromArgb(255, 128, 0);
            Color clrEnd = Color.FromArgb(0, 255, 0);
            if(!this.Enabled)
            {
                clrStart = UIUtil.ColorToGrayscale(SystemColors.ControlDark);
                clrEnd = UIUtil.ColorToGrayscale(SystemColors.ControlLight);
            }

            bool bRtl = (this.RightToLeft == RightToLeft.Yes);
            if(bRtl)
            {
                Color clrTemp = clrStart;
                clrStart = clrEnd;
                clrEnd = clrTemp;
            }

            // Workaround for Windows <= XP
            Rectangle rectGrad = new Rectangle(rectDraw.X, rectDraw.Y,
                rectDraw.Width, rectDraw.Height);
            if(!WinUtil.IsAtLeastWindowsVista && !NativeLib.IsUnix())
                rectGrad.Inflate(1, 0);

            using(LinearGradientBrush brush = new LinearGradientBrush(rectGrad,
                clrStart, clrEnd, LinearGradientMode.Horizontal))
            {
                g.FillRectangle(brush, (bRtl ? (rectDraw.Width - nDrawWidth + 1) :
                    rectDraw.Left), rectDraw.Top, nDrawWidth, rectDraw.Height);
            }

            PaintText(g, rectDraw);
        }
示例#9
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            VisualStyleElement normal;
            Color backColor;
            switch (this._borderStyle)
            {
                case System.Windows.Forms.BorderStyle.FixedSingle:
                    e.Graphics.FillRectangle(new SolidBrush(this.BackColor), base.ClientRectangle);
                    ControlPaint.DrawBorder(e.Graphics, base.ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
                    return;

                case System.Windows.Forms.BorderStyle.Fixed3D:
                    if (!TextBoxRenderer.IsSupported)
                    {
                        e.Graphics.FillRectangle(new SolidBrush(this.BackColor), base.ClientRectangle);
                        ControlPaint.DrawBorder3D(e.Graphics, base.ClientRectangle, Border3DStyle.Sunken);
                        return;
                    }
                    normal = VisualStyleElement.TextBox.TextEdit.Normal;
                    backColor = this.BackColor;
                    if (!base.Enabled)
                    {
                        normal = VisualStyleElement.TextBox.TextEdit.Disabled;
                        backColor = this.BackColorDisabled;
                        break;
                    }
                    if (!this.ReadOnly)
                    {
                        if (this.Focused)
                        {
                            normal = VisualStyleElement.TextBox.TextEdit.Focused;
                        }
                        break;
                    }
                    normal = VisualStyleElement.TextBox.TextEdit.ReadOnly;
                    break;

                default:
                    return;
            }
            VisualStyleRenderer renderer = new VisualStyleRenderer(normal);
            renderer.DrawBackground(e.Graphics, base.ClientRectangle);
            Rectangle backgroundContentRectangle = renderer.GetBackgroundContentRectangle(e.Graphics, base.ClientRectangle);
            e.Graphics.FillRectangle(new SolidBrush(backColor), backgroundContentRectangle);
        }