DOBON.NET DOBON.NETプログラミング掲示板過去ログ

フォームのデザインでレイヤー

環境/言語:[2000/vb]
分類:[.NET]

フォームデザインでフォーム上に配置したピクチャーボックスやパネルはレイヤー的に階層を決めれるのでしょうか?

例えば一番上に配置したピクチャーボックスをtransparent にしてそこに描画をしながらその下に配置されたピクチャーボックス画像を見る事は可能かという質問です。

線の描画プログラムで 以下のコードを書いたのですが マウスが動いている時にそのマウスの軌跡を追うようにリフレッシュをかけているのですが、リフレッシュをかけるとマウスが動いている時に既に書かれた線が一時的に消えてしまいます。だったらピクチャーボックスの2層もしくはピクチャーボックスとパネルを重ねた上で描画を行えばいいかな〜と思って書き出したのですが、レイヤー構造に出来ない為にうまく行きません。レイヤーでなくてもいいのですがなんか解決策がありましたら教えてください。

'マウスダウン時の点
Dim StartP() As Point
'マウスアップ時の点
Dim EndP() As Point
Dim CountA As Long = -1
Dim CountB As Long
Dim StLine As Boolean = False
Dim gp As New Pen(Color.Green, 1)
Dim p As New Pen(Color.Black, 1)

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Dim TempP As Point
'直線の描画
If StLine = True Then
If e.Button = MouseButtons.Left Then
CountA = CountA + 1

ReDim Preserve StartP(CountA)
StartP(CountA) = New Point(e.X, e.Y)
ListBox1.Items.Add("StartS")
ListBox1.Items.Add(StartP(CountA))
End If
End If
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Label1.Text = e.X
Label2.Text = e.Y
Dim TempP As Point()
Dim G2 As Graphics = PictureBox1.CreateGraphics
Dim i As Integer
Dim A As Point, B As Point
If e.Button = MouseButtons.Left Then
ReDim Preserve TempP(CountA)
TempP(CountA) = New Point(e.X, e.Y)
PictureBox1.Refresh()
A = StartP(CountA)
B = TempP(CountA)
End If
G2.DrawLine(gp, A, B)
End Sub

Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
Dim TempP As Point
Dim i As Long
Dim G3 As Graphics = PictureBox1.CreateGraphics
'直線の描画
If StLine = True Then
If e.Button = MouseButtons.Left Then
ReDim Preserve EndP(CountA)
EndP(CountA) = New Point(e.X, e.Y)
ListBox1.Items.Add("EndS")
ListBox1.Items.Add(EndP(CountA))
End If
End If

For i = 0 To CountA
G3.DrawLine(p, StartP(i), EndP(i))
Next
End Sub
End Class
書き忘れましたが これは後で端点接続のラインのコードを書くためにマウスがUPされた時の点を入れています。端点接続をしなければ最後の点はいらないですから
色々試してみてなんかできちゃったので 一応自作自演ぽいですけど参考に載せておきます。ちなみにレイヤーは使わなくていけました。
'マウスダウン時の点
Dim StartP() As Point
'マウスアップ時の点
Dim EndP() As Point
'マウスの軌跡を追う為に点を格納する
Dim A As Point, B As Point, C As Point
'端点を探す為にマウスのクリック位置とデータに入っている点を探す為の値
Protected FINDIT As Long = 20
'点の配列用カウンター
Dim CountA As Long = -1
'ラジオ用のブール
Dim StLine As Boolean = True
Dim SP As Boolean = False

Dim rp As New Pen(Color.Red, 1)
Dim p As New Pen(Color.Black, 1)
Dim wp As New Pen(Color.White, 1)



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
'端点を探すファンクション 
'GET ホイント型
'RETURN ポイント型
Function FindPoint(ByVal TP As Point) As Point
Dim Xrange
Dim Yrange
Dim CountB As Long

For CountB = 0 To CountA
For Xrange = 0 To FINDIT
If StartP(CountB).X = TP.X - Xrange Or StartP(CountB).X = TP.X + Xrange Then
For Yrange = 0 To FINDIT
If StartP(CountB).Y = TP.Y - Yrange Or StartP(CountB).Y = TP.Y + Yrange Then
FindPoint = StartP(CountB)
Exit Function
End If
Next
End If
Next

For Xrange = 0 To FINDIT
If EndP(CountB).X = TP.X - Xrange Or EndP(CountB).X = TP.X + Xrange Then
For Yrange = 0 To FINDIT
If EndP(CountB).Y = TP.Y - Yrange Or EndP(CountB).Y = TP.Y + Yrange Then
FindPoint = EndP(CountB)
Exit Function
End If
Next
End If
Next
Next
FindPoint = New Point(-1, -1)
End Function

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Dim TempP1 As Point
'直線の描画
If StLine = True Then
If e.Button = MouseButtons.Left Then
CountA = CountA + 1
ReDim Preserve StartP(CountA)
StartP(CountA) = New Point(e.X, e.Y)
ListBox1.Items.Add("StartS")
ListBox1.Items.Add(StartP(CountA))
End If
End If

'端点用
If SP = True Then
If e.Button = MouseButtons.Left Then
TempP1 = New Point(e.X, e.Y)
'マウスでクリックされた点を補正して端点に設定
TempP1 = FindPoint(TempP1)
If TempP1.X > -1 Then
If TempP1.Y > -1 Then
ReDim Preserve StartP(CountA)
StartP(CountA) = TempP1
ListBox1.Items.Add("StartT")
ListBox1.Items.Add(StartP(CountA))
End If
End If
End If
Else
SP = False
End If
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Dim G2 As Graphics = PictureBox1.CreateGraphics
Dim CountC As Long = 0
Dim TempP2 As Point()

Label1.Text = e.X
Label2.Text = e.Y
If e.Button = MouseButtons.Left Then
ReDim Preserve TempP2(CountC)
TempP2(CountC) = New Point(e.X, e.Y)
A = StartP(CountA)
B = TempP2(CountC)
CountC = CountC + 1
G2.DrawLine(wp, A, C)
G2.DrawLine(rp, A, B)
C = B
End If

End Sub

Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
Dim TempP3 As Point
Dim i As Long
Dim G3 As Graphics = PictureBox1.CreateGraphics

Me.Refresh()
'直線の描画
If StLine = True Then
If e.Button = MouseButtons.Left Then
ReDim Preserve EndP(CountA)
EndP(CountA) = New Point(e.X, e.Y)
ListBox1.Items.Add("EndS")
ListBox1.Items.Add(EndP(CountA))
End If
End If
'端点用
If SP = True Then
If e.Button = MouseButtons.Left Then
TempP3 = New Point(e.X, e.Y)
'マウスでクリックされた点を補正して端点に設定()
TempP3 = FindPoint(TempP3)
If TempP3.X > -1 Then
If TempP3.Y > -1 Then
ReDim Preserve EndP(CountA)
EndP(CountA) = TempP3
ListBox1.Items.Add("EndT")
ListBox1.Items.Add(EndP(CountA))
End If
End If
End If
End If

For i = 0 To CountA
G3.DrawLine(p, StartP(i), EndP(i))
Next
End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
StLine = True
ElseIf RadioButton2.Checked = True Then
SP = True
End If
End Sub
解決クリックを忘れてました
■No3017に返信(ぱーやんさんの記事)
> 色々試してみてなんかできちゃったので 一応自作自演ぽいですけど参考に載せておきます。ちなみにレイヤーは使わなくていけました。
> 'マウスダウン時の点
> Dim StartP() As Point
> 'マウスアップ時の点
> Dim EndP() As Point
> 'マウスの軌跡を追う為に点を格納する
> Dim A As Point, B As Point, C As Point
> '端点を探す為にマウスのクリック位置とデータに入っている点を探す為の値
> Protected FINDIT As Long = 20
> '点の配列用カウンター
> Dim CountA As Long = -1
> 'ラジオ用のブール
> Dim StLine As Boolean = True
> Dim SP As Boolean = False
>
> Dim rp As New Pen(Color.Red, 1)
> Dim p As New Pen(Color.Black, 1)
> Dim wp As New Pen(Color.White, 1)
>
>
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
>
> End Sub
> '端点を探すファンクション 
> 'GET ホイント型
> 'RETURN ポイント型
> Function FindPoint(ByVal TP As Point) As Point
> Dim Xrange
> Dim Yrange
> Dim CountB As Long
>
> For CountB = 0 To CountA
> For Xrange = 0 To FINDIT
> If StartP(CountB).X = TP.X - Xrange Or StartP(CountB).X = TP.X + Xrange Then
> For Yrange = 0 To FINDIT
> If StartP(CountB).Y = TP.Y - Yrange Or StartP(CountB).Y = TP.Y + Yrange Then
> FindPoint = StartP(CountB)
> Exit Function
> End If
> Next
> End If
> Next
>
> For Xrange = 0 To FINDIT
> If EndP(CountB).X = TP.X - Xrange Or EndP(CountB).X = TP.X + Xrange Then
> For Yrange = 0 To FINDIT
> If EndP(CountB).Y = TP.Y - Yrange Or EndP(CountB).Y = TP.Y + Yrange Then
> FindPoint = EndP(CountB)
> Exit Function
> End If
> Next
> End If
> Next
> Next
> FindPoint = New Point(-1, -1)
> End Function
>
> Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
> Dim TempP1 As Point
> '直線の描画
> If StLine = True Then
> If e.Button = MouseButtons.Left Then
> CountA = CountA + 1
> ReDim Preserve StartP(CountA)
> StartP(CountA) = New Point(e.X, e.Y)
> ListBox1.Items.Add("StartS")
> ListBox1.Items.Add(StartP(CountA))
> End If
> End If
>
> '端点用
> If SP = True Then
> If e.Button = MouseButtons.Left Then
> TempP1 = New Point(e.X, e.Y)
> 'マウスでクリックされた点を補正して端点に設定
> TempP1 = FindPoint(TempP1)
> If TempP1.X > -1 Then
> If TempP1.Y > -1 Then
> ReDim Preserve StartP(CountA)
> StartP(CountA) = TempP1
> ListBox1.Items.Add("StartT")
> ListBox1.Items.Add(StartP(CountA))
> End If
> End If
> End If
> Else
> SP = False
> End If
> End Sub
>
> Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
> Dim G2 As Graphics = PictureBox1.CreateGraphics
> Dim CountC As Long = 0
> Dim TempP2 As Point()
>
> Label1.Text = e.X
> Label2.Text = e.Y
> If e.Button = MouseButtons.Left Then
> ReDim Preserve TempP2(CountC)
> TempP2(CountC) = New Point(e.X, e.Y)
> A = StartP(CountA)
> B = TempP2(CountC)
> CountC = CountC + 1
> G2.DrawLine(wp, A, C)
> G2.DrawLine(rp, A, B)
> C = B
> End If
>
> End Sub
>
> Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
> Dim TempP3 As Point
> Dim i As Long
> Dim G3 As Graphics = PictureBox1.CreateGraphics
>
> Me.Refresh()
> '直線の描画
> If StLine = True Then
> If e.Button = MouseButtons.Left Then
> ReDim Preserve EndP(CountA)
> EndP(CountA) = New Point(e.X, e.Y)
> ListBox1.Items.Add("EndS")
> ListBox1.Items.Add(EndP(CountA))
> End If
> End If
> '端点用
> If SP = True Then
> If e.Button = MouseButtons.Left Then
> TempP3 = New Point(e.X, e.Y)
> 'マウスでクリックされた点を補正して端点に設定()
> TempP3 = FindPoint(TempP3)
> If TempP3.X > -1 Then
> If TempP3.Y > -1 Then
> ReDim Preserve EndP(CountA)
> EndP(CountA) = TempP3
> ListBox1.Items.Add("EndT")
> ListBox1.Items.Add(EndP(CountA))
> End If
> End If
> End If
> End If
>
> For i = 0 To CountA
> G3.DrawLine(p, StartP(i), EndP(i))
> Next
> End Sub
>
> Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
> If RadioButton1.Checked = True Then
> StLine = True
> ElseIf RadioButton2.Checked = True Then
> SP = True
> End If
> End Sub
>
解決済み!

DOBON.NET | プログラミング道 | プログラミング掲示板