0

Visual Basic のFormで、現dirからcsvファイルを読み込んで、図形を描くコードの作成をしています。

初心者のため、csvファイルの入出力が分かりませんので、
最初に座標nodeと要素element(node番号を線分で接続)するFormを以下のように作成しました。
動作は正しく動きました。

以下のコードで、Point部分に①のnode.csvからx、y座標を読み込んで、
②elementのように2点のnodeを線分で繋いで図を作成したいのですが、
初心者のため躓いていました。

ご知見を頂けますと有難く存じます。

Public Class Form1
    Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint

        Dim point1 As New Point(200, 400)  'node1
        Dim point2 As New Point(200, 100)  'node2

        e.Graphics.DrawLine(Pens.Blue, point1, point2)  'elem1

        Dim point11 As New Point(650, 400)  'node11
        Dim point12 As New Point(650, 100)  'node12

        e.Graphics.DrawLine(Pens.Blue, point11, point12)  'elem2

        Dim point3 As New Point(250, 100)  'node3
        Dim point4 As New Point(300, 100)  'node4
        Dim point5 As New Point(350, 100)  'node5
        Dim point6 As New Point(400, 100)  'node6
        Dim point7 As New Point(450, 100)  'node7
        Dim point8 As New Point(500, 100)  'node8
        Dim point9 As New Point(550, 100)  'node9
        Dim point10 As New Point(600, 100)  'node10

        e.Graphics.DrawLine(Pens.Blue, point2, point3)  'elem3
        e.Graphics.DrawLine(Pens.Blue, point3, point4)  'elem4
        e.Graphics.DrawLine(Pens.Blue, point4, point5)  'elem5
        e.Graphics.DrawLine(Pens.Blue, point5, point6)  'elem6
        e.Graphics.DrawLine(Pens.Blue, point6, point7)  'elem7
        e.Graphics.DrawLine(Pens.Blue, point7, point8)  'elem8
        e.Graphics.DrawLine(Pens.Blue, point8, point9)  'elem9
        e.Graphics.DrawLine(Pens.Blue, point9, point10)  'elem10
        e.Graphics.DrawLine(Pens.Blue, point10, point12)  'elem11

    End Sub

End Class

①node.csv

200 400
200 100
250 100
300 100
350 100
400 100
450 100
500 100
550 100
600 100
650 400
650 100

②element.csv

1   2
11  12
2   3
3   4
4   5
5   6
6   7
7   8
8   9
9   10
10  12
5
  • 質問は何ですか? CVS ファイルを読み込む方法ですか? 質問を書いてください。あと、Windows Forms アプリでグラフを作るなら、Chart の利用を考えてはいかがですか? サンプルを入手できます ⇒ surferonwww.info/BlogEngine/post/2021/11/30/…
    – WebSurfer
    3月25日 11:44
  • nodeファイルとelementファイルは上からnode1,element1成分としています。座標をその都度ソースに記録するのではなく、汎用的にcsvファイルから読み込んでしたいです。イメージは次のような感じです element(i, j) iは要素数で12要素、jは両側のnode座標で、x(1), y(1), x(2), y(2)。 要素数12個をForループで描きたいです。 e.Graphics.DrawLine(Pens.Blue, x(1), y(1), x(2), y(2)) 'elem1
    – shiro
    3月25日 21:12
  • 質問は何か依然としてわかりません。Chart の利用をお勧めしましたがスルーですか?
    – WebSurfer
    3月25日 23:03
  • 一つの質問に多くを詰め込むのではなく、細かい段階に分けて1個づつ片付ける方が良いでしょう。CSVファイルの読み込みはこんな記事を参考に。VB.NET - CSVファイル読込処理
    – kunif
    3月26日 3:35
  • 様々なアドバイスのお陰で問題解決出来ました。今後はFormに描かれた画像をjpegなどの形式で保存するなど、改良していきたいと思います。また、Chartも勉強させて頂きます。
    – shiro
    3月26日 10:02

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。