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

わんくま同盟

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

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


■103797 / )  Re[8]: Visual Basicで簡易CADを作成
□投稿者/ shiro (5回)-(2025/08/01(Fri) 06:15:16)
魔界の仮面弁士 様


ご助言有難うございます。

「ポリモーフィズムな実装」など、画像処理を始めたばかりで難解で、
まずはListで処理をしようと思います。

下記のとおりListで試したところ、Invalidate メソッドで壁も柱も
残ったのですが、壁を配置するとき、次の壁を書くと、直前に書いた壁が消えます。
結局、最後に書いた壁だけが残ります。

全て配置した壁を残る場合はどうすれば良いか上手くいきません。

     記

Public Class Form1

    Private pointList As New List(Of Point)
    Private element As String
    Private startPoint As Point
    Private endPoint As Point
    Private isDragging As Boolean = False

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

        Select Case element

                Case "wall"

                    startPoint = SnapToGrid(e.Location)

                     isDragging = True

        End Select

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

        Select Case element

            Case "wall"
 
                If isDragging Then
                    endPoint = SnapToGrid(e.Location)
                    PictureBox1.Invalidate()
                End If

        End Select

    End Sub


    Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp

        isDragging = False
 
        pointList.Clear()
        pointList.Add(startPoint)
        pointList.Add(endPoint)

        PictureBox1.Invalidate()

    End Sub

    Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint

        Dim pen7 As New Pen(Color.Blue, 5)

        If isDragging Then
            e.Graphics.DrawLine(Pens.Blue, startPoint, endPoint)
        ElseIf pointList.Count = 2 Then
            e.Graphics.DrawLine(Pen7, pointList(0), pointList(1))
        End If

    End Sub


返信 編集キー/


管理者用

- Child Tree -