本ページは公開が終了した情報の複製であり、掲載時点での情報です。本ページに記載されている内容について各所に問い合わせることはご遠慮下さい。
サポート技術情報

[VB2] 複雑な図形の塗りつぶしをする方法

文書番号: 410503

最終更新日: 1999/03/23


この資料は以下の製品について記述したものです。


この記事は、以前は次の ID で公開されていました: JP410503

概要

Visual Basic for Windows 2.0 において、Circle や Line 単体での塗りつぶしは
できますが、三角形のような図形の内部を塗りつぶすことはできません。
この資料では Windows API の FloodFill を使用することで、このような図形の
塗りつぶしを実現させる方法について記述しています。

関連情報

Microsoft(R) Windows(TM) Software Development Kit Version 3.1 プログラマーズ リファレンス Vol.2 関数

サンプル

[GRAPHIC: ]
  VERSION 2.00
  Begin Form frmTriangle
     Caption         =   "Triangle"
     Height          =   2775
     Left            =   975
     LinkTopic       =   "Form1"
     ScaleHeight     =   2400
     ScaleWidth      =   1740
     Top             =   1230
     Width           =   1830
     Begin CommandButton cmdPaint
        Caption         =   "&Paint"
        Height          =   495
        Left            =   360
        TabIndex        =   0
        Top             =   1680
        Width           =   1095
     End
  End
  Option Explicit
  Declare Function FloodFill Lib "GDI" (ByVal hDC As Integer, ByVal x As Intege
  r, ByVal y As Integer, ByVal lColor As Long) As Integer
  Declare Function CreateSolidBrush Lib "GDI" (ByVal lColor As Long) As Integer
  Declare Function SelectObject Lib "GDI" (ByVal hDC As Integer, ByVal hObject
  As Integer) As Integer
  Declare Function DeleteObject Lib "GDI" (ByVal hObject As Integer) As Integer
  Sub cmdPaint_Click ()
      Dim n As Integer
      Dim nS As Integer
      nS = Me.ScaleMode
      Me.ScaleMode = 3
      Me.Line (10, 10)-(100, 100), 0
      Me.Line -(100, 10), 0
      Me.Line -(10, 10), 0
      n = Paint(CInt(Me.hDC), 50, 25, RGB(0, 192, 0), 0)
      Me.CurrentY = 100
      If n = 0 Then
          Print "error"
      End If
      Me.ScaleMode = nS
  End Sub
  ' Paint 関数
  '
  ' 機能  指定したエリアの塗りつぶしをおこないます。
  ' 構文  Paint(hDC, x, y, PaintCol, BorderCol)
  ' 解説  引数 hDC に塗りつぶしをおこなうコントロールのデバイス コンテキス
  '       トを、引数 x および y にピクセル単位の座標を、引数 PaintCol に塗
  '       りつぶす色を、引数 BorderCol に境界色を指定してください。
  '       正常終了の場合には 0 以外の値が返ります。
  '
  Function Paint (hDC As Integer, x As Integer, y As Integer, Paintcol As Long,
   Bordercol As Long) As Integer
      Dim hBrush As Integer
      Dim hBackBrush As Integer
      Dim n As Integer
      hBrush = CreateSolidBrush(Paintcol)
      hBackBrush = SelectObject(hDC, hBrush)
      Paint = FloodFill(hDC, x, y, Bordercol)
      n = DeleteObject(SelectObject(hDC, hBackBrush))
  End Function

詳細

Visual Basic 4.0、5.0、6.0 はヘルプ機能で、"hDC プロパティ" の使用例をご覧ください。

Keywords: KBHOWTO VB2 塗りつぶし KB410503
Technology: kbAudDeveloper kbVBSearch

inserted by FC2 system