System.Drawing.Graphics.FillRectangle(System.Drawing.Brush, System.Drawing.Rectangle)

Here are the examples of the csharp api System.Drawing.Graphics.FillRectangle(System.Drawing.Brush, System.Drawing.Rectangle) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

840 Examples 7

19 View Source File : Map.cs
License : GNU General Public License v3.0
Project Creator : AHeroicLlama

public static void Draw()
		{
			// Reset the current image to the background layer
			finalImage = (Image)backgroundLayer.Clone();

			Graphics imageGraphic = Graphics.FromImage(finalImage);
			imageGraphic.SmoothingMode = SmoothingMode.AntiAlias;
			Font font = new Font(fontCollection.Families[0], fontSize, GraphicsUnit.Pixel);

			CellScaling cellScaling = null;

			// Prepare the game version and watermark to be printed later
			string infoText = (SettingsPlot.IsTopographic() ? "Topographic View\n" : string.Empty) + "Game version " + IOManager.GetGameVersion() + "\nMade with Mappalachia - github.com/AHeroicLlama/Mappalachia";

			// Additional steps for cell mode (Add further text to watermark text, get cell height boundings)
			if (SettingsMap.IsCellModeActive())
			{
				Cell currentCell = SettingsCell.GetCell();

				// replacedign the CellScaling property
				cellScaling = currentCell.GetScaling();

				infoText =
					currentCell.displayName + " (" + currentCell.editorID + ")\n" +
					"Height distribution: " + SettingsCell.minHeightPerc + "% - " + SettingsCell.maxHeightPerc + "%\n" +
					"Scale: 1:" + Math.Round(cellScaling.scale, 2) + "\n\n" +
					infoText;
			}

			// Gather resources for drawing informational watermark text
			Brush brushWhite = new SolidBrush(Color.White);
			RectangleF infoTextBounds = new RectangleF(plotXMin, 0, mapDimension - plotXMin, mapDimension);
			StringFormat stringFormatBottomRight = new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Far }; // Align the text bottom-right
			StringFormat stringFormatBottomLeft = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Far }; // Align the text bottom-left

			// Draws bottom-right info text
			imageGraphic.DrawString(infoText, font, brushWhite, infoTextBounds, stringFormatBottomRight);

			// Draw a height-color key for Topography mode
			if (SettingsPlot.IsTopographic())
			{
				// Identify the sizing and locations for drawing the height-color-key strings
				double numHeightKeys = SettingsPlotTopograph.heightKeyIndicators;
				Font topographFont = new Font(fontCollection.Families[0], 62, GraphicsUnit.Pixel);
				float singleLineHeight = imageGraphic.MeasureString(SettingsPlotTopograph.heightKeyString, topographFont, new SizeF(infoTextBounds.Width, infoTextBounds.Height)).Height;

				// Identify the lower limit to start printing the key so that it ends up centered
				double baseHeight = (mapDimension / 2) - (singleLineHeight * (numHeightKeys / 2d));

				for (int i = 0; i <= numHeightKeys - 1; i++)
				{
					Brush brush = new SolidBrush(GetTopographColor(i / (numHeightKeys - 1)));
					imageGraphic.DrawString(SettingsPlotTopograph.heightKeyString, topographFont, brush, new RectangleF(plotXMax, 0, mapDimension - plotXMax, (float)(mapDimension - baseHeight)), stringFormatBottomRight);
					baseHeight += singleLineHeight;
				}
			}

			// Draw all legend text for every MapItem
			int skippedLegends = DrawLegend(font, imageGraphic);

			// Adds additional text if some items were missed from legend
			if (skippedLegends > 0)
			{
				string extraLegendText = "+" + skippedLegends + " more item" + (skippedLegends == 1 ? string.Empty : "s") + "...";
				imageGraphic.DrawString(extraLegendText, font, brushWhite, infoTextBounds, stringFormatBottomLeft);
			}

			// Start progress bar off at 0
			progressBarMain.Value = progressBarMain.Minimum;
			float progress = 0;

			// Nothing else to plot - ensure we update for the background layer but then return
			if (FormMaster.legendItems.Count == 0)
			{
				mapFrame.Image = finalImage;
				return;
			}

			// Count how many Map Data Points are due to be mapped
			int totalMapDataPoints = 0;
			foreach (MapItem mapItem in FormMaster.legendItems)
			{
				totalMapDataPoints += mapItem.count;
			}

			// Loop through every MapDataPoint represented by all the MapItems to find the min/max z coord in the dataset
			bool first = true;
			int zMin = 0;
			int zMax = 0;
			double zRange = 0;
			if (SettingsPlot.IsTopographic())
			{
				foreach (MapItem mapItem in FormMaster.legendItems)
				{
					foreach (MapDataPoint point in mapItem.GetPlots())
					{
						if (first)
						{
							zMin = point.z - (point.boundZ / 2);
							zMax = point.z + (point.boundZ / 2);
							first = false;
							continue;
						}

						// Do not contribute outlier values to the min/max range - this ensures they have the same
						// color as the min/max *legitimate* item and they do not skew the color ranges
						if (point.z > SettingsPlotTopograph.zThreshUpper || point.z < SettingsPlotTopograph.zThreshLower)
						{
							continue;
						}

						if (point.z - (point.boundZ / 2) < zMin)
						{
							zMin = point.z - (point.boundZ / 2);
						}

						if (point.z + (point.boundZ / 2) > zMax)
						{
							zMax = point.z + (point.boundZ / 2);
						}
					}
				}

				zRange = Math.Abs(zMax - zMin);

				if (zRange == 0)
				{
					zRange = 1;
				}
			}

			if (SettingsPlot.IsIconOrTopographic())
			{
				if (SettingsPlot.IsTopographic())
				{
					// Somehow this line prevents a memory leak
					// Without it, if drawing a large topographic map on first map draw, GC will not collect the multiple PlotIcon elements used in topographic drawing.
					Application.DoEvents();
				}

				// Processing each MapItem in serial, draw plots for every matching valid MapDataPoint
				foreach (MapItem mapItem in FormMaster.legendItems)
				{
					// Generate a Plot Icon and colours/brushes to be used for all instances of the MapItem
					PlotIcon plotIcon = mapItem.GetIcon();
					Image plotIconImg = SettingsPlot.IsIcon() ? plotIcon.GetIconImage() : null; // Icon mode has icon per MapItem, Topography needs icons per MapDataPoint and will be generated later
					Color volumeColor = Color.FromArgb(volumeOpacity, plotIcon.color);
					Brush volumeBrush = new SolidBrush(volumeColor);

					// Iterate over every data point and draw it
					foreach (MapDataPoint point in mapItem.GetPlots())
					{
						// Override colors in Topographic mode
						if (SettingsPlot.IsTopographic())
						{
							// Clamp the z values to the percieved outlier threshold
							double z = point.z + (point.boundZ / 2);
							z = Math.Max(Math.Min(z, SettingsPlotTopograph.zThreshUpper), SettingsPlotTopograph.zThreshLower);

							// Normalize the height of this item between the min/max z of the whole set
							double colorValue = (z - zMin) / zRange;

							// Override the plot icon color
							plotIcon.color = GetTopographColor(colorValue);
							plotIconImg = plotIcon.GetIconImage(); // Generate a new icon with a unique color for this height color

							// Apply the color to volume plotting too
							volumeColor = Color.FromArgb(volumeOpacity, plotIcon.color);
							volumeBrush = new SolidBrush(volumeColor);
						}

						if (SettingsMap.IsCellModeActive())
						{
							// If this coordinate exceeds the user-selected cell mapping height bounds, skip it
							// (Also accounts for the z-height of volumes)
							if (point.z + (point.boundZ / 2d) < SettingsCell.GetMinHeightCoordBound() || point.z - (point.boundZ / 2d) > SettingsCell.GetMaxHeightCoordBound())
							{
								continue;
							}

							point.x += cellScaling.xOffset;
							point.y += cellScaling.yOffset;

							// Multiply the coordinates by the scaling, but multiply around 0,0
							point.x = ((point.x - (mapDimension / 2)) * cellScaling.scale) + (mapDimension / 2);
							point.y = ((point.y - (mapDimension / 2)) * cellScaling.scale) + (mapDimension / 2);
							point.boundX *= cellScaling.scale;
							point.boundY *= cellScaling.scale;
						}
						else // Skip the point if its origin is outside the surface world
						if (point.x < plotXMin || point.x >= plotXMax || point.y < plotYMin || point.y >= plotYMax)
						{
							continue;
						}

						// If this meets all the criteria to be suitable to be drawn as a volume
						if (point.primitiveShape != string.Empty && // This is a primitive shape at all
							SettingsPlot.drawVolumes && // Volume drawing is enabled
							point.boundX >= minVolumeDimension && point.boundY >= minVolumeDimension) // This is large enough to be visible if drawn as a volume
						{
							Image volumeImage = new Bitmap((int)point.boundX, (int)point.boundY);
							Graphics volumeGraphic = Graphics.FromImage(volumeImage);
							volumeGraphic.SmoothingMode = SmoothingMode.AntiAlias;

							switch (point.primitiveShape)
							{
								case "Box":
								case "Line":
								case "Plane":
									volumeGraphic.FillRectangle(volumeBrush, new Rectangle(0, 0, (int)point.boundX, (int)point.boundY));
									break;
								case "Sphere":
								case "Ellipsoid":
									volumeGraphic.FillEllipse(volumeBrush, new Rectangle(0, 0, (int)point.boundX, (int)point.boundY));
									break;
								default:
									continue; // If we reach this, we dropped the drawing of a volume. Verify we've covered all shapes via the database summary.txt
							}

							volumeImage = ImageTools.RotateImage(volumeImage, point.rotationZ);
							imageGraphic.DrawImage(volumeImage, (float)(point.x - (volumeImage.Width / 2)), (float)(point.y - (volumeImage.Height / 2)));
						}

						// This MapDataPoint is not suitable to be drawn as a volume - draw a normal plot icon, or topographic plot
						else
						{
							imageGraphic.DrawImage(plotIconImg, (float)(point.x - (plotIconImg.Width / 2d)), (float)(point.y - (plotIconImg.Height / 2d)));
						}
					}

					// Increment the progress bar per MapItem
					progress += mapItem.count;
					progressBarMain.Value = (int)((progress / totalMapDataPoints) * progressBarMain.Maximum);
					Application.DoEvents();
				}
			}
			else if (SettingsPlot.IsHeatmap())
			{
				int resolution = SettingsPlotHeatmap.resolution;
				int blendRange = SettingsPlotHeatmap.blendDistance;

				// Create a 2D Array of HeatMapGridSquare
				HeatMapGridSquare[,] squares = new HeatMapGridSquare[resolution, resolution];
				for (int x = 0; x < resolution; x++)
				{
					for (int y = 0; y < resolution; y++)
					{
						squares[x, y] = new HeatMapGridSquare();
					}
				}

				int pixelsPerSquare = mapDimension / resolution;

				foreach (MapItem mapItem in FormMaster.legendItems)
				{
					int heatmapLegendGroup = SettingsPlotHeatmap.IsDuo() ? mapItem.legendGroup % 2 : 0;

					foreach (MapDataPoint point in mapItem.GetPlots())
					{
						if (SettingsMap.IsCellModeActive())
						{
							point.x += cellScaling.xOffset;
							point.y += cellScaling.yOffset;

							point.x = ((point.x - (mapDimension / 2)) * cellScaling.scale) + (mapDimension / 2);
							point.y = ((point.y - (mapDimension / 2)) * cellScaling.scale) + (mapDimension / 2);
						}

						// Identify which grid square this MapDataPoint falls within
						int squareX = (int)Math.Floor(point.x / pixelsPerSquare);
						int squareY = (int)Math.Floor(point.y / pixelsPerSquare);

						// Loop over every grid square within range, and increment by the weight proportional to the distance
						for (int x = squareX - blendRange; x < squareX + blendRange; x++)
						{
							for (int y = squareY - blendRange; y < squareY + blendRange; y++)
							{
								// Don't try to target squares which would lay outside of the grid
								if (x < 0 || x >= resolution || y < 0 || y >= resolution)
								{
									continue;
								}

								// Pythagoras on the x and y dist gives us the 'as the crow flies' distance between the squares
								double distance = Pythagoras(squareX - x, squareY - y);

								// Weight and hence brightness is modified by 1/x^2 + 1 where x is the distance from actual item
								double additionalWeight = point.weight * (1d / ((distance * distance) + 1));
								squares[x, y].weights[heatmapLegendGroup] += additionalWeight;
							}
						}
					}

					// Increment the progress bar per MapItem
					progress += mapItem.count;
					progressBarMain.Value = (int)((progress / totalMapDataPoints) * progressBarMain.Maximum);
					Application.DoEvents();
				}

				// Find the largest weight value of all squares
				double largestWeight = 0;
				for (int x = 0; x < resolution; x++)
				{
					for (int y = 0; y < resolution; y++)
					{
						double weight = squares[x, y].GetTotalWeight();
						if (weight > largestWeight)
						{
							largestWeight = weight;
						}
					}
				}

				// Finally now weights are calculated, draw a square for every HeatGripMapSquare in the array
				for (int x = 0; x < resolution; x++)
				{
					int xCoord = x * pixelsPerSquare;

					// Don't draw grid squares which are entirely within the legend text area
					if (xCoord + pixelsPerSquare < plotXMin)
					{
						continue;
					}

					for (int y = 0; y < resolution; y++)
					{
						int yCoord = y * pixelsPerSquare;

						Color color = squares[x, y].GetColor(largestWeight);
						Brush brush = new SolidBrush(color);

						Rectangle heatMapSquare = new Rectangle(xCoord, yCoord, mapDimension / SettingsPlotHeatmap.resolution, mapDimension / SettingsPlotHeatmap.resolution);
						imageGraphic.FillRectangle(brush, heatMapSquare);
					}
				}
			}

			mapFrame.Image = finalImage;
		}

19 View Source File : PlotIcon.cs
License : GNU General Public License v3.0
Project Creator : AHeroicLlama

public Image GetIconImage()
		{
			// Regenerate the icon image in topography mode, since we tend to update the color
			if (iconImage != null && !SettingsPlot.IsTopographic())
			{
				return iconImage;
			}

			if (shape.crosshairInner)
			{
				icon.DrawLine(pen, halfSize, quartSize, halfSize, threeQuartSize); // Vertical
				icon.DrawLine(pen, quartSize, halfSize, threeQuartSize, halfSize); // Horizontal
			}

			if (shape.crosshairOuter)
			{
				icon.DrawLine(pen, halfSize, size, halfSize, threeQuartSize); // Top
				icon.DrawLine(pen, halfSize, 0, halfSize, quartSize); // Bottom
				icon.DrawLine(pen, 0, halfSize, quartSize, halfSize); // Left
				icon.DrawLine(pen, size, halfSize, threeQuartSize, halfSize); // Right
			}

			if (shape.diamond)
			{
				PointF[] diamondCorners =
				{
					new PointF(halfSize, quartSize), // Top
					new PointF(quartSize, halfSize), // Bottom
					new PointF(halfSize, threeQuartSize), // Left
					new PointF(threeQuartSize, halfSize), // Right
				};

				if (shape.fill)
				{
					icon.FillPolygon(brush, diamondCorners);
				}
				else
				{
					icon.DrawPolygon(pen, diamondCorners);
				}
			}

			if (shape.square || shape.circle)
			{
				Rectangle halfRadiusRect = new Rectangle((int)quartSize, (int)quartSize, (int)halfSize, (int)halfSize);

				if (shape.square)
				{
					if (shape.fill)
					{
						icon.FillRectangle(brush, halfRadiusRect);
					}
					else
					{
						icon.DrawRectangle(pen, halfRadiusRect);
					}
				}

				if (shape.circle)
				{
					if (shape.fill)
					{
						icon.FillEllipse(brush, halfRadiusRect);
					}
					else
					{
						icon.DrawEllipse(pen, halfRadiusRect);
					}
				}
			}

			iconImage = ImageTools.AdjustARGB(bitmap, Color.FromArgb((int)(iconOpacityPercent / 100f * 255f), color));
			iconImage = ImageTools.AddDropShadow(iconImage, lineWidth, (int)(shadowOpacityPercent / 100f * 255f));

			return iconImage;
		}

19 View Source File : TextureView.cs
License : GNU General Public License v3.0
Project Creator : ahmed605

private void listTextures_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
                return;

            bool selected = ((e.State & DrawItemState.Selected) != 0);

            var texture = listTextures.Items[e.Index] as Texture;
            if (texture == null)
                return;

            string format = texture.TextureType.ToString();
            string textMain = texture.replacedleName;
            string textSub = texture.Width + "x" + texture.Height + " (" + format + ")";
            Font fontNormal = listTextures.Font;
            Font fontBold = new Font(fontNormal, FontStyle.Bold);
            Brush brushFG = selected ? SystemBrushes.HighlightText : SystemBrushes.ControlText;

            Graphics g = e.Graphics;

            // Clear the background
            if (selected)
            {
                Brush brushBG =
                    new LinearGradientBrush(e.Bounds, SystemColors.Highlight, SystemColors.HotTrack,
                                            LinearGradientMode.Horizontal);
                g.FillRectangle(brushBG, e.Bounds);
            }
            else
            {
                Brush brushBG = SystemBrushes.Window;
                g.FillRectangle(brushBG, e.Bounds);
            }

            Image thumbnail = texture.DecodeAsThumbnail();

            // Draw the icon
            int iconLeft = TextureListIconPadding + (TextureListIconSize - thumbnail.Width) / 2;
            int iconTop = TextureListIconPadding + (TextureListIconSize - thumbnail.Height) / 2;
            g.DrawImage(thumbnail, iconLeft, iconTop + e.Bounds.Top, thumbnail.Width, thumbnail.Height);

            // Draw the text
            int textLeft = TextureListIconSize + TextureListIconPadding * 2;

            SizeF sizeMain = g.MeasureString(textMain, fontBold);
            SizeF sizeSub = g.MeasureString(textSub, fontNormal);

            int textSpacer = (int)(e.Bounds.Height - (sizeMain.Height + sizeSub.Height + TextureListIconPadding * 2)) / 2;

            g.DrawString(textMain, fontBold, brushFG, textLeft, textSpacer + e.Bounds.Top + TextureListIconPadding);
            g.DrawString(textSub, fontNormal, brushFG, textLeft,
                         textSpacer + sizeMain.Height + e.Bounds.Top + TextureListIconPadding);

        }

19 View Source File : DataGridViewDisableButtonCell.cs
License : MIT License
Project Creator : AlexanderPro

protected override void Paint(Graphics graphics,
            Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
            DataGridViewElementStates elementState, object value,
            object formattedValue, string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            // The button cell is disabled, so paint the border,
            // background, and disabled button for the cell.
            if (!Enabled)
            {
                // Draw the cell background, if specified.
                if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background)
                {
                    SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor);
                    graphics.FillRectangle(cellBackground, cellBounds);
                    cellBackground.Dispose();
                }

                // Draw the cell borders, if specified.
                if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
                {
                    PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
                }

                // Calculate the area in which to draw the button.
                Rectangle buttonArea = cellBounds;
                Rectangle buttonAdjustment = BorderWidths(advancedBorderStyle);
                buttonArea.X += buttonAdjustment.X;
                buttonArea.Y += buttonAdjustment.Y;
                buttonArea.Height -= buttonAdjustment.Height;
                buttonArea.Width -= buttonAdjustment.Width;

                // Draw the disabled button.
                ButtonRenderer.DrawButton(graphics, buttonArea, PushButtonState.Disabled);

                // Draw the disabled button text.
                if (FormattedValue is string)
                {
                    TextRenderer.DrawText(graphics, (string)FormattedValue, DataGridView.Font, buttonArea, SystemColors.GrayText);
                }
            }
            else
            {
                // The button cell is enabled, so let the base clreplaced
                // handle the painting.
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            }
        }

19 View Source File : BendPoint.cs
License : GNU General Public License v3.0
Project Creator : alexgracianoarj

internal void Draw(Graphics g, bool onScreen, float zoom, Point offset)
		{
			int x = (int) (X * zoom) - SquareSize / 2 - offset.X;
			int y = (int) (Y * zoom) - SquareSize / 2 - offset.Y;
			Rectangle square = new Rectangle(x, y, SquareSize, SquareSize);

			if (AutoPosition)
			{
				squarePen.Color = RelativeToStartShape ? lightStartColor : lightEndColor;
				g.DrawRectangle(squarePen, square.X, square.Y, square.Width, square.Height);
			}
			else
			{
				squarePen.Color = RelativeToStartShape ? darkStartColor : darkEndColor;
				squareBrush.Color = RelativeToStartShape ? lightStartColor : lightEndColor;

				g.FillRectangle(squareBrush, square);
				g.DrawRectangle(squarePen, square);
			}
		}

19 View Source File : TabBar.cs
License : GNU General Public License v3.0
Project Creator : alexgracianoarj

private void DrawTabs(Graphics g)
		{
			Pen borderPen = new Pen(BorderColor);
			Brush activeTabBrush = new SolidBrush(ActiveTabColor);
			Brush inactiveTabBrush = new LinearGradientBrush(
				new Rectangle(0, 5, Width, Height - 1), ActiveTabColor,
				SystemColors.ControlLight, LinearGradientMode.Vertical);
			Brush textBrush;
			int left = LeftMargin;

			if (ForeColor.IsKnownColor)
				textBrush = SystemBrushes.FromSystemColor(ForeColor);
			else
				textBrush = new SolidBrush(ForeColor);

			g.DrawLine(borderPen, 0, Height - 1, left, Height - 1);
			foreach (Tab tab in tabs)
			{
				//TODO: szépíteni
				bool isActiveTab = (tab == activeTab);
				int top = (isActiveTab ? TopMargin : TopMargin + 2);
				Brush tabBrush = (isActiveTab ? activeTabBrush : inactiveTabBrush);
				Rectangle tabRectangle = new Rectangle(left, top, tab.Width, Height - top);

				// To display bottom line for inactive tabs
				if (!isActiveTab)
					tabRectangle.Height--;

				g.FillRectangle(tabBrush, tabRectangle); // Draw background
				g.DrawRectangle(borderPen, tabRectangle); // Draw border
				Font font = (isActiveTab) ? activeTabFont : Font;
				g.DrawString(tab.Text, font, textBrush, tabRectangle, stringFormat);

				left += tab.Width;
			}
			g.DrawLine(borderPen, left, Height - 1, Width - 1, Height - 1);

			borderPen.Dispose();
			if (!ForeColor.IsKnownColor)
				textBrush.Dispose();
			activeTabBrush.Dispose();
			inactiveTabBrush.Dispose();
		}

19 View Source File : SplitContainerAdv.cs
License : MIT License
Project Creator : AlexGyver

protected override void OnPaint(PaintEventArgs e) {
      base.OnPaint(e);

      Graphics g = e.Graphics;
      Rectangle r = SplitterRectangle;
      using (SolidBrush brush = new SolidBrush(color))
        g.FillRectangle(brush, r);
      ControlPaint.DrawBorder3D(g, r, border3DStyle);
    }

19 View Source File : TreeColumn.cs
License : MIT License
Project Creator : AlexGyver

internal Bitmap CreateGhostImage(Rectangle bounds, Font font)
		{
			Bitmap b = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
			Graphics gr = Graphics.FromImage(b);
			gr.FillRectangle(SystemBrushes.ControlDark, bounds);
			DrawContent(gr, bounds, font);
			BitmapHelper.SetAlphaChanelValue(b, 150);
			return b;
		}

19 View Source File : TreeColumn.cs
License : MIT License
Project Creator : AlexGyver

internal static void DrawBackground(Graphics gr, Rectangle bounds, bool pressed, bool hot)
		{
			if (Application.RenderWithVisualStyles)
			{
				CreateRenderers();
				if (pressed)
					_pressedRenderer.DrawBackground(gr, bounds);
				else if (hot)
					_hotRenderer.DrawBackground(gr, bounds);
				else
					_normalRenderer.DrawBackground(gr, bounds);
			}
			else
			{
				gr.FillRectangle(SystemBrushes.Control, bounds);
				Pen p1 = SystemPens.ControlLightLight;
				Pen p2 = SystemPens.ControlDark;
				Pen p3 = SystemPens.ControlDarkDark;
				if (pressed)
					gr.DrawRectangle(p2, bounds.X, bounds.Y, bounds.Width, bounds.Height);
				else
				{
					gr.DrawLine(p1, bounds.X, bounds.Y, bounds.Right, bounds.Y);
					gr.DrawLine(p3, bounds.X, bounds.Bottom, bounds.Right, bounds.Bottom);
					gr.DrawLine(p3, bounds.Right - 1, bounds.Y, bounds.Right - 1, bounds.Bottom - 1);
					gr.DrawLine(p1, bounds.Left, bounds.Y + 1, bounds.Left, bounds.Bottom - 2);
					gr.DrawLine(p2, bounds.Right - 2, bounds.Y + 1, bounds.Right - 2, bounds.Bottom - 2);
					gr.DrawLine(p2, bounds.X, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
				}
			}
		}

19 View Source File : TreeViewAdv.Draw.cs
License : MIT License
Project Creator : AlexGyver

private void DrawRow(PaintEventArgs e, ref DrawContext context, int row, Rectangle rowRect)
		{
			TreeNodeAdv node = RowMap[row];
			context.DrawSelection = DrawSelectionMode.None;
			context.CurrentEditorOwner = CurrentEditorOwner;
			if (DragMode)
			{
				if ((_dropPosition.Node == node) && _dropPosition.Position == NodePosition.Inside && HighlightDropPosition)
					context.DrawSelection = DrawSelectionMode.Active;
			}
			else
			{
				if (node.IsSelected && Focused)
					context.DrawSelection = DrawSelectionMode.Active;
				else if (node.IsSelected && !Focused && !HideSelection)
					context.DrawSelection = DrawSelectionMode.Inactive;
			}
			context.DrawFocus = Focused && CurrentNode == node;
			
			OnRowDraw(e, node, context, row, rowRect);

			if ((GridLineStyle & GridLineStyle.Horizontal) == GridLineStyle.Horizontal) {
				e.Graphics.DrawLine(LightGrayPen, 0, rowRect.Bottom, e.Graphics.ClipBounds.Right, rowRect.Bottom);
      }

			if (FullRowSelect)
			{
				context.DrawFocus = false;
				if (context.DrawSelection == DrawSelectionMode.Active || context.DrawSelection == DrawSelectionMode.Inactive)
				{
					Rectangle focusRect = new Rectangle(OffsetX, rowRect.Y, ClientRectangle.Width, rowRect.Height);
					if (context.DrawSelection == DrawSelectionMode.Active)
					{
						e.Graphics.FillRectangle(GrayBrush, focusRect);
						context.DrawSelection = DrawSelectionMode.FullRowSelect;
					}
					else
					{
						e.Graphics.FillRectangle(GrayBrush, focusRect);
						context.DrawSelection = DrawSelectionMode.None;
					}
				}
			}

			if (ShowLines)
				DrawLines(e.Graphics, node, rowRect);

			DrawNode(node, context);
		}

19 View Source File : TreeViewAdv.Draw.cs
License : MIT License
Project Creator : AlexGyver

private void DrawScrollBarsBox(Graphics gr)
		{
			Rectangle r1 = DisplayRectangle;
			Rectangle r2 = ClientRectangle;
			gr.FillRectangle(SystemBrushes.Control,
				new Rectangle(r1.Right, r1.Bottom, r2.Width - r1.Width, r2.Height - r1.Height));
		}

19 View Source File : TreeViewAdv.Draw.cs
License : MIT License
Project Creator : AlexGyver

[Conditional("PERF_TEST")]
		private void EndPerformanceCount(PaintEventArgs e)
		{
			double time = TimeCounter.Finish();
			_totalTime += time;
			string debugText = string.Format("FPS {0:0.0}; Avg. FPS {1:0.0}",
				1 / time, 1 / (_totalTime / _paintCount));
			e.Graphics.FillRectangle(Brushes.White, new Rectangle(DisplayRectangle.Width - 150, DisplayRectangle.Height - 20, 150, 20));
			e.Graphics.DrawString(debugText, Control.DefaultFont, Brushes.Gray,
				new PointF(DisplayRectangle.Width - 150, DisplayRectangle.Height - 20));
		}

19 View Source File : GifDecoder.cs
License : MIT License
Project Creator : AlexGyver

private void SetPixels() 
		{
			// expose destination image's pixels as int array
			//		int[] dest =
			//			(( int ) image.getRaster().getDataBuffer()).getData();
			int[] dest = GetPixels( bitmap );

			// fill in starting image contents based on last image's dispose code
			if (lastDispose > 0) 
			{
				if (lastDispose == 3) 
				{
					// use image before last
					int n = frameCount - 2;
					if (n > 0) 
					{
						lastImage = GetFrame(n - 1).Image;
					} 
					else 
					{
						lastImage = null;
					}
				}

				if (lastImage != null) 
				{
					//				int[] prev =
					//					((DataBufferInt) lastImage.getRaster().getDataBuffer()).getData();
					int[] prev = GetPixels( new Bitmap( lastImage ) );
					Array.Copy(prev, 0, dest, 0, width * height);
					// copy pixels

					if (lastDispose == 2) 
					{
						// fill last image rect area with background color
						Graphics g = Graphics.FromImage( image );
						Color c = Color.Empty;
						if (transparency) 
						{
							c = Color.FromArgb( 0, 0, 0, 0 ); 	// replacedume background is transparent
						} 
						else 
						{
							c = Color.FromArgb( lastBgColor ) ;
							//						c = new Color(lastBgColor); // use given background color
						}
						Brush brush = new SolidBrush( c );
						g.FillRectangle( brush, lastRect );
						brush.Dispose();
						g.Dispose();
					}
				}
			}

			// copy each source line to the appropriate place in the destination
			int preplaced = 1;
			int inc = 8;
			int iline = 0;
			for (int i = 0; i < ih; i++) 
			{
				int line = i;
				if (interlace) 
				{
					if (iline >= ih) 
					{
						preplaced++;
						switch (preplaced) 
						{
							case 2 :
								iline = 4;
								break;
							case 3 :
								iline = 2;
								inc = 4;
								break;
							case 4 :
								iline = 1;
								inc = 2;
								break;
						}
					}
					line = iline;
					iline += inc;
				}
				line += iy;
				if (line < height) 
				{
					int k = line * width;
					int dx = k + ix; // start of line in dest
					int dlim = dx + iw; // end of dest line
					if ((k + width) < dlim) 
					{
						dlim = k + width; // past dest edge
					}
					int sx = i * iw; // start of line in source
					while (dx < dlim) 
					{
						// map color and insert in destination
						int index = ((int) pixels[sx++]) & 0xff;
						int c = act[index];
						if (c != 0) 
						{
							dest[dx] = c;
						}
						dx++;
					}
				}
			}
			SetPixels( dest );
		}

19 View Source File : GdiGraphics.cs
License : GNU General Public License v3.0
Project Creator : alexgracianoarj

public void FillRectangle(Brush brush, Rectangle rect)
		{
			graphics.FillRectangle(brush, rect);
		}

19 View Source File : BaseTextControl.cs
License : MIT License
Project Creator : AlexGyver

public override void Draw(TreeNodeAdv node, DrawContext context)
		{
			if (context.CurrentEditorOwner == this && node == Parent.CurrentNode)
				return;

			Performancereplacedyzer.Start("BaseTextControl.Draw");
			string label = GetLabel(node);
			Rectangle bounds = GetBounds(node, context);
			Rectangle focusRect = new Rectangle(bounds.X, context.Bounds.Y,	
				bounds.Width, context.Bounds.Height);

			Brush backgroundBrush;
			Color textColor;
			Font font;
			CreateBrushes(node, context, label, out backgroundBrush, out textColor, out font, ref label);

			if (backgroundBrush != null)
				context.Graphics.FillRectangle(backgroundBrush, focusRect);
			if (context.DrawFocus)
			{
				focusRect.Width--;
				focusRect.Height--;
				if (context.DrawSelection == DrawSelectionMode.None)
					_focusPen.Color = SystemColors.ControlText;
				else
					_focusPen.Color = SystemColors.InactiveCaption;
				context.Graphics.DrawRectangle(_focusPen, focusRect);
			}
			
			Performancereplacedyzer.Start("BaseTextControl.DrawText");
			if (UseCompatibleTextRendering)
				TextRenderer.DrawText(context.Graphics, label, font, bounds, textColor, _formatFlags);
			else
				context.Graphics.DrawString(label, font, GetFrush(textColor), bounds, _format);
			Performancereplacedyzer.Finish("BaseTextControl.DrawText");

			Performancereplacedyzer.Finish("BaseTextControl.Draw");
		}

19 View Source File : PlotControl.cs
License : MIT License
Project Creator : AlexGyver

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var rc = new GraphicsRenderContext(this, e.Graphics, e.ClipRectangle);
            if (model != null)
                model.Render(rc);
            if (zoomRectangle != Rectangle.Empty)
            {
                using (var zoomBrush = new SolidBrush(Color.FromArgb(0x40, 0xFF, 0xFF, 0x00)))
                using (var zoomPen = new Pen(Color.Black))
                {
                    zoomPen.DashPattern = new float[] { 3, 1 };
                    e.Graphics.FillRectangle(zoomBrush, zoomRectangle);
                    e.Graphics.DrawRectangle(zoomPen, zoomRectangle);
                }
            }
        }

19 View Source File : Plot.cs
License : MIT License
Project Creator : AlexGyver

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            try
            {
                lock (this.invalidateLock)
                {
                    if (this.isModelInvalidated)
                    {
                        if (this.model != null)
                        {
                            this.model.Update(this.updateDataFlag);
                            this.updateDataFlag = false;
                        }

                        this.isModelInvalidated = false;
                    }
                }

                lock (this.renderingLock)
                {
                    this.renderContext.SetGraphicsTarget(e.Graphics);
                    if (this.model != null)
                    {
                        this.model.Render(this.renderContext, this.Width, this.Height);
                    }

                    if (this.zoomRectangle != Rectangle.Empty)
                    {
                        using (var zoomBrush = new SolidBrush(Color.FromArgb(0x40, 0xFF, 0xFF, 0x00)))
                        using (var zoomPen = new Pen(Color.Black))
                        {
                            zoomPen.DashPattern = new float[] { 3, 1 };
                            e.Graphics.FillRectangle(zoomBrush, this.zoomRectangle);
                            e.Graphics.DrawRectangle(zoomPen, this.zoomRectangle);
                        }
                    }
                }
            }
            catch (Exception paintException)
            {
                var trace = new StackTrace(paintException);
                Debug.WriteLine(paintException);
                Debug.WriteLine(trace);
                using (var font = new Font("Arial", 10))
                {
                    e.Graphics.DrawString(
                        "OxyPlot paint exception: " + paintException.Message, font, Brushes.Red, 10, 10);
                }
            }
        }

19 View Source File : TagDisplayControl.cs
License : MIT License
Project Creator : AlturosDestinations

private void TagDisplayControl_Paint(object sender, PaintEventArgs e)
        {
            var size = this.Size;

            this._labelOffsetX = 0;
            this._labelOffsetY = 0;

            if (this.Tags == null)
            {
                return;
            }

            foreach (var tag in this.Tags)
            {
                var rectangle = this.GetRectangle(e.Graphics, tag, size);
                e.Graphics.FillRectangle(Brushes.SkyBlue, rectangle);
                e.Graphics.DrawString(tag, SystemFonts.DefaultFont, Brushes.DarkBlue, new PointF(rectangle.X + _labelPadding, rectangle.Y + _labelPadding));
            }
        }

19 View Source File : loading.cs
License : MIT License
Project Creator : Amine-Smahi

private void t_Tick(object sender, EventArgs e)
        {
            g = Graphics.FromImage(bmp);
            g.Clear(Color.White);
            var myBrush = new SolidBrush(Color.FromArgb(37, 155, 36));
            g.FillRectangle(myBrush, new Rectangle(0, 0, (int) (pbComplete * pbUnit), pbHEIGHT));


            if (pbComplete == 60)
            {

                FileInfo fi = new FileInfo(@".\a\lang.txt");
                DirectoryInfo di = new DirectoryInfo(@".\a");
                if (!di.Exists)
                {
                    di.Create();
                }
                if (!fi.Exists)
                {
                    fi.Create().Dispose();
                }

                /* if (!File.Exists(path))
                 {
                     File.Create(path).Dispose();
                     using (TextWriter tw = new StreamWriter(path))
                     {
                         tw.WriteLine("english");
                         tw.Close();
                     }
                 }
                 */
            }

            if (pbComplete == 70)
                if (File.Exists(path))
                    using (TextReader tr = new StreamReader(path))
                    {
                        var langugeChoused = tr.ReadLine();

                        if (langugeChoused == "arabic")
                        {
                            fom.bunifuTileButton1.LabelText = "إفتح صورة";
                            fom.bunifuTileButton2.LabelText = "إحفظ الصورة";
                            fom.bunifuTileButton3.LabelText = "أكتب الرسالة";
                            fom.bunifuTileButton4.LabelText = "أظهر الصورة";
                            fom.about_us.LabelText = "عن البرنامج";
                            fom.bunifuTileButton6.LabelText = "إعداداتي";
                        }
                    }

            picboxPB.Image = bmp;
            pbComplete++;

            if (pbComplete > 100)
            {
                g.Dispose();
                t.Stop();
                Hide();

                fom.Show();
            }
        }

19 View Source File : DiffControl.cs
License : Apache License 2.0
Project Creator : AmpScm

internal static void PaintColorLegendItem(ToolStripItem Item, PaintEventArgs e)
        {
            if (Item != null)
            {
                //Make our outermost painting rect a little smaller.
                Rectangle R = e.ClipRectangle;
                R.Inflate(-1, -1);

                //Paint the background.
                Graphics G = e.Graphics;
                using (Brush B = new SolidBrush(Item.BackColor))
                {
                    G.FillRectangle(B, R);
                }

                //Draw a border.
                Rectangle BorderRect = new Rectangle(R.X, R.Y, R.Width - 1, R.Height - 1);
                ControlPaint.DrawVisualStyleBorder(G, BorderRect);

                //Draw the image centered.  (I should probably check the
                //item's ImageAlign property here, but I know I'm always
                //using MiddleCenter for all the preplaceded-in items.)
                Image I = Item.Image;
                Rectangle ImageRect = new Rectangle(R.X + (R.Width - I.Width) / 2, R.Y + (R.Height - I.Height) / 2, I.Width, I.Height);
                G.DrawImage(I, ImageRect);
            }
        }

19 View Source File : DiffOverview.cs
License : Apache License 2.0
Project Creator : AmpScm

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics G = e.Graphics;

            if (m_Image != null)
            {
                Rectangle R = e.ClipRectangle;
                G.DrawImage(m_Image, R.X, R.Y, R, GraphicsUnit.Pixel);

                //Repaint the view window if any of it is invalid
                if (R.IntersectsWith(m_ViewRect))
                {
                    bool bDisposePen = false;
                    Pen P = SystemPens.Highlight;
                    Rectangle rPen;

                    if (UseTranslucentView)
                    {
                        //Set the alpha blend to 20% (51/256);
                        SolidBrush B = new SolidBrush(Color.FromArgb(51, SystemColors.Highlight));
                        R.Intersect(m_ViewRect);
                        G.FillRectangle(B, R);
                        B.Dispose();

                        //Draw the pen border with view rect.
                        rPen = m_ViewRect;
                    }
                    else
                    {
                        //Create a two pixel wide highlight pen.
                        P = new Pen(SystemColors.Highlight, 2);
                        bDisposePen = true;

                        //Because the lines will go back up a pixel
                        //we have to shrink the bounds of the rect.
                        rPen = new Rectangle(m_ViewRect.X + 1, m_ViewRect.Y + 1, m_ViewRect.Width - 1, m_ViewRect.Height - 1);
                    }

                    //Draw a Highlight Pen border.  In some cases, it will
                    //draw a pixel too far (because we always round up), so
                    //we'll check for that case here.  If we're scrolled to
                    //the bottom, I don't want the last line cut off.
                    int iViewHeight = rPen.Height - 1;
                    int iUsableHeight = ClientSize.Height - rPen.Y - 1;
                    int iHeight = Math.Min(iViewHeight, iUsableHeight);
                    G.DrawRectangle(P, rPen.X, rPen.Y, rPen.Width - 1, iHeight);

                    if (bDisposePen)
                    {
                        P.Dispose();
                    }
                }
            }
            else
            {
                G.FillRectangle(SystemBrushes.Control, ClientRectangle);
            }
        }

19 View Source File : AnnotateMarginControl.cs
License : Apache License 2.0
Project Creator : AmpScm

protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            if (DesignMode)
            {
                using (Brush grayBg = new LinearGradientBrush(new Point(0, 0), new Point(Width, 0), BackColor, Color.LightGray))
                {
                    pevent.Graphics.FillRectangle(grayBg, ClientRectangle);
                }
            }
        }

19 View Source File : AnnotateMarginControl.cs
License : Apache License 2.0
Project Creator : AmpScm

protected override void OnPaint(PaintEventArgs e)
        {
            if (DesignMode)
                return;

            StringFormat sfr = new StringFormat();
            sfr.Alignment = StringAlignment.Far;

            StringFormat sfl = new StringFormat();
            sfl.Trimming = StringTrimming.EllipsisCharacter;
            sfl.FormatFlags = StringFormatFlags.NoWrap;

            using (Font f = new Font(Font.FontFamily, 7F))
            using (Pen border = new Pen(Color.Gray))
            using (Brush textColor = new SolidBrush(Color.Black))
            using (Brush selectedTextColor = new SolidBrush(SystemColors.HighlightText))
            using (Brush grayBg = new LinearGradientBrush(new Point(0, 0), new Point(Width, 0), BackColor, Color.LightGray))
            using (Brush blueBg = new LinearGradientBrush(new Point(0, 0), new Point(Width, 0), BackColor, Color.LightBlue))
            using (Brush selectedBg = new SolidBrush(SystemColors.Highlight))
            using (SolidBrush localBg = new SolidBrush(SystemColors.Info))
            {
                foreach (AnnotateRegion region in _regions)
                {
                    // We try to draw a few regions above and below to fix up drawing
                    // when the actual editor is smaller than our view. 
                    // (E.g. navigation bar for C# editor)
                    if (region.EndLine < _firstLine-4) 
                        continue;
                    if (region.StartLine > _lastLine+4)
                        break;

                    Rectangle rect = GetRectangle(region);
                    if (!e.ClipRectangle.IntersectsWith(rect))
                        continue;

                    if (IsSelected(region))
                        e.Graphics.FillRectangle(selectedBg, rect);
                    else
                    {
                        if (region.Hovered)
                            e.Graphics.FillRectangle(blueBg, rect);
                        else if (region.Source.Revision >= 0)
                            e.Graphics.FillRectangle(grayBg, rect);
                        else
                            e.Graphics.FillRectangle(localBg, rect);
                    }
                    e.Graphics.DrawRectangle(border, rect);

                    AnnotateSource src = region.Source;
                    if (src.Revision >= 0)
                    {
                        string revisionString = src.Revision.ToString();
                        string dateString = src.Time.ToShortDateString();

                        float rectTop = rect.Top + 2; // top padding of 2px
                        float revisionWidth = e.Graphics.MeasureString(revisionString, f).Width;
                        float dateWidth = e.Graphics.MeasureString(dateString, f).Width;

                        // Calculate the author field based on the fields to the left and right of it
                        // because we use ellipsis trimming when it's too small
                        float authorWidth = Width - revisionWidth - dateWidth - 8; // left+right padding of both revision and date means 2+2+2+2 = 8

                        Brush color = IsSelected(region) ? selectedTextColor : textColor;
                        e.Graphics.DrawString(revisionString, f, color, new RectangleF(3, rectTop, revisionWidth, LineHeight), sfr);

                        // TODO: decide if this is the best way
                        // If the authorWidth is negative, don't attempt to show the author. This case should only
                        // occur with very long ShortDateStrings, or very long revision strings.
                        if (authorWidth > 0)
                            e.Graphics.DrawString(src.Author, f, color, new RectangleF(revisionWidth + 5, rectTop, authorWidth, LineHeight), sfl);

                        e.Graphics.DrawString(dateString, f, color, new RectangleF(Width - dateWidth - 2, rectTop, dateWidth, LineHeight), sfr);
                    }
                }

                Rectangle clip = e.ClipRectangle;
                using (SolidBrush sb = new SolidBrush(BackColor))
                {
                    if (_regions.Count > 0)
                    {
                        Rectangle rect = GetRectangle(_regions[0]);

                        if (e.ClipRectangle.Top < rect.Top)
                            e.Graphics.FillRectangle(sb, clip.X, clip.Y, clip.Width, rect.Top - clip.Y);
                            
                        rect = GetRectangle(_regions[_regions.Count - 1]);

                        if (e.ClipRectangle.Bottom > rect.Bottom)
                            e.Graphics.FillRectangle(sb, clip.X, rect.Bottom + 1, rect.Width, clip.Y+clip.Height - rect.Bottom - 1);
                    }
                    else
                        e.Graphics.FillRectangle(sb, clip);
                }
            }
        }

19 View Source File : StatusContainer.cs
License : Apache License 2.0
Project Creator : AmpScm

protected override void OnPaint(PaintEventArgs e)
        {
            //base.OnPaint(e);
            int width = ClientSize.Width;
            Font fnt = null;
            StringFormat fmt = null;
            try
            {
                foreach (StatusPanel panel in Controls)
                {
                    if (!panel.Visible)
                        continue;

                    Point pl = panel.PanelLocation;
                    Size pz = panel.PanelSize;
                    int hh = panel.HeaderHeight;

                    e.Graphics.DrawRectangle(SystemPens.ControlDark, new Rectangle(pl, pz));
                    e.Graphics.DrawLine(SystemPens.ControlDark, pl.X + 1, pl.Y + hh + 1, pl.X + pz.Width, pl.Y + hh + 1);

                    using (Brush brush = new LinearGradientBrush(pl, pl + new Size(width, 0), panel.GradientLeft, panel.GradientRight))
                        e.Graphics.FillRectangle(brush, new Rectangle(pl.X + 1, pl.Y + 1, pz.Width - 1, panel.HeaderHeight));

                    Image img = panel.HeaderImage;

                    if (img != null)
                        e.Graphics.DrawImageUnscaled(img, pl + new Size((hh - img.Width) / 2, (hh - img.Height) / 2));

                    if (!string.IsNullOrEmpty(panel.replacedle))
                    {
                        if (fnt == null)
                        {
                            Font f = Font;
                            fnt = new Font(SystemFonts.CaptionFont.FontFamily, f.SizeInPoints * 1.5f, FontStyle.Regular);
                            fmt = new StringFormat(StringFormatFlags.NoWrap);
                            fmt.LineAlignment = StringAlignment.Center;
                        }

                        int x = pl.X + hh;
                        e.Graphics.DrawString(panel.replacedle, fnt, SystemBrushes.ControlText, new RectangleF(x, pl.Y + 1, pz.Width - x, hh), fmt);
                    }
                }
            }
            finally
            {
                if (fnt != null)
                    fnt.Dispose();
            }
        }

19 View Source File : SmartSplitter.cs
License : Apache License 2.0
Project Creator : AmpScm

protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            if (_hreplacedplitterColor)
            {
                using (SolidBrush sb = new SolidBrush(SplitterColor))
                    e.Graphics.FillRectangle(sb, SplitterRectangle);
            }
        }

19 View Source File : SnippingTool.cs
License : Apache License 2.0
Project Creator : AnkiUniversal

protected override void OnPaint(PaintEventArgs e)
        {
            using (Brush br = new SolidBrush(Color.FromArgb(120, Color.White)))
            {
                int x1 = rectSelection.X;
                int x2 = rectSelection.X + rectSelection.Width;
                int y1 = rectSelection.Y;
                int y2 = rectSelection.Y + rectSelection.Height;
                e.Graphics.FillRectangle(br, new Rectangle(0, 0, x1, Height));
                e.Graphics.FillRectangle(br, new Rectangle(x2, 0, Width - x2, Height));
                e.Graphics.FillRectangle(br, new Rectangle(x1, 0, x2 - x1, y1));
                e.Graphics.FillRectangle(br, new Rectangle(x1, y2, x2 - x1, Height - y2));
            }
            using (Pen pen = new Pen(Color.Green, 2))
            {
                e.Graphics.DrawRectangle(pen, rectSelection);
            }
        }

19 View Source File : ClearTypeLetterGlyph.cs
License : Apache License 2.0
Project Creator : anmcgrath

public static ClearTypeLetterGlyph CreateGlyph(GlyphTypeface glyphTypeface, System.Drawing.Font font, double size, char ch, Color fontColor, Color bgColor)
        {
            if (ch == ' ') return CreateSpaceGlyph(glyphTypeface, size);

            int width;
            int height;

            using (var bmp1 = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
            {
                using (var g = Graphics.FromImage(bmp1))
                {
                    //var sizef = g.MeasureString("" + ch, font, new PointF(0, 0), StringFormat.GenericTypographic);
                    var sizef = g.MeasureString("" + ch, font, new PointF(0, 0), StringFormat.GenericTypographic);
                    width = (int) Math.Ceiling(sizef.Width);
                    height = (int) Math.Ceiling(sizef.Height);
                }
            }

            if (width == 0 || height == 0) return null;

            var res = new List<Item>();

            using (var bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
            {
                var fg2 = System.Drawing.Color.FromArgb(fontColor.A, fontColor.R, fontColor.G, fontColor.B);
                var bg2 = System.Drawing.Color.FromArgb(bgColor.A, bgColor.R, bgColor.G, bgColor.B);

                using (var g = System.Drawing.Graphics.FromImage(bmp))
                {
                    g.FillRectangle(new System.Drawing.SolidBrush(bg2), new Rectangle(0, 0, width, height));
                    g.DrawString("" + ch, font, new System.Drawing.SolidBrush(fg2), 0, 0, StringFormat.GenericTypographic);
                }

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        var color = bmp.GetPixel(x, y);
                        if (color != bg2)
                        {
                            res.Add(new Item
                            {
                                X = (short)x,
                                Y = (short)y,
                                Color = WriteableBitmapExtensions.ConvertColor(Color.FromArgb(color.A, color.R, color.G, color.B)),
                            });
                        }
                    }
                }
            }

            //var res = new List<int>();

            //using (var bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
            //{
            //    var fg2 = System.Drawing.Color.FromArgb(fontColor.A, fontColor.R, fontColor.G, fontColor.B);
            //    var bg2 = System.Drawing.Color.FromArgb(bgColor.A, bgColor.R, bgColor.G, bgColor.B);

            //    using (var g = System.Drawing.Graphics.FromImage(bmp))
            //    {
            //        g.FillRectangle(new System.Drawing.SolidBrush(bg2), new Rectangle(0, 0, width, height));
            //        g.DrawString("" + ch, font, new System.Drawing.SolidBrush(fg2), 0, 0, StringFormat.GenericTypographic);
            //    }

            //    int bgint = WriteableBitmapExtensions.ConvertColor(Color.FromArgb(bgColor.A, bgColor.R, bgColor.G, bgColor.B));
            //    for (int y = 0; y < height; y++)
            //    {
            //        var line = new List<int>();
            //        for (int x = 0; x < width; x++)
            //        {
            //            var color = bmp.GetPixel(x, y);
            //            line.Add(WriteableBitmapExtensions.ConvertColor(Color.FromArgb(color.A, color.R, color.G, color.B)));
            //        }
            //        if (line.All(x => x == bgint)) continue; // all pixels filled with BG color
            //        int minx = line.FindIndex(x => x != bgint);
            //        int maxx = line.FindLastIndex(x => x != bgint);
            //        res.Add(y);
            //        res.Add(minx);
            //        res.Add(maxx - minx + 1);
            //        for (int i = minx; i <= maxx; i++) res.Add(line[i]);
            //    }
            //}

            //res.Add(-1); // end mark

            return new ClearTypeLetterGlyph
                {
                    Width = width,
                    Height = height,
                    Ch = ch,
                    //Instructions = res.ToArray(),
                    Items = res.ToArray(),
                };
        }

19 View Source File : ImageBrowserItem.cs
License : GNU General Public License v3.0
Project Creator : anotak

public void Draw(Graphics g, Rectangle bounds)
		{
			Brush forecolor;
			Brush backcolor;
			
			// Remember if the preview is loaded
			imageloaded = icon.IsPreviewLoaded;

			// Drawing settings
			g.CompositingQuality = CompositingQuality.HighSpeed;
			g.InterpolationMode = InterpolationMode.NearestNeighbor;
			g.SmoothingMode = SmoothingMode.HighSpeed;
			g.PixelOffsetMode = PixelOffsetMode.None;

			// Determine coordinates
			SizeF textsize = g.MeasureString(displaytext, this.ListView.Font, bounds.Width * 2);
			Rectangle imagerect = new Rectangle(bounds.Left + ((bounds.Width - General.Map.Data.Previews.MaxImageWidth) >> 1),
				bounds.Top + ((bounds.Height - General.Map.Data.Previews.MaxImageHeight - (int)textsize.Height) >> 1),
				General.Map.Data.Previews.MaxImageWidth, General.Map.Data.Previews.MaxImageHeight);
			PointF textpos = new PointF(bounds.Left + ((float)bounds.Width - textsize.Width) * 0.5f, bounds.Bottom - textsize.Height - 2);

			// Determine colors
			if(this.Selected)
			{
                // Highlighted
                /*
				backcolor = new LinearGradientBrush(new Point(0, bounds.Top - 1), new Point(0, bounds.Bottom + 1),
					AdjustedColor(SystemColors.Highlight, 0.2f),
					AdjustedColor(SystemColors.Highlight, -0.1f));
                */
                backcolor = SystemBrushes.Highlight;
				forecolor = SystemBrushes.HighlightText;
			}
			else
			{
                // Normal
                if (unselected_backcolor == null)
                {
                    unselected_backcolor = new SolidBrush(base.ListView.BackColor);
                }
				backcolor = unselected_backcolor;

                if (unselected_forecolor == null)
                {
                    unselected_forecolor = new SolidBrush(base.ListView.ForeColor);
                }
                forecolor = unselected_forecolor;
			}

			// Draw!
			g.FillRectangle(backcolor, bounds);
			icon.DrawPreview(g, imagerect.Location);
			g.DrawString(displaytext, this.ListView.Font, forecolor, textpos);
		}

19 View Source File : ActionSelectorControl.cs
License : GNU General Public License v3.0
Project Creator : anotak

private void list_DrawItem(object sender, DrawItemEventArgs e)
		{
			INumberedreplacedle item;
			Brush displaybrush = SystemBrushes.WindowText;
			Brush backbrush = SystemBrushes.Window;
			string displayname = "";
			int intnumber = 0;
			
			// Only when running
			if(!this.DesignMode)
			{
				// Unknow item?
				if(e.Index < 0)
				{
					// Grayed
					displaybrush = new SolidBrush(SystemColors.GrayText);
					backbrush = new SolidBrush(SystemColors.Window);

					// Try getting integral number
					int.TryParse(number.Text, out intnumber);

					// Check what to display
					if(number.Text.Length == 0)
						displayname = "";
					else if(intnumber == 0)
						displayname = "None";
					else if((generalizedcategories != null) && GameConfiguration.IsGeneralized(intnumber, generalizedcategories))
						displayname = "Generalized (" + General.Map.Config.GetGeneralizedActionCategory(intnumber) + ")";
					else
						displayname = "Unknown";
				}
				// In the display part of the combobox?
				else if((e.State & DrawItemState.ComboBoxEdit) != 0)
				{
					// Show without number
					item = (INumberedreplacedle)list.Items[e.Index];
					displayname = item.replacedle.Trim();

					// Determine colors to use
					if(item.Index == 0)
					{
						// Grayed
						displaybrush = new SolidBrush(SystemColors.GrayText);
						backbrush = new SolidBrush(SystemColors.Window);
					}
					else
					{
						// Normal color
						displaybrush = new SolidBrush(list.ForeColor);
						backbrush = new SolidBrush(SystemColors.Window);
					}
				}
				else
				{
					// Use number and description
					item = (INumberedreplacedle)list.Items[e.Index];
					displayname = item.Index + NUMBER_SEPERATOR + item.replacedle;

					// Determine colors to use
					if((e.State & DrawItemState.Focus) != 0)
					{
						displaybrush = new SolidBrush(SystemColors.HighlightText);
						backbrush = new SolidBrush(SystemColors.Highlight);
					}
					else
					{
						displaybrush = new SolidBrush(list.ForeColor);
						backbrush = new SolidBrush(SystemColors.Window);
					}
				}
				
			}

			// Draw item
			e.Graphics.FillRectangle(backbrush, e.Bounds);
			e.Graphics.DrawString(displayname, list.Font, displaybrush, e.Bounds.X, e.Bounds.Y);
		}

19 View Source File : ProgressBarEx.cs
License : GNU General Public License v3.0
Project Creator : antikmozib

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            Point StartPoint = new Point(0, 0);
            Point EndPoint = new Point(0, this.Height);

            if (_ProgressDirection == ProgressDir.Vertical)
            {
                EndPoint = new Point(this.Width, 0);
            }

            using (GraphicsPath gp = new GraphicsPath())
            {
                Rectangle rec = new Rectangle(0, 0, this.Width, this.Height);
                int rad = Convert.ToInt32(rec.Height / 2.5);
                if (rec.Width < rec.Height)
                    rad = Convert.ToInt32(rec.Width / 2.5);

                using (LinearGradientBrush _BackColorBrush = new LinearGradientBrush(StartPoint, EndPoint, _BackColor, _GradiantColor))
                {
                    _BackColorBrush.Blend = bBlend;
                    if (_RoundedCorners)
                    {
                        gp.AddArc(rec.X, rec.Y, rad, rad, 180, 90);
                        gp.AddArc(rec.Right - (rad), rec.Y, rad, rad, 270, 90);
                        gp.AddArc(rec.Right - (rad), rec.Bottom - (rad), rad, rad, 0, 90);
                        gp.AddArc(rec.X, rec.Bottom - (rad), rad, rad, 90, 90);
                        gp.CloseFigure();
                        e.Graphics.FillPath(_BackColorBrush, gp);
                    }
                    else
                    {
                        e.Graphics.FillRectangle(_BackColorBrush, rec);
                    }
                }

                if (_Value > _Minimum)
                {
                    int lngth = Convert.ToInt32((double)(this.Width / (double)(_Maximum - _Minimum)) * _Value);
                    if (_ProgressDirection == ProgressDir.Vertical)
                    {
                        lngth = Convert.ToInt32((double)(this.Height / (double)(_Maximum - _Minimum)) * _Value);
                        rec.Y = rec.Height - lngth;
                        rec.Height = lngth;
                    }
                    else
                    {
                        rec.Width = lngth;
                    }

                    using (LinearGradientBrush _ProgressBrush = new LinearGradientBrush(StartPoint, EndPoint, _ProgressColor, _GradiantColor))
                    {
                        _ProgressBrush.Blend = bBlend;
                        if (_RoundedCorners)
                        {
                            if (_ProgressDirection == ProgressDir.Horizontal)
                            {
                                rec.Height -= 1;
                            }
                            else
                            {
                                rec.Width -= 1;
                            }

                            using (GraphicsPath gp2 = new GraphicsPath())
                            {
                                gp2.AddArc(rec.X, rec.Y, rad, rad, 180, 90);
                                gp2.AddArc(rec.Right - (rad), rec.Y, rad, rad, 270, 90);
                                gp2.AddArc(rec.Right - (rad), rec.Bottom - (rad), rad, rad, 0, 90);
                                gp2.AddArc(rec.X, rec.Bottom - (rad), rad, rad, 90, 90);
                                gp2.CloseFigure();
                                using (GraphicsPath gp3 = new GraphicsPath())
                                {
                                    using (Region rgn = new Region(gp))
                                    {
                                        rgn.Intersect(gp2);
                                        gp3.AddRectangles(rgn.GetRegionScans(new Matrix()));
                                    }
                                    e.Graphics.FillPath(_ProgressBrush, gp3);
                                }
                            }
                        }
                        else
                        {
                            e.Graphics.FillRectangle(_ProgressBrush, rec);
                        }
                    }
                }

                if (_Image != null)
                {
                    if (_ImageLayout == ImageLayoutType.Stretch)
                    {
                        e.Graphics.DrawImage(_Image, 0, 0, this.Width, this.Height);
                    }
                    else if (_ImageLayout == ImageLayoutType.None)
                    {
                        e.Graphics.DrawImage(_Image, 0, 0);
                    }
                    else
                    {
                        int xx = Convert.ToInt32((this.Width / 2) - (_Image.Width / 2));
                        int yy = Convert.ToInt32((this.Height / 2) - (_Image.Height / 2));
                        e.Graphics.DrawImage(_Image, xx, yy);
                    }
                }

                if (_ShowPercentage | _ShowText)
                {
                    string perc = "";
                    if (_ShowText)
                        perc = this.Text;
                    if (_ShowPercentage)
                        perc += Convert.ToString(Convert.ToInt32(((double)100 / (double)(_Maximum - _Minimum)) * _Value)) + "%";
                    using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
                    {
                        e.Graphics.DrawString(perc, this.Font, _ForeColorBrush, new Rectangle(0, 0, this.Width, this.Height), sf);
                    }
                }

                if (_Border)
                {
                    rec = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
                    if (_RoundedCorners)
                    {
                        gp.Reset();
                        gp.AddArc(rec.X, rec.Y, rad, rad, 180, 90);
                        gp.AddArc(rec.Right - (rad), rec.Y, rad, rad, 270, 90);
                        gp.AddArc(rec.Right - (rad), rec.Bottom - (rad), rad, rad, 0, 90);
                        gp.AddArc(rec.X, rec.Bottom - (rad), rad, rad, 90, 90);
                        gp.CloseFigure();
                        e.Graphics.DrawPath(_BorderPen, gp);
                    }
                    else
                    {
                        e.Graphics.DrawRectangle(_BorderPen, rec);
                    }
                }
            }
        }

19 View Source File : FormPattern.cs
License : MIT License
Project Creator : arsium

protected override void OnPaint(PaintEventArgs e) // you can safely omit this method if you want
        {
            Color C = ColorTranslator.FromHtml("#00adef");

            SolidBrush B = new SolidBrush(C);

            //e.Graphics.FillRectangle(Brushes.Green, Top);
            e.Graphics.FillRectangle(B, Top);
            e.Graphics.FillRectangle(B, Left);
            e.Graphics.FillRectangle(B, Right);
            e.Graphics.FillRectangle(B, Bottom);
        }

19 View Source File : ControlsDrawing.cs
License : MIT License
Project Creator : arsium

private static void headerDraw(object sender, DrawListViewColumnHeaderEventArgs e, Color backColor, Color foreColor)
        {
            using (SolidBrush backBrush = new SolidBrush(backColor))
            {
                e.Graphics.FillRectangle(backBrush, e.Bounds);
            }

            using (SolidBrush foreBrush = new SolidBrush(foreColor))
            {
                e.Graphics.DrawString(e.Header.Text, e.Font, foreBrush, e.Bounds);
            }
        }

19 View Source File : ControlsDrawing.cs
License : MIT License
Project Creator : arsium

private static void DrawItem(object sender, DrawListViewItemEventArgs e , Color Normal, Color Selected)
        {
            //e.DrawDefault = true;
            if (e.Item.Selected == true)
            {
                //e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(60, 60, 60)), e.Bounds);
                e.Graphics.FillRectangle(new SolidBrush(Selected), e.Bounds);
            }
            else
            {
                e.Graphics.FillRectangle(new SolidBrush(Normal), e.Bounds);
                //e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(30, 30, 30)), e.Bounds);
                //e.DrawText(TextFormatFlags.VerticalCenter);
            }
            if (((ListView)sender).Name == "clientsListView") 
            {
                //e.DrawText(TextFormatFlags.VerticalCenter);
                if (e.Item.ImageKey != null || e.Item.ImageIndex != -1)
                {
                    Rectangle rectangle = new Rectangle(e.Bounds.X, e.Bounds.Y, 28, 28);
                    e.Graphics.DrawImage(StartForm.M.countryImageList.Images[e.Item.ImageKey], rectangle);
                }
                else { return; }
            }
        }

19 View Source File : MetroDropShadow.cs
License : MIT License
Project Creator : arsium

protected override void OnPaint(PaintEventArgs e)
		{
			e.Graphics.Clear(Color.FromArgb(0, 173, 239));//16, 26, 39

			using (Brush b = new SolidBrush(Color.FromArgb(0, 173, 239)))//0; 173; 239
			{
				e.Graphics.FillRectangle(b, new Rectangle(4, 4, ClientRectangle.Width - 8, ClientRectangle.Height - 8));
			}
		}

19 View Source File : WindowsTabControls.cs
License : MIT License
Project Creator : arsium

protected override void OnPaintBackground(PaintEventArgs pevent)
		{
			if (this.DesignMode == true)
			{
				LinearGradientBrush backBrush = new LinearGradientBrush(this.Bounds, SystemColors.ControlLightLight, SystemColors.ControlLight, LinearGradientMode.Vertical);
				pevent.Graphics.FillRectangle(backBrush, this.Bounds);
				backBrush.Dispose();
			}
			else
			{
				this.PaintTransparentBackground(pevent.Graphics, this.ClientRectangle);
			}
		}

19 View Source File : WindowsTabControls.cs
License : MIT License
Project Creator : arsium

protected void PaintTransparentBackground(Graphics g, Rectangle clipRect)
		{
			if (this.Parent != null)
			{
				clipRect.Offset(this.Location);
				PaintEventArgs e = new PaintEventArgs(g, clipRect);
				GraphicsState state = g.Save();
				g.SmoothingMode = SmoothingMode.HighSpeed;
				try
				{
					g.TranslateTransform((float)(-this.Location.X), (float)(-this.Location.Y));
					this.InvokePaintBackground(this.Parent, e);
					this.InvokePaint(this.Parent, e);
				}
				finally
				{
					g.Restore(state);
					clipRect.Offset(-this.Location.X, -this.Location.Y);
					//新加片段,待测试
					using (SolidBrush brush = new SolidBrush(_backColor))
					{
						clipRect.Inflate(1, 1);
						g.FillRectangle(brush, clipRect);
					}
				}
			}
			else
			{
				System.Drawing.Drawing2D.LinearGradientBrush backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(this.Bounds, SystemColors.ControlLightLight, SystemColors.ControlLight, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
				g.FillRectangle(backBrush, this.Bounds);
				backBrush.Dispose();
			}
		}

19 View Source File : SetupDialogForm.cs
License : GNU General Public License v3.0
Project Creator : ASCOMInitiative

void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0) return; // Do not paint if no item is selected

            ComboBox combo = sender as ComboBox;

            if (!combo.Enabled) return; // Do not paint if the combo box is disabled

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) // Draw the selected item in menu highlight colour
            {
                e.Graphics.FillRectangle(new SolidBrush(SystemColors.MenuHighlight), e.Bounds);
                e.Graphics.DrawString(combo.Items[e.Index].ToString(), e.Font, new SolidBrush(SystemColors.HighlightText), new Point(e.Bounds.X, e.Bounds.Y));
            }
            else
            {
                e.Graphics.FillRectangle(new SolidBrush(SystemColors.Window), e.Bounds);
                e.Graphics.DrawString(combo.Items[e.Index].ToString(), e.Font, new SolidBrush(combo.ForeColor), new Point(e.Bounds.X, e.Bounds.Y));
            }

            e.DrawFocusRectangle();
        }

19 View Source File : HideTabControlBorders.cs
License : GNU General Public License v3.0
Project Creator : ASCOMInitiative

protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == WM_PAINT)
            {
                using (Graphics g = Graphics.FromHwnd(m.HWnd))
                {

                    //Replace the outside white borders:
                    if (tabControl.Parent != null)
                    {
                        g.SetClip(new Rectangle(0, 0, tabControl.Width - 2, tabControl.Height - 1), CombineMode.Exclude);
                        using (SolidBrush sb = new SolidBrush(tabControl.Parent.BackColor))
                            g.FillRectangle(sb, new Rectangle(0,
                                                              tabControl.ItemSize.Height + 2,
                                                              tabControl.Width,
                                                              tabControl.Height - (tabControl.ItemSize.Height + 2)));
                    }

                    //Replace the inside white borders:
                    if (tabControl.SelectedTab != null)
                    {
                        g.ResetClip();
                        Rectangle r = tabControl.SelectedTab.Bounds;
                        g.SetClip(r, CombineMode.Exclude);
                        using (SolidBrush sb = new SolidBrush(tabControl.SelectedTab.BackColor))
                            g.FillRectangle(sb, new Rectangle(r.Left - 3,
                                                              r.Top - 1,
                                                              r.Width + 4,
                                                              r.Height + 3));
                    }
                }
            }
        }

19 View Source File : ServedDevice.cs
License : GNU General Public License v3.0
Project Creator : ASCOMInitiative

public void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0) return;

            ComboBox combo = sender as ComboBox;
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) // Draw the selected item in menu highlight colour
            {
                e.Graphics.FillRectangle(new SolidBrush(SystemColors.MenuHighlight), e.Bounds);
                e.Graphics.DrawString(combo.Items[e.Index].ToString(), e.Font, new SolidBrush(SystemColors.HighlightText), new Point(e.Bounds.X, e.Bounds.Y));
            }
            else
            {
                e.Graphics.FillRectangle(new SolidBrush(SystemColors.Window), e.Bounds);
                e.Graphics.DrawString(combo.Items[e.Index].ToString(), e.Font, new SolidBrush(combo.ForeColor), new Point(e.Bounds.X, e.Bounds.Y));
            }

            e.DrawFocusRectangle();
        }

19 View Source File : ProfileSelector.cs
License : MIT License
Project Creator : AstroTechies

private void ListBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0) return;

            string decidedText = ((KeyValuePair<string, ModProfile>)listBox1.Items[e.Index]).Key;
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, e.State ^ DrawItemState.Selected, AMLPalette.ForeColor, AMLPalette.HighlightColor);
            }

            Rectangle decidedNewBounds = new Rectangle(e.Bounds.Location.X + (AMLPalette.BorderPenWidth / 2), e.Bounds.Location.Y + (AMLPalette.BorderPenWidth / 2), e.Bounds.Width - AMLPalette.BorderPenWidth, e.Bounds.Height);

            e.Graphics.FillRectangle(new SolidBrush(e.BackColor), decidedNewBounds);
            e.Graphics.DrawString(decidedText, e.Font, new SolidBrush(AMLPalette.ForeColor), decidedNewBounds, StringFormat.GenericDefault);
            if ((e.State & DrawItemState.Focus) == DrawItemState.Focus && (e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, decidedNewBounds, e.ForeColor, e.BackColor);
            }
        }

19 View Source File : SettingsForm.cs
License : GNU General Public License v3.0
Project Creator : audiamus

private void tabControl1_DrawItem (object sender, DrawItemEventArgs e) {
      TabPage tp = tabControl1.TabPages[e.Index];
      using (SolidBrush brush =
             new SolidBrush (Enabled ? tp.BackColor : SystemColors.ControlLight))
      using (SolidBrush textBrush =
             new SolidBrush (Enabled ? tp.ForeColor : SystemColors.ControlDark)) {
        e.Graphics.FillRectangle (brush, e.Bounds);
        e.Graphics.DrawString (tp.Text, e.Font, textBrush, e.Bounds.X + 1, e.Bounds.Y + 3);
      }
    }

19 View Source File : FocusControl.cs
License : GNU General Public License v3.0
Project Creator : aurelitec

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            // Draw the active or inactive focus border only when the control is fully created, not while creating it with the mouse
            if (this.creationEnded)
            {
                // Draw the active or inactive focus border
                e.Graphics.DrawRectangle(this.Focused ? this.borderFocusPen : this.borderClearPen, this.ClientRectangle);

                // Draw the slightly darker dragging section of the top border
                if (this.Focused && this.Width > this.BorderSize * 2)
                {
                    int left = Math.Max(this.ClientRectangle.Width / 4, this.BorderSize);
                    int width = Math.Min(2 * (this.ClientRectangle.Width / 4), this.Width - (this.BorderSize * 2));
                    Rectangle northDragBounds = new Rectangle(left, 0, width, this.BorderSize / 2);
                    e.Graphics.FillRectangle(this.borderDragBrush, northDragBounds);
                }
            }
        }

19 View Source File : SimpleProgressBar.cs
License : MIT License
Project Creator : AutoItConsulting

protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            var brush = new SolidBrush(ForeColor);
            float percent = (_val - _min) / (float)(_max - _min);
            Rectangle rect = ClientRectangle;

            // Calculate area for drawing the progress.
            rect.Width = (int)(rect.Width * percent);

            // Draw the progress meter.
            g.FillRectangle(brush, rect);

            // Draw a three-dimensional border around the control.
            if (DrawBorder)
            {
                Draw3DBorder(g);
            }

            // Clean up.
            brush.Dispose();
            g.Dispose();
        }

19 View Source File : WidgetRenderer.cs
License : MIT License
Project Creator : azist

private Image drawGDIPuzzleKeypadImage(PuzzleKeypad keypad, Color? bgColor = null, bool showRects = false)
    {
      var sz = keypad.Size;
      var result = new Bitmap(sz.Width + PuzzleKeypad.DEFAULT_RENDER_OFFSET_X * 2, sz.Height + PuzzleKeypad.DEFAULT_RENDER_OFFSET_Y * 2);
      using (var gr = System.Drawing.Graphics.FromImage(result))
      {
        if (bgColor.HasValue)
          gr.Clear(bgColor.Value);

        gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

        var boxPen = new Pen(Color.FromArgb(240, 240, 240), 1.0f);

        var boxPen2 = new Pen(Color.FromArgb(200, 200, 200), 1.3f);
        boxPen2.DashStyle = DashStyle.Dot;

        var shadowPen = new Pen(Color.FromArgb(255, 220, 220, 220), 1.0f);

        LinearGradientBrush paperBrush = null;
        Font font = null;
        LinearGradientBrush fntBrush = null;
        LinearGradientBrush fntBadBrush = null;

        try
        {
          foreach (var box in keypad.Boxes)
          {
            if (paperBrush == null)
            {
              paperBrush = new LinearGradientBrush(box.Rect, Color.FromArgb(240, 240, 240), Color.FromArgb(255, 255, 255), LinearGradientMode.Vertical);
              paperBrush.WrapMode = WrapMode.TileFlipXY;
            }

            if (fntBrush == null)
            {
              fntBrush = new LinearGradientBrush(box.Rect, Color.FromArgb(240, 240, 250), Color.FromArgb(100, 80, 150), LinearGradientMode.ForwardDiagonal);
              fntBrush.WrapMode = WrapMode.TileFlipXY;

              fntBadBrush = new LinearGradientBrush(box.Rect, Color.FromArgb(240, 240, 250), Color.FromArgb(200, 180, 255), LinearGradientMode.Vertical);
              fntBadBrush.WrapMode = WrapMode.TileFlipXY;
            }

            if (font == null)
            {
              font = new Font("Courier New", box.Rect.Height * 0.65f, FontStyle.Bold, GraphicsUnit.Pixel);
            }


            gr.ResetTransform();
            gr.TranslateTransform(PuzzleKeypad.DEFAULT_RENDER_OFFSET_X, PuzzleKeypad.DEFAULT_RENDER_OFFSET_Y);

            if (showRects)
              gr.DrawRectangle(Pens.Red, box.Rect);

            var rnd = App.Random;

            gr.RotateTransform((float)(-3d + (6d * rnd.NextRandomDouble)));

            var pTL = new Point(box.Rect.Left + rnd.NextScaledRandomInteger(-6, +6),
                                 box.Rect.Top + rnd.NextScaledRandomInteger(-6, +6));

            var pTR = new Point(box.Rect.Right + rnd.NextScaledRandomInteger(-6, +6),
                                 box.Rect.Top  + rnd.NextScaledRandomInteger(-6, +6));

            var pBL = new Point(box.Rect.Left    + rnd.NextScaledRandomInteger(-6, +6),
                                 box.Rect.Bottom + rnd.NextScaledRandomInteger(-6, +6));

            var pBR = new Point(box.Rect.Right   + rnd.NextScaledRandomInteger(-6, +6),
                                 box.Rect.Bottom + rnd.NextScaledRandomInteger(-6, +6));

            var pa = new[] { pTL, pTR, pBR, pBL };
            gr.FillPolygon(paperBrush, pa);
            gr.DrawPolygon(boxPen, pa);

            //gr.FillRectangle(paperBrush, box.Rect);
            //gr.DrawRectangle(boxPen, box.Rect);

            //var distortedBRX = box.Rect.Right + ExternalRandomGenerator.Instance.NextScaledRandomInteger(-10, +4);
            //var distortedBRY = box.Rect.Bottom + ExternalRandomGenerator.Instance.NextScaledRandomInteger(-10, +8);

            gr.DrawLine(shadowPen, pTR, pBR);

            gr.DrawLine(boxPen2, pBL.X + 1, pBL.Y, pBR.X - 1, pBR.Y);
            gr.DrawLine(boxPen2, pBL.X, pBL.Y + 1, pBR.X - 2, pBR.Y + 1);


            var tsz = gr.MeasureString(box.Char.ToString(), font);
            var pnt = new PointF((box.Rect.Left + box.Rect.Width / 2f) - tsz.Width / 2f,
                                  (box.Rect.Top + box.Rect.Height / 2f) - tsz.Height / 2f);


            if (rnd.NextScaledRandomInteger(0, 100) > 40)
            {
              var bpnt = pnt;
              bpnt.X += rnd.NextScaledRandomInteger(-2, 4);
              bpnt.Y += rnd.NextScaledRandomInteger(-2, 4);
              gr.DrawString(box.Char.ToString(), font, fntBadBrush, bpnt);

              for (var i = 0; i < rnd.NextScaledRandomInteger(8, 75); i++)
              {
                gr.FillRectangle(fntBadBrush, new Rectangle(box.Rect.Left + rnd.NextScaledRandomInteger(0, box.Rect.Width - 4),
                                                            box.Rect.Top + rnd.NextScaledRandomInteger(0, box.Rect.Height - 4),
                                                            rnd.NextScaledRandomInteger(1, 4),
                                                            rnd.NextScaledRandomInteger(1, 4)
                                                            ));

              }
            }

            gr.DrawString(box.Char.ToString(), font, fntBrush, pnt);
          }
        }
        finally
        {
          if (boxPen != null) boxPen.Dispose();
          if (boxPen2 != null) boxPen2.Dispose();
          if (shadowPen != null) shadowPen.Dispose();
          if (paperBrush != null) paperBrush.Dispose();
          if (font != null) font.Dispose();
          if (fntBrush != null)
          {
            fntBrush.Dispose();
            fntBadBrush.Dispose();
          }
        }

      }
      return result;
    }

19 View Source File : SymbolElement.cs
License : MIT License
Project Creator : azist

protected internal override void Paint(System.Drawing.Graphics gr)
      {
         Point midPoint = new Point(Region.Left + Region.Width / 2,
                                    Region.Top + Region.Height / 2);
         int dim; //min dimension, cant span more than that
         dim = Region.Width;
         if (Region.Height < dim) dim = Region.Height;

         Rectangle rect = new Rectangle(midPoint.X - dim / 2,
                                        midPoint.Y - dim / 2,
                                        dim,
                                        dim);

         gr.SmoothingMode = SmoothingMode.AntiAlias;

         using( LinearGradientBrush brush = new LinearGradientBrush(rect, Color.White, m_BrushColor, m_BrushGradientAngle) )
         {
           using ( Pen pen = new Pen(m_PenColor, m_PenWidth) )
           {


                 switch(m_SymbolType)
                 {
                   case SymbolType.Circle:
                   {
                     gr.FillEllipse(brush, rect);
                     gr.DrawEllipse(pen, rect);
                     break;
                   }

                   case SymbolType.Square:
                   {
                     gr.FillRectangle(brush, rect);
                     gr.DrawRectangle(pen, rect);
                     break;
                   }

                   case SymbolType.Diamond:
                   {
                     Point [] vtx = new Point[4];
                     vtx[0] = new Point(midPoint.X, rect.Top); //north
                     vtx[1] = new Point(rect.Right, midPoint.Y); //east
                     vtx[2] = new Point(midPoint.X, rect.Bottom); //south
                     vtx[3] = new Point(rect.Left, midPoint.Y); //west
                     gr.FillPolygon(brush, vtx);
                     gr.DrawPolygon(pen, vtx);
                     break;
                   }

                   case SymbolType.TriangleUp:
                   {
                     Point[] vtx = new Point[3];
                     vtx[0] = new Point(midPoint.X, rect.Top); //north
                     vtx[1] = new Point(rect.Right, midPoint.Y); //east
                     vtx[2] = new Point(rect.Left, midPoint.Y); //west
                     gr.FillPolygon(brush, vtx);
                     gr.DrawPolygon(pen, vtx);
                     break;
                   }


                   case SymbolType.TriangleDown:
                   {
                     Point[] vtx = new Point[3];
                     vtx[0] = new Point(midPoint.X, rect.Bottom); //south
                     vtx[1] = new Point(rect.Right, midPoint.Y); //east
                     vtx[2] = new Point(rect.Left, midPoint.Y); //west
                     gr.FillPolygon(brush, vtx);
                     gr.DrawPolygon(pen, vtx);
                     break;
                   }


                   case SymbolType.TriangleLeft:
                   {
                     Point[] vtx = new Point[3];
                     vtx[0] = new Point(midPoint.X, rect.Top); //north
                     vtx[1] = new Point(midPoint.X, rect.Bottom); //south
                     vtx[2] = new Point(rect.Left, midPoint.Y); //west
                     gr.FillPolygon(brush, vtx);
                     gr.DrawPolygon(pen, vtx);
                     break;
                   }


                   case SymbolType.TriangleRight:
                   {
                     Point[] vtx = new Point[3];
                     vtx[0] = new Point(midPoint.X, rect.Top); //north
                     vtx[1] = new Point(midPoint.X, rect.Bottom); //south
                     vtx[2] = new Point(rect.Right, midPoint.Y); //east
                     gr.FillPolygon(brush, vtx);
                     gr.DrawPolygon(pen, vtx);
                     break;
                   }

                 } //switch

           }//using pen
         }//using brush
      }

19 View Source File : CandleView.cs
License : MIT License
Project Creator : azist

protected internal override void Paint(System.Drawing.Graphics gr)
                 {
                   //for now, no styles
                     using(var pen = getContourPen(new LineStyle{ Color = Color.Black,
                                                                  Width = 1,
                                                                  DashStyle = System.Drawing.Drawing2D.DashStyle.Solid}))
                     {
                  //     gr.DrawLine(pen, m_Lay_X+1, m_Lay_HighTickY, m_Lay_X+m_Lay_W-2, m_Lay_HighTickY); //High tick
                  //     gr.DrawLine(pen, m_Lay_X+1, m_Lay_LowTickY, m_Lay_X+m_Lay_W-2, m_Lay_LowTickY); //Low tick

                       var x = m_Lay_X + (m_Lay_W/2);
                       gr.DrawLine(pen,x, m_Lay_LowTickY, x, m_Lay_HighTickY); //Vertical



                    // using(var brush = getBrush(m_Style))//body
                     {
                       var brush = m_BW ? Brushes.Silver : ( m_Lay_Inc ? Brushes.LimeGreen : Brushes.Red );
                       gr.FillRectangle(brush, m_Lay_Body);
                     }

                       gr.DrawRectangle(pen, m_Lay_Body);
                     }
                 }

19 View Source File : ComboBoxEx.cs
License : MIT License
Project Creator : azist

protected override void OnDrawItem(DrawItemEventArgs e)
    {
      if (e.Index < 0) return;

      e.Graphics.FillRectangle(
          (e.State & DrawItemState.Selected) == DrawItemState.Selected
              ? new SolidBrush(HighlightColor)
              : new SolidBrush(this.BackColor),
          e.Bounds);

      e.Graphics.DrawString(Items[e.Index].ToString(), e.Font,
                            new SolidBrush(ForeColor),
                            new Point(e.Bounds.X, e.Bounds.Y));

      e.DrawFocusRectangle();

      base.OnDrawItem(e);
    }

19 View Source File : Theme.cs
License : MIT License
Project Creator : b9q

protected override void OnPaint(PaintEventArgs e)
    {
        Bitmap b = new Bitmap(Width, Height);
        using (Graphics g = Graphics.FromImage(b))
        {
            g.Clear(Color.FromArgb(254, 255, 255));

            for (int i = 0; i <= TabCount - 1; i++)
            {
                Rectangle TabRectangle = GetTabRect(i);

                //fix tab position
                TabRectangle.X += 2;
                //TabRectangle.Height = 34;
                TabRectangle.Y += 1;

                Rectangle stringRect = TabRectangle;
                stringRect.X += 3;

                if (i == SelectedIndex)
                {
                    g.FillRectangle(Drawing.tehColor, TabRectangle);
                    g.DrawString(TabPages[i].Text, _font, Brushes.White, stringRect, new StringFormat
                    {
                        LineAlignment = StringAlignment.Center,
                        Alignment = StringAlignment.Near
                    });
                }
                else
                {
                    g.DrawRectangle(new Pen(Color.FromArgb(208, 230, 246)), TabRectangle);
                    g.DrawString(TabPages[i].Text, _font, Drawing.tehColor, stringRect, new StringFormat
                    {
                        LineAlignment = StringAlignment.Center,
                        Alignment = StringAlignment.Near
                    });
                }

                g.DrawLine(new Pen(Drawing.tehColor), new Point(TabRectangle.X, TabRectangle.Y + TabRectangle.Height),
                    new Point(this.Width - 5, TabRectangle.Y + TabRectangle.Height));
            }

            e.Graphics.DrawImage(b, 0, 0);
        }

        b.Dispose();
        base.OnPaint(e);
    }

19 View Source File : Theme.cs
License : MIT License
Project Creator : b9q

public static void DrawWithOutline(Graphics G, Brush InnerBrush, Brush OutlineBrush, Rectangle Rectangle)
    {
        G.FillRectangle(InnerBrush, Rectangle);
        G.DrawRectangle(new Pen(OutlineBrush), Rectangle);
    }

19 View Source File : Theme.cs
License : MIT License
Project Creator : b9q

protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        using (Graphics g = e.Graphics)
        {
            g.Clear(Color.FromArgb(246, 251, 254));

            g.FillRectangle(new SolidBrush(Color.FromArgb(254, 255, 255)), new Rectangle(0, replacedleHeight, Width, Height));
            using (Pen thickness = new Pen(Drawing.tehColor))
            {
                thickness.Width = 2.0F;
                g.DrawRectangle(thickness, new Rectangle(1, 1, Width - 2, Height - 2)); //outline
            }

            using (Pen thickness = new Pen(Drawing.underlineColor))
            {
                thickness.Width = 1.5F;
                g.DrawLine(thickness, 4, replacedleHeight, Width - 4, replacedleHeight); //replacedleline
            }

            //replacedle text
            g.DrawString(Text, Font, new SolidBrush(Color.FromArgb(220, 20, 60)), new Rectangle(7, 0, Width, replacedleHeight + 2), new StringFormat
            {
                Alignment = StringAlignment.Near,
                LineAlignment = StringAlignment.Center
            });
        }
    }

See More Examples