/// <summary> /// Draws preview on the appearance tab /// </summary> private void DrawAppearancePreview() { ShpfileType shapeType = _shapefile.ShapefileType; for (int i = 0; i < 2; i++) { ShapeDrawingOptions sdo = new ShapeDrawingOptions(); PictureBox pct = new PictureBox(); pct = pictureBox1; sdo = _shapefile.DefaultDrawingOptions; if (pct.Image != null) { pct.Image.Dispose(); } Rectangle rect = pct.ClientRectangle; Bitmap bmp = new Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmp); IntPtr ptr = g.GetHdc(); if (shapeType == ShpfileType.SHP_POINT || shapeType == ShpfileType.SHP_POINTM || shapeType == ShpfileType.SHP_POINTZ || shapeType == ShpfileType.SHP_MULTIPOINT || shapeType == ShpfileType.SHP_MULTIPOINTM || shapeType == ShpfileType.SHP_MULTIPOINTZ) { sdo.DrawPoint(ptr.ToInt32(), 0.0f, 0.0f, rect.Width, rect.Height, Colors.ColorToUInteger(Color.White)); } else if (shapeType == ShpfileType.SHP_POLYLINE || shapeType == ShpfileType.SHP_POLYLINEZ || shapeType == ShpfileType.SHP_POLYLINEM) { if (sdo.UseLinePattern) { sdo.DrawLine(ptr.ToInt32(), 20.0f, 0.0f, 0, 0, true, rect.Width - 40, rect.Height, Colors.ColorToUInteger(Color.White)); } else { int w = rect.Width - 40; int h = rect.Height - 40; sdo.DrawLine(ptr.ToInt32(), (rect.Width - w) / 2, (rect.Height - h) / 2, w, h, true, rect.Width, rect.Height, Colors.ColorToUInteger(Color.White)); } } else if (shapeType == ShpfileType.SHP_POLYGON || shapeType == ShpfileType.SHP_POLYGONZ || shapeType == ShpfileType.SHP_POLYGONM) { sdo.DrawRectangle(ptr.ToInt32(), rect.Width / 2 - 40, rect.Height / 2 - 40, 80, 80, true, rect.Width, rect.Height, Colors.ColorToUInteger(Color.White)); } g.ReleaseHdc(ptr); pct.Image = bmp; } }
public bool DrawLine(IntPtr hdc, float x, float y, int width, int height, bool drawVertices, int clipWidth, int clipHeight, Color?backColor = null) { var hdcInt = hdc.ToInt32(); return(_style.DrawLine(hdcInt, x, y, width, height, drawVertices, clipWidth, clipHeight, backColor.ToUInt())); }
private void DrawPreview() { if (_noEvents) { return; } if (pctPreview.Image != null) { pctPreview.Image.Dispose(); } Rectangle rect = pctPreview.ClientRectangle; Bitmap bmp = new Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmp); IntPtr ptr = g.GetHdc(); // creating shape to draw if (_shpFileType == ShpfileType.SHP_POLYGON) { _options.DrawRectangle(ptr, 40.0f, 40.0f, rect.Width - 80, rect.Height - 80, true, rect.Width, rect.Height, Colors.ColorToUInteger(this.BackColor)); } else { _options.DrawLine(ptr, 40.0f, 40.0f, rect.Width - 80, rect.Height - 80, true, rect.Width, rect.Height, Colors.ColorToUInteger(this.BackColor)); } g.ReleaseHdc(); pctPreview.Image = bmp; }
/// <summary> /// Draws shapefile category. /// </summary> private void DrawShapefileCategorySymbology(int hdcInt, int top, ShapeDrawingOptions options, int categoryIndex, bool hasCheckbox) { var categoryHeight = _layer.GetCategoryHeight(options); var categoryWidth = _layer.GetCategoryWidth(options); var backColor = Convert.ToUInt32(ColorTranslator.ToOle(Legend.BackColor)); var left = _bounds.Left + Constants.TextLeftPad; if (hasCheckbox) { left += Constants.CategoryCheckboxWidthWithPadding; } if (categoryWidth != Constants.IconWidth) { left -= (categoryWidth - Constants.IconWidth) / 2; } var topCentering = (Constants.ItemHeight - Constants.IconHeight) / 2 - 1; switch (_layer.LegendLayerType) { case LegendLayerType.PointShapefile: options.DrawPoint(hdcInt, left, top, categoryWidth + 1, categoryHeight + 1, backColor); break; case LegendLayerType.LineShapefile: options.DrawLine( hdcInt, left, top + topCentering, categoryWidth - 1, Constants.IconHeight - 1, false, categoryWidth, categoryHeight, backColor); break; case LegendLayerType.PolygonShapefile: options.DrawRectangle( hdcInt, left, top + topCentering, categoryWidth - 1, Constants.IconHeight - 1, false, categoryWidth, categoryHeight, backColor); break; } _layer.Elements.Add(LayerElementType.ColorBox, new Rectangle(left, top, categoryWidth, categoryHeight), categoryIndex); }
/// <summary> /// 绘制单元格 /// </summary> private void dgvCategories_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex != CMN_STYLE) { return; } if (e.RowIndex >= 0 && e.RowIndex < _shapefile.Categories.Count) { System.Drawing.Image img = e.Value as System.Drawing.Image; if (img == null) { return; } ShapefileCategory cat = _shapefile.Categories.get_Item(e.RowIndex); if (cat == null) { return; } ShapeDrawingOptions sdo = cat.DrawingOptions; Graphics g = Graphics.FromImage(img); g.Clear(Color.White); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; if (_shapefile.ShapefileType == ShpfileType.SHP_POLYGON) { sdo.DrawRectangle(g.GetHdc(), 0, 0, img.Width - 1, img.Height - 1, true, img.Width, img.Height, Colors.ColorToUInteger(dgvCategories.BackgroundColor)); } else if (_shapefile.ShapefileType == ShpfileType.SHP_POLYLINE) { sdo.DrawLine(g.GetHdc(), 0, 0, img.Width - 1, img.Height - 1, true, img.Width, img.Height, Colors.ColorToUInteger(dgvCategories.BackgroundColor)); } else if (_shapefile.ShapefileType == ShpfileType.SHP_POINT) { sdo.DrawPoint(g.GetHdc(), 0.0f, 0.0f, img.Width, img.Height, Colors.ColorToUInteger(dgvCategories.BackgroundColor)); } g.ReleaseHdc(); g.Dispose(); } }