/// 実習H3 グラフィックス(1) プログラミング実習 目次に戻る
 back next 

プロジェクト名  実習H3ペンの設定

動作説明

 いろいろな種類の直線を描画する。

デザイン

実習H3のデザイン
フォーム Form1
 Size = 300, 300

ピクチャボックス picCanvas
 BackColor = White (白)
 BorderStyle = FixedSingle
 Location = 12, 12
 Size = 268, 242

コード(プログラム)

Public Class Form1
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Bitmapオブジェクト作成
    picCAnvas.Image = New Bitmap(picCAnvas.Width, picCAnvas.Height)
    'Graphicsオブジェクト作成
    Dim gr As Graphics = Graphics.FromImage(picCAnvas.Image)
    'Penオブジェクト作成
    Dim MyPen As New Pen(Color.Red, 8)
    gr.DrawLine(MyPen, 10, 10, 250, 10)  '赤色、太さ8pix

    MyPen.Color = Color.Green
    MyPen.Width = 5
    gr.DrawLine(MyPen, 10, 21, 250, 21)  '緑色、太さ5pix

     @  = Color.Blue
     A  = 3
    gr.DrawLine(MyPen, 10, 29, 250, 29)  '青色、太さ3pix

    MyPen.DashStyle = Drawing2D.DashStyle.Dash
    gr.DrawLine(MyPen, 10, 40, 250, 40)  '青色、太さ3pix、破線

    MyPen.DashStyle = Drawing2D.DashStyle.Dot
    gr.DrawLine(MyPen, 10, 50, 250, 50)  '青色、太さ3pix、点線

     B  = Drawing2D.DashStyle.Solid  '直線の設定
    MyPen.Width = 5
    MyPen.Color = Color.Red
    MyPen.EndCap = Drawing2D.LineCap.ArrowAnchor
    gr.DrawLine(MyPen, 10, 60, 250, 60)  '赤色、太さ5pix、終点に矢印

    MyPen.Color = Color.Green
    MyPen.StartCap = Drawing2D.LineCap.ArrowAnchor
    gr.DrawLine(MyPen, 10, 70, 250, 70)  '赤色、太さ5pix、両端に矢印

    MyPen.Color = Color.Blue
    MyPen.EndCap = Drawing2D.LineCap.NoAnchor
     C (MyPen, 10, 80, 250, 80)  '赤色、太さ5pix、始点に矢印

    picCAnvas.Refresh()    'picCanvasの更新
    gr.Dispose()        'オブジェクト解放
    MyPen.Dispose()   'オブジェクト解放
  End Sub
End Class

解答欄(英数字は半角で入力すること。余分な空白は入れないこと)
  @   A   B   C
   解答を入力し、[解答チェック]ボタンをクリックする。正解は   、不正解は   で表示される。

 直線を1本ずつ描画するところまでプログラムを入力して実行しながら確認するとよい。まずは、次のように。

Public Class Form1
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Bitmapオブジェクト作成
    picCAnvas.Image = New Bitmap(picCAnvas.Width, picCAnvas.Height)
    'Graphicsオブジェクト作成
    Dim gr As Graphics = Graphics.FromImage(picCAnvas.Image)
    'Penオブジェクト作成
    Dim MyPen As New Pen(Color.Red, 8)
    gr.DrawLine(MyPen, 10, 10, 250, 10)  '赤色、太さ8pix

    picCAnvas.Refresh()    'picCanvasの更新
    gr.Dispose()        'オブジェクト解放
    MyPen.Dispose()   'オブジェクト解放
  End Sub
End Class

テスト

□ いろいろな種類の直線が描画される。


 back next 
/// 実習H3 グラフィックス(1) Copyright©2014 Hiroshi Masuda 

 

 

 

inserted by FC2 system