C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


■103795 / )  Re[6]: Visual Basicで簡易CADを作成
□投稿者/ shiro (4回)-(2025/07/31(Thu) 07:34:24)
魔界の仮面弁士 様

ダブルクリックでの画像消去コード有難うございました。
非常に参考になりました。

Form1 上に
 Private element As String
は設定していました。

参考のListは「polygon」となっています。
これですと、グリッドの交点を掴むと、スパン幅(1m)に壁が配置されてしまいます。

私のwallはグリッドの2点の交点を結んで、線分の幅で厚さを表そうとしています。
これですと実際のCADに近くなり使いやすいです。
その場合、Pointになるのではと思い、下記のとおり簡単なListを作ってみました。

しかし、今度は次の壁を描こうとすると前のが消えてしまいます。

Paintで「For Each」で描かないとダメなのでしょうか。
その場合のコード記述が分かりませんでした。


       記

   Private startPoint As Point
    Private endPoint As Point
    Private isDragging As Boolean = False

     Private pointList As New List(Of Point)



    Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
        startPoint = SnapToGrid(e.Location)
        isDragging = True
    End Sub

    Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
        If isDragging Then
            endPoint = SnapToGrid(e.Location)
            PictureBox1.Invalidate()
        End If
    End Sub

    Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
        isDragging = False
         endPoint = SnapToGrid(e.Location)
        PictureBox1.Invalidate()
    End Sub

    Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
        Dim pen As New Pen(Color.Black, 1)
        ' グリッド描画
        For i = 0 To PictureBox1.Width Step 10
            e.Graphics.DrawLine(pen, i, 0, i, PictureBox1.Height)
        Next
        For j = 0 To PictureBox1.Height Step 10
            e.Graphics.DrawLine(pen, 0, j, PictureBox1.Width, j)
        Next

        ' ラバーバンド線描画
        ' If isDragging Then
        Dim rubberPen As New Pen(Color.Blue, 5)
        rubberPen.DashStyle = Drawing2D.DashStyle.Solid

        e.Graphics.DrawLine(rubberPen, startPoint, endPoint)
        'End If
    End Sub


返信 編集キー/


管理者用

- Child Tree -