|
'flowlayoutpanelの中にラベルを入れる場合、flowlayoutpanelのx,yを加える!! rect1 = New Rectangle(Label1.Left + 44, Label1.Top + 12, Label1.Width, Label1.Height) rect2 = New Rectangle(Label2.Left + 44, Label2.Top + 12, Label2.Width, Label2.Height) rect3 = New Rectangle(Label3.Left + 44, Label3.Top + 12, Label3.Width, Label3.Height) Label_p4 = New Point(Label4.Left, Label4.Top) '初期位置を保管 Label_p5 = New Point(Label5.Left, Label5.Top) '初期位置を保管 Label_p6 = New Point(Label6.Left, Label6.Top) '初期位置を保管 Label_p7 = New Point(Label7.Left, Label7.Top) '初期位置を保管 Label_p8 = New Point(Label8.Left, Label8.Top) '初期位置を保管 Label_p9 = New Point(Label9.Left, Label9.Top) '初期位置を保管 Me.Controls.Add(Label4) AddHandler Label4.MouseDown, AddressOf Label4_MouseDown AddHandler Label4.MouseMove, AddressOf Label4_MouseMove AddHandler Label4.MouseUp, AddressOf Label4_MouseUp Me.Controls.Add(Label5) AddHandler Label5.MouseDown, AddressOf label5_MouseDown AddHandler Label5.MouseMove, AddressOf label5_MouseMove AddHandler Label5.MouseUp, AddressOf label5_MouseUp Me.Controls.Add(Label6) AddHandler Label6.MouseDown, AddressOf label6_MouseDown AddHandler Label6.MouseMove, AddressOf label6_MouseMove AddHandler Label6.MouseUp, AddressOf label6_MouseUp Me.Controls.Add(Label7) AddHandler Label7.MouseDown, AddressOf label7_MouseDown AddHandler Label7.MouseMove, AddressOf label7_MouseMove AddHandler Label7.MouseUp, AddressOf label7_MouseUp Me.Controls.Add(Label8) AddHandler Label8.MouseDown, AddressOf label8_MouseDown AddHandler Label8.MouseMove, AddressOf label8_MouseMove AddHandler Label8.MouseUp, AddressOf label8_MouseUp Me.Controls.Add(Label9) AddHandler Label9.MouseDown, AddressOf label9_MouseDown AddHandler Label9.MouseMove, AddressOf label9_MouseMove AddHandler Label9.MouseUp, AddressOf label9_MouseUp Button1.Enabled = False
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If Not (rect1.Contains(New Point(Label4.Left, Label4.Top)) Or rect1.Contains(New Point(Label5.Left, Label5.Top)) _ Or rect1.Contains(New Point(Label6.Left, Label6.Top)) Or rect1.Contains(New Point(Label7.Left, Label7.Top))) Then b0 = 1 Label1.BackColor = Color.Yellow Else b0 = 0 End If If Not (rect2.Contains(New Point(Label4.Left, Label4.Top)) Or rect2.Contains(New Point(Label5.Left, Label5.Top)) _ Or rect2.Contains(New Point(Label6.Left, Label6.Top)) Or rect2.Contains(New Point(Label7.Left, Label7.Top))) Then b1 = 1 Label2.BackColor = Color.Yellow Else b1 = 0 End If If Not (rect3.Contains(New Point(Label4.Left, Label4.Top)) Or rect3.Contains(New Point(Label5.Left, Label5.Top)) _ Or rect3.Contains(New Point(Label6.Left, Label6.Top)) Or rect3.Contains(New Point(Label7.Left, Label7.Top))) Then b2 = 1 Label3.BackColor = Color.Yellow Else b2 = 0 End If b = b0 + b1 + b2 If b > 0 Then MsgBox("全てに解答しましょう。") ElseIf b = 0 Then
"ここをどう書けばいいのでしょうか・・・・・・"
End If Button1.Enabled = True End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Me.Close() End Sub
Private Sub Label4_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = MouseButtons.Left Then '左クリック mp = Me.PointToClient(Cursor.Position) 'マウスを押した位置の座標を取得 sender_Label4 = DirectCast(sender, Label) '移動させるlabel sender_Label4.BringToFront() '最前面へ移動 sender_Label4.BackColor = Color.Pink sender_Label4.Cursor = Cursors.Hand 'ポインターを変更したければ End If End Sub
Public Sub Label4_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = MouseButtons.Left Then '左クリック Dim new_mp As Point = Me.PointToClient(Cursor.Position) 'マウスの最新座標 If rect1.Contains(New Point(new_mp.X, new_mp.Y)) Then 'マウスが目的のLabelの領域内に入ったら吸着させる sender_Label4.Location = New Point(rect1.X, rect1.Y) ElseIf rect2.Contains(New Point(new_mp.X, new_mp.Y)) Then 'マウスが目的のLabelの領域内に入ったら吸着させる sender_Label4.Location = New Point(rect2.X, rect2.Y) ElseIf rect3.Contains(New Point(new_mp.X, new_mp.Y)) Then 'マウスが目的のLabelの領域内に入ったら吸着させる sender_Label4.Location = New Point(rect3.X, rect3.Y) Else 'マウスが目的のLabelの領域外であれば自由に移動 sender_Label4.Left += (new_mp.X - mp.X) sender_Label4.Top += (new_mp.Y - mp.Y) End If mp = new_mp 'マウス座標を更新 End If End Sub
Private Sub Label4_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = MouseButtons.Left Then '左クリック
'マウスが目的の領域外の時は移動中のLabelを元の位置に戻す If Not (rect1.Contains(New Point(mp.X, mp.Y)) Or rect2.Contains(New Point(mp.X, mp.Y)) Or rect3.Contains(New Point(mp.X, mp.Y))) Then sender_Label4.Location = New Point(Label_p4.X, Label_p4.Y) End If If Label4.Location = Label5.Location Or Label4.Location = Label6.Location Or Label4.Location = Label7.Location Or Label4.Location = Label8.Location Or Label4.Location = Label9.Location Then sender_Label4.Location = New Point(Label_p4.X, Label_p4.Y) End If
sender_Label4.BackColor = Color.PowderBlue sender_Label4.Cursor = Cursors.Default 'ポインターを変更したければ End If End Sub Private Sub label5_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = MouseButtons.Left Then '左クリック mp = Me.PointToClient(Cursor.Position) 'マウスを押した位置の座標を取得 sender_Label5 = DirectCast(sender, Label) '移動させるlabel sender_Label5.BringToFront() '最前面へ移動 sender_Label5.BackColor = Color.Pink sender_Label5.Cursor = Cursors.Hand 'ポインターを変更したければ End If End Sub
Public Sub label5_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = MouseButtons.Left Then '左クリック Dim new_mp As Point = Me.PointToClient(Cursor.Position) 'マウスの最新座標 If rect1.Contains(New Point(new_mp.X, new_mp.Y)) Then 'マウスが目的のLabelの領域内に入ったら吸着させる sender_Label5.Location = New Point(rect1.X, rect1.Y) ElseIf rect2.Contains(New Point(new_mp.X, new_mp.Y)) Then 'マウスが目的のLabelの領域内に入ったら吸着させる sender_Label5.Location = New Point(rect2.X, rect2.Y) ElseIf rect3.Contains(New Point(new_mp.X, new_mp.Y)) Then 'マウスが目的のLabelの領域内に入ったら吸着させる sender_Label5.Location = New Point(rect3.X, rect3.Y) Else 'マウスが目的のLabelの領域外であれば自由に移動 sender_Label5.Left += (new_mp.X - mp.X) sender_Label5.Top += (new_mp.Y - mp.Y) End If mp = new_mp 'マウス座標を更新 End If End Sub
Private Sub label5_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = MouseButtons.Left Then '左クリック
'マウスが目的の領域外の時は移動中のLabelを元の位置に戻す If Not (rect1.Contains(New Point(mp.X, mp.Y)) Or rect2.Contains(New Point(mp.X, mp.Y)) Or rect3.Contains(New Point(mp.X, mp.Y))) Then sender_Label5.Location = New Point(Label_p5.X, Label_p5.Y) End If If Label5.Location = Label4.Location Or Label5.Location = Label6.Location Or Label5.Location = Label7.Location Or Label5.Location = Label8.Location Or Label5.Location = Label9.Location Then sender_Label5.Location = New Point(Label_p5.X, Label_p5.Y) End If sender_Label5.BackColor = Color.PowderBlue sender_Label5.Cursor = Cursors.Default 'ポインターを変更したければ End If End Sub
|