freeHand Draw

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
        Me.PictureBox1.Location = New System.Drawing.Point(24, 64)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(440, 232)
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Label1.Location = New System.Drawing.Point(40, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(416, 32)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "free hand Draw  By  wgscd       QQ:153964481"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(224, Byte), CType(192, Byte))
        Me.ClientSize = New System.Drawing.Size(496, 334)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.PictureBox1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region
 

    Dim mousePath As New System.Drawing.Drawing2D.GraphicsPath   'declare a new Graphic path to follow the mouse movement
    Dim myAlpha As Integer = 100 ' declare a Alpha variable
    Dim myUserColor As New Color   'this is a color the user selects
    Dim myPenWidth As Single = 5 'set pen width variable

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown

        If e.Button = MouseButtons.Left Then ' draw a filled circle if left mouse is down 

            mousePath.StartFigure()   ' The L mouse is down so we need to start a new line in mousePath

        End If

    End Sub


    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

        If e.Button = MouseButtons.Left Then ' draw a filled circle if left mouse is down 

            Try
                mousePath.AddLine(e.X, e.Y, e.X, e.Y)  'Add mouse coordiantes to mousePath

            Catch
                MsgBox("No way, Hose!")
            End Try

        End If

        PictureBox1.Invalidate() 'Repaint the PictureBox using the PictureBox1 Paint event

    End Sub

    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint


        Try

            myUserColor = (System.Drawing.Color.Black)
            myAlpha = 100

            Dim CurrentPen = New Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth) 'Set up the pen

            e.Graphics.DrawPath(CurrentPen, mousePath)  'draw the path! :)

        Catch
            ' MsgBox("Not happening!")
        End Try


    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

### OpenLayers Draw 功能使用教程 #### 创建地图实例 为了实现绘图功能,首先需要创建一个基本的地图实例。这涉及到初始化视图、设置投影以及加载底图瓦片。 ```javascript import 'ol/ol.css'; import Map from 'ol/Map'; import View from 'ol/View'; import TileLayer from 'ol/layer/Tile'; import OSM from 'ol/source.OSM'; const map = new Map({ target: 'map', layers: [ new TileLayer({ source: new OSM() }) ], view: new View({ center: [0, 0], zoom: 2 }) }); ``` #### 添加矢量图层用于存储绘制要素 为了让用户能够在地图上画出几何对象(如点、线或多边形),需添加一个`VectorSource`作为数据源,并将其绑定至一个新的`VectorLayer`之上。 ```javascript import VectorSource from 'ol/source/Vector'; import VectorLayer from 'ol/layer/Vector'; import {Style, Stroke, Fill} from 'ol/style'; // 定义样式 const style = new Style({ stroke: new Stroke({color: '#ffcc33', width: 2}), fill: new Fill({color: 'rgba(255, 204, 51, 0.4)'}) }); // 初始化向量图层及其数据源 const vectorSource = new VectorSource(); const vectorLayer = new VectorLayer({ source: vectorSource, style: style }); // 将新图层加入到现有地图中 map.addLayer(vectorLayer); ``` #### 实现交互式绘图工具 通过引入`Draw`控件来允许用户直接在浏览器窗口内的地图界面上进行操作。这里展示了如何配置不同类型的地理实体供选择性地绘制出来。 ```javascript import Draw from 'ol/interaction/Draw'; let draw; // global so we can remove it later function addInteraction(type) { draw = new Draw({ source: vectorSource, type: /** @type {GeometryType} */ (type), freehand: true }); map.addInteraction(draw); // 监听drawend事件,在此之后可以访问最新的Feature draw.on('drawend', function(event){ const feature = event.feature; console.log(feature.getGeometry()); }, this); } addInteraction('Polygon'); // 更改参数可切换其他模式比如'Point','LineString' ``` 上述代码片段实现了基于OpenLayers框架下的简单绘图机制[^1]。当调用`addInteraction()`函数时传入特定字符串值即可指定想要激活的编辑状态;而每当完成一次完整的形状构建动作后都会触发相应的回调处理逻辑以便进一步利用这些空间信息做更多事情[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值