×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to change cursor to specific highlighted area (points and coordinates) of a picture box?

How to change cursor to specific highlighted area (points and coordinates) of a picture box?

How to change cursor to specific highlighted area (points and coordinates) of a picture box?

(OP)
Hello, is it possible to change the cursor to hand in a highlighted area of a picture box as a triangle or rectagle for example? How can I achieve that? May anyone guide me please?
I was thinking to create a class for Triangle for example but I don't know if I am thinking right, because I have to do with points and coordinates of points. What I need to do that?
I would like an example, or further explanation and suggestions about this. Any help will be much appreciated. Thank you so much in advanced.

Public Function HighlightTriangle(ByVal ResultDice As Byte, _
ByRef GrpSmpleDice As GroupSmpleDice, ByRef GrpDblDice As GroupDblDice, ByVal DblDice As Boolean) As RectangleOfTriangle
Dim graphics As System.Drawing.Graphics = BrdPB.CreateGraphics()

Dim g As System.Drawing.Graphics = BrdPB.CreateGraphics()
Dim brsh As SolidBrush
Dim Highlighted As Boolean = False

Dim Rect As New RectangleOfTriangle

Dim points(CType(Trigwna(0), ArrayList).Count - 1) As Point
For i As Integer = 0 To CType(Trigwna(ResultDice), ArrayList).Count - 1
points(i) = CType(CType(Trigwna(ResultDice), ArrayList)(i), Point)
Next

If DblDice = False Then
If GrpSmpleDice.FrstDice And ResultDice = Me.Rd1 - 1 Then
RectInst1 = BrdPB.SquareTriangles(ResultDice)
Rect = RectInst1
USDices.Hlght1 = True
End If

If GrpSmpleDice.ScndDice And ResultDice = Me.Rd2 - 1 Then
RectInst2 = BrdPB.SquareTriangles(ResultDice)
Rect = RectInst2
USDices.Hlght2 = True
End If
Else
With GrpDblDice
If ResultDice = Me.Rd1 - 1 And .FrstDice Then
RectInst1 = BrdPB.SquareTriangles(ResultDice)
Me.RectI1 = RectInst1
End If

If ResultDice = Me.Rd2 - 1 And .ScndDice Then
RectInst2 = BrdPB.SquareTriangles(ResultDice)
Me.RectI2 = RectInst2
End If


If ResultDice = Me.rd3 - 1 And .ThrdDice Then
RectInst3 = BrdPB.SquareTriangles(ResultDice)
Me.RectI3 = RectInst3
End If


If ResultDice = Me.rd4 - 1 And .FrthDice Then
RectInst4 = BrdPB.SquareTriangles(ResultDice)
Me.RectI4 = RectInst4
End If

Rect = BrdPB.SquareTriangles(ResultDice)

End With

End If

g = BrdPB.CreateGraphics()
brsh = New SolidBrush(Color.FromArgb(130, 255, 255, 0))
g.FillPolygon(brsh, points)
brsh.Dispose()
g.Dispose()
Return Rect
End Function

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

As a member of TT for about 5 years, could you please start formatting your code with TGML tags ponder

You can start with Editing your post above.


---- Andy

There is a great need for a sarcasm font.

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

(OP)
What is TGML tags exactly?

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

Above the box where you type your post or reply, you have these little icons (B, I, U, etc. for Bold, Italic, Underline, etc.) If you investigate the rest of them, you will find Code icon. This allows you to format you code to look like this:

CODE

If GrpSmpleDice.ScndDice And ResultDice = Me.Rd2 - 1 Then
    RectInst2 = BrdPB.SquareTriangles(ResultDice)
    Rect = RectInst2
    USDices.Hlght2 = True
End If 

Don't you agree that this (above) is easier to read...?


---- Andy

There is a great need for a sarcasm font.

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

(OP)

CODE -->

Public Function HighlightTriangle(ByVal ResultDice As Byte, _
ByRef GrpSmpleDice As GroupSmpleDice, ByRef GrpDblDice As GroupDblDice, ByVal DblDice As Boolean) As RectangleOfTriangle
Dim graphics As System.Drawing.Graphics = BrdPB.CreateGraphics()

  Dim g As System.Drawing.Graphics = BrdPB.CreateGraphics()
  Dim brsh As SolidBrush
  Dim Highlighted As Boolean = False

  Dim Rect As New RectangleOfTriangle

  Dim points(CType(Trigwna(0), ArrayList).Count - 1) As Point
  For i As Integer = 0 To CType(Trigwna(ResultDice), ArrayList).Count - 1
    points(i) = CType(CType(Trigwna(ResultDice), ArrayList)(i), Point)
  Next

  If DblDice = False Then
     If GrpSmpleDice.FrstDice And ResultDice = Me.Rd1 - 1 Then
         RectInst1 = BrdPB.SquareTriangles(ResultDice)
         Rect = RectInst1
         USDices.Hlght1 = True
     End If

     If GrpSmpleDice.ScndDice And ResultDice = Me.Rd2 - 1 Then
        RectInst2 = BrdPB.SquareTriangles(ResultDice)
        Rect = RectInst2
        USDices.Hlght2 = True
     End If
  Else
    With GrpDblDice
      If ResultDice = Me.Rd1 - 1 And .FrstDice Then
        RectInst1 = BrdPB.SquareTriangles(ResultDice)
        Me.RectI1 = RectInst1
      End If

      If ResultDice = Me.Rd2 - 1 And .ScndDice Then
        RectInst2 = BrdPB.SquareTriangles(ResultDice)
        Me.RectI2 = RectInst2
      End If

      If ResultDice = Me.rd3 - 1 And .ThrdDice Then
        RectInst3 = BrdPB.SquareTriangles(ResultDice)
        Me.RectI3 = RectInst3
      End If

      If ResultDice = Me.rd4 - 1 And .FrthDice Then
        RectInst4 = BrdPB.SquareTriangles(ResultDice)
        Me.RectI4 = RectInst4
      End If

      Rect = BrdPB.SquareTriangles(ResultDice)
    End With

  End If

  g = BrdPB.CreateGraphics()
  brsh = New SolidBrush(Color.FromArgb(130, 255, 255, 0))
  g.FillPolygon(brsh, points)
  brsh.Dispose()
  g.Dispose()
  Return Rect
End Function 
I don't have the possibility to do it at the initial post, but I hope that I did it now, I didn't know it. Thank you.

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

Here's a simple solution that will hopefully get you going in the right direction.

First, double-click the picture box, then select the MouseMove event. Put this for the MouseMove event handler:

CODE

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

        Dim pt As Point
        Dim gp As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath

        'get the mouse's current position in the picture box
        pt = New Point(e.X, e.Y)

        Dim tri() As Point

        'points for a triangle
        tri = New Point() { _
            New Point(PictureBox1.Width / 2, 1), New Point(PictureBox1.Width - 1, PictureBox1.Height - 1), _
            New Point(1, PictureBox1.Height - 1)}

        'creates an invisible polygon with the position and dimensions of tri()
        gp.AddPolygon(tri)

        'test if mouse's current position is inside tri.  If yes, change cursor to hand.  Default cursor if not.
        If gp.IsVisible(pt) Then
            PictureBox1.Cursor = Cursors.Hand
        Else
            PictureBox1.Cursor = Cursors.Default
        End If)
        
    End Sub 

Finally, for the picture box's Paint event handler, do this:

CODE

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

        Dim tri() As Point

        'points for a triangle
        tri = New Point() { _
            New Point(PictureBox1.Width / 2, 1), New Point(PictureBox1.Width - 1, PictureBox1.Height - 1), _
            New Point(1, PictureBox1.Height - 1)}

        'draw the polygon in the picture box
        e.Graphics.DrawPolygon(Pens.Black, tri)

    End Sub 

The key here is using the System.Drawing.Drawing2D.GraphicsPath object. It contains the "IsVisible" method, which returns True or False if a point is inside the drawing or not, respectively. This is the best method for doing this, as it can apply to a drawing of any shape.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

(OP)
Than sounds really great but in my case I have to pass tri point as argument each time in PictureBox MouseMove event. I have to do this because my function HighlightTriangle, highlights specific triangles, with FillPolygon method, depending on different dices, every time the user rolls the dice. The problem in it, is that I don't know to how to pass it as argument in the mouseMove event, because if I do that, they don't have compatible signature. I tried on mouse move event the following

CODE -->

If Backgammon.RollDicesBtn.Visible And UsrTurn = False Then
            'NothingR1 = True
            'NothingR2 = True
            'NothingRO = True
            RectInst1 = New RectangleOfTriangle
            PrevRect2 = New RectangleOfTriangle
            UsrRectOut = New RectangleOfTriangle
            If ((e.X < RectInst1.pnt1.X And e.X > RectInst1.pnt2.X And e.Y > RectInst1.pnt3.Y) _
            Or (e.X > RectInst1.pnt1.X And e.X < RectInst1.pnt2.X And e.Y < RectInst1.pnt3.Y)) Or
            ((e.X < RectInst2.pnt1.X And e.X > RectInst2.pnt2.X And e.Y > RectInst2.pnt3.Y) _
            Or (e.X > RectInst2.pnt1.X And e.X < RectInst2.pnt2.X And e.Y < RectInst2.pnt3.Y)) Or
            ((e.X < UsrRectOut.pnt1.X And e.X > UsrRectOut.pnt2.X And e.Y > UsrRectOut.pnt3.Y) _
            Or (e.X > UsrRectOut.pnt1.X And e.X < UsrRectOut.pnt2.X And e.Y < UsrRectOut.pnt3.Y)) Then
                Cursor = Windows.Forms.Cursors.Default
                Exit Sub
            End If
        End If

        With RectInst1
            If .pnt1.X <> 0 And .pnt1.Y <> 0 And .pnt2.X <> 0 And .pnt2.Y <> 0 And .pnt3.X <> 0 And .pnt3.Y <> 0 And .pnt4.X <> 0 And .pnt4.Y <> 0 Then
                NothingR1 = False
            ElseIf .pnt1.X = 0 And .pnt1.Y = 0 And .pnt2.X = 0 And .pnt2.Y = 0 And .pnt3.X = 0 And .pnt3.Y = 0 And .pnt4.X = 0 And .pnt4.Y = 0 Then
                NothingR1 = True
            End If
        End With
        With RectInst2
            If .pnt1.X <> 0 And .pnt1.Y <> 0 And .pnt2.X <> 0 And .pnt2.Y <> 0 And .pnt3.X <> 0 And .pnt3.Y <> 0 And .pnt4.X <> 0 And .pnt4.Y <> 0 Then
                NothingR2 = False
            ElseIf .pnt1.X = 0 And .pnt1.Y = 0 And .pnt2.X = 0 And .pnt2.Y = 0 And .pnt3.X = 0 And .pnt3.Y = 0 And .pnt4.X = 0 And .pnt4.Y = 0 Then
                NothingR2 = True
            End If
        End With
        With UsrRectOut
            If .pnt1.X <> 0 And .pnt1.Y <> 0 And .pnt2.X <> 0 And .pnt2.Y <> 0 And .pnt3.X <> 0 And .pnt3.Y <> 0 And .pnt4.X <> 0 And .pnt4.Y <> 0 Then
                NothingRO = False
            ElseIf .pnt1.X = 0 And .pnt1.Y = 0 And .pnt2.X = 0 And .pnt2.Y = 0 And .pnt3.X = 0 And .pnt3.Y = 0 And .pnt4.X = 0 And .pnt4.Y = 0 Then
                NothingRO = True
            End If
        End With

        If NothingR1 = False Or NothingR2 = False Or NothingR4Dbl = False Or NothingRO = False Then

            If ((e.X < RectInst1.pnt1.X And e.X > RectInst1.pnt2.X And e.Y > RectInst1.pnt3.Y) _
            Or (e.X > RectInst1.pnt1.X And e.X < RectInst1.pnt2.X And e.Y < RectInst1.pnt3.Y)) Or
            ((e.X < RectInst2.pnt1.X And e.X > RectInst2.pnt2.X And e.Y > RectInst2.pnt3.Y) _
            Or (e.X > RectInst2.pnt1.X And e.X < RectInst2.pnt2.X And e.Y < RectInst2.pnt3.Y)) Or
            ((e.X < UsrRectOut.pnt1.X And e.X > UsrRectOut.pnt2.X And e.Y > UsrRectOut.pnt3.Y) _
            Or (e.X > UsrRectOut.pnt1.X And e.X < UsrRectOut.pnt2.X And e.Y < UsrRectOut.pnt3.Y)) Then
                Cursor = Windows.Forms.Cursors.Hand
            Else
                Cursor = Windows.Forms.Cursors.Default
            End If
        Else
            Cursor = Windows.Forms.Cursors.Default
        End If 
But at the interval the user clicks at submit playing up to the AutoRoll dice interval for computer player, when the mouse pointer shows to UsrRectOut area, similtuneously the PcTimerDie Run, the cursor is hand. And I come to this problem again, because in order to avoid it I created a class for Timer

CODE -->

Public Class CustomTimerDieTick
    Inherits System.Windows.Forms.Timer
    Private m_UsrTimer As Boolean
    Public Property IsUsrTimer() As Boolean
        Get
            Return m_UsrTimer
        End Get
        Set(ByVal value As Boolean)
            m_UsrTimer = value
        End Set
    End Property
    Private count1 As Integer
    Public Sub New()
        Me.IsUsrTimer = False
        Me.Interval = 17
        Me.Enabled = True
    End Sub
    Public Sub NewCustomTick(ByVal sender As Object, ByVal e2 As System.Windows.Forms.MouseEventArgs) Handles Me.Tick
        'MsgBox("I am enabled right now")
        If IsUsrTimer = False Then
            'Start the random number generator
            Randomize()
            'Assign a random number to a variable
           
            With Backgammon
                PcDice1 = CInt(Int((.numPics * Rnd()) + 1))
                PcDice2 = CInt(Int((.numPics * Rnd()) + 1))

                If .PcDice1PB.Visible = False Then .PcDice1PB.Visible = True
                If .PcDice2PB.Visible = False Then .PcDice2PB.Visible = True
                .PcDice1PB = FlexibleSelectCaseStatement(PcDice1, .PcDice1PB)
                .PcDice2PB = FlexibleSelectCaseStatement(PcDice2, .PcDice2PB)

                'Show the picture for the random number
                'Count 1 for every round
                count1 += 1
                Backgammon.PcDice1PB.Visible = True
                .PcDice2PB.Visible = True
                .UsrDice1PB.Visible = False
                .UsrDice2PB.Visible = False

                'If the count equals the number of rotations,
                '   then stop the wheel, and reset the count

                If count1 < 35 Then
                    .TmrDieRun = True
                    BrdPB.RectInst1 = New BackgammonBrdPB.RectangleOfTriangle
                    BrdPB.RectInst2 = New BackgammonBrdPB.RectangleOfTriangle
                    BrdPB.UsrRectOut = New BackgammonBrdPB.RectangleOfTriangle
                    If ((e2.X < BrdPB.RectInst1.pnt1.X And e2.X > BrdPB.RectInst1.pnt2.X And e2.Y > BrdPB.RectInst1.pnt3.Y) _
                    Or (e2.X > BrdPB.RectInst1.pnt1.X And e2.X < BrdPB.RectInst1.pnt2.X And e2.Y < BrdPB.RectInst1.pnt3.Y)) Or
                    ((e2.X < BrdPB.RectInst2.pnt1.X And e2.X > BrdPB.RectInst2.pnt2.X And e2.Y > BrdPB.RectInst2.pnt3.Y) _
                    Or (e2.X > BrdPB.RectInst2.pnt1.X And e2.X < BrdPB.RectInst2.pnt2.X And e2.Y < BrdPB.RectInst2.pnt3.Y)) Or
                    ((e2.X < BrdPB.UsrRectOut.pnt1.X And e2.X > BrdPB.UsrRectOut.pnt2.X And e2.Y > BrdPB.UsrRectOut.pnt3.Y) _
                    Or (e2.X > BrdPB.UsrRectOut.pnt1.X And e2.X < BrdPB.UsrRectOut.pnt2.X And e2.Y < BrdPB.UsrRectOut.pnt3.Y)) Then
                        .Cursor = Windows.Forms.Cursors.Default
                    End If

                Else
                    Me.Enabled = False
                    '.PcTmrDie.Enabled = False
                    .TmrDieRun = False
                    Me.Dispose()
                    '.PcTmrDie.Dispose()
                End If
                If .TmrDieRun = False And count1 = 35 Then
                    'Rotate the picture in the picture box.
                    'Move the picture box.
                    'MovePic()
                    count1 = 0

                    PcDice1Tmp = PcDice1 : PcDice2Tmp = PcDice2

                    .Dices(PcDice1, PcDice2)

                    .PcNumDices = New Num_Dices With {.Dice1 = PcDice1, .Dice2 = PcDice2}
                    
                    EntireDice.NumRd1 = PcDice1Tmp : EntireDice.NumRd2 = PcDice2Tmp

                    For i = 0 To UsrCheckerBtns.Length - 1
                        UsrCheckerBtns(i).Enabled = False
                    Next
                    .UsrDice1PB.Visible = False

                    TotalDice = PcDice1Tmp + PcDice2Tmp
                    BrdPB.FillValuesBrdTrianglePortes()
                    BrdPB.FillValues2RectOut()
                    Dim DblDice As Boolean = False

                    If PcDice1Tmp = PcDice2Tmp Then DblDice = True

                    'trexw prwta to pcPlayTmr kai meta to PcDelayTmr giati sto 
                    'runtime trexoun me antistrofh seira
                    .PcPlayTmr.Enabled = True
                    .PcDelayTmr.Enabled = True

                    BrdPB.RectInst1 = New BackgammonBrdPB.RectangleOfTriangle
                    BrdPB.RectInst2 = New BackgammonBrdPB.RectangleOfTriangle
                    BrdPB.UsrRectOut = New BackgammonBrdPB.RectangleOfTriangle

                    If ((e2.X < BrdPB.RectInst1.pnt1.X And e2.X > BrdPB.RectInst1.pnt2.X And e2.Y > BrdPB.RectInst1.pnt3.Y) _
                    Or (e2.X > BrdPB.RectInst1.pnt1.X And e2.X < BrdPB.RectInst1.pnt2.X And e2.Y < BrdPB.RectInst1.pnt3.Y)) Or
                    ((e2.X < BrdPB.RectInst2.pnt1.X And e2.X > BrdPB.RectInst2.pnt2.X And e2.Y > BrdPB.RectInst2.pnt3.Y) _
                    Or (e2.X > BrdPB.RectInst2.pnt1.X And e2.X < BrdPB.RectInst2.pnt2.X And e2.Y < BrdPB.RectInst2.pnt3.Y)) Or
                    ((e2.X < BrdPB.UsrRectOut.pnt1.X And e2.X > BrdPB.UsrRectOut.pnt2.X And e2.Y > BrdPB.UsrRectOut.pnt3.Y) _
                    Or (e2.X > BrdPB.UsrRectOut.pnt1.X And e2.X < BrdPB.UsrRectOut.pnt2.X And e2.Y < BrdPB.UsrRectOut.pnt3.Y)) Then
                        .Cursor = Windows.Forms.Cursors.Default
                    End If

                End If
            End With

        End If
    End Sub  
End Class 
And the problem is that NewCustomTick doesn't run as it run the the PcTmrDie_Tick event, with step over running it enters only one time

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

Ah, I get what you're trying to do now (I'm a backgammon player, btw). Try this:

Create a Global List of GraphicsPath objects:

Dim HighlightedTriangles As List (Of System.Drawing.Drawing2D.GraphicsPath)

Then when the player rolls the dice and the points (triangles) are highlighted, clear the HighlightedTriangles List (HighlightedTriangles.Clear()), then add a GraphicsPath object for each highlighted point. Then, in the MouseMove event, do this:

CODE

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

        Dim pt As Point 

        'get the mouse's current position in the picture box
        pt = New Point(e.X, e.Y)

        'loop through highlighted points (triangles)
        For Each gp As System.Drawing.Drawing2D.GraphicsPath In HighlightedTriangles
            'test if mouse's current position is inside the current triangle.  If yes, change cursor to hand.  Default cursor if not.
            If gp.IsVisible(pt) Then
                PictureBox1.Cursor = Cursors.Hand
                Exit For
            Else
                PictureBox1.Cursor = Cursors.Default
            End If
        Next
                
    End Sub 

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

(OP)
Thank you so much Jebenson. May you help me with the initialization of HighlightedTriangles?
The first piece of code is a routine I use to initialize all Triangle Points, here it is:

CODE -->

Public Sub FillValuesBrdTrianglePortes()
        ' Η συνάρτηση αυτή γεμίζει ένα πίνακα με τα σημεία κάθε τριγώνου της ταβλιέρας
        ' ξεκινώντας από το αντίθετο σημείο εκκίνησης του χρήστη δηλαδή 0 για κάτω δεξιά γωνία
        ' για τις πόρτες.

        Dim i, cnt, previous, x, y As Integer

        For i = 0 To Triangles.Length - 1
            cnt = i + 1
            Triangles(i) = New Triangle
            Rectangles(i) = New RectangleOfTriangle
            Triangles(i).indx = cnt
            If i > 0 Then previous = i - 1
            Select Case i
                Case 0
                    Triangles(i).pnt1 = New Point(650, 678)
                    Triangles(i).pnt2 = New Point(604, 678)
                    Triangles(i).pnt3 = New Point(627, 459)
                    'Case 23
                    'Triangles(i).pnt1 = New Point(604, 39)
                    'Triangles(i).pnt2 = New Point(650, 39)
                    'Triangles(i).pnt3 = New Point(627, 255)
                    'Triangles(i).Area_Width = 45
                    'Triangles(i).Area_Height = Triangles(i).pnt3.Y
                Case 6
                    Triangles(i).pnt1 = New Point(310, 678)
                    Triangles(i).pnt2 = New Point(265, 678)
                    Triangles(i).pnt3 = New Point(287, 459)

                Case 11
                    Triangles(i).pnt1 = New Point(76, 678)
                    Triangles(i).pnt2 = New Point(32, 678)
                    Triangles(i).pnt3 = New Point(54, 459)
                Case 12
                    Triangles(i).pnt1 = New Point(30, 37)
                    Triangles(i).pnt2 = New Point(77, 37)
                    Triangles(i).pnt3 = New Point(54, 255)
                Case 18
                    Triangles(i).pnt1 = New Point(370, 37) '9)
                    Triangles(i).pnt2 = New Point(416, 37)
                    Triangles(i).pnt3 = New Point(393, 255)
                Case 17
                    Triangles(i).pnt1 = New Point(265, 37)
                    Triangles(i).pnt2 = New Point(310, 37)
                    Triangles(i).pnt3 = New Point(287, 255)
                Case 0 To 11
                    x = Triangles(previous).pnt2.X - 1
                    y = Triangles(previous).pnt2.Y
                    Triangles(i).pnt1 = New Point(x, y)
                    x = Triangles(i).pnt1.X - 46
                    Triangles(i).pnt2 = New Point(x, y)
                    x = Triangles(previous).pnt3.X - 47
                    y = Triangles(previous).pnt3.Y
                    Triangles(i).pnt3 = New Point(x, y)
                Case 12 To 23 '22
                    x = Triangles(previous).pnt2.X + 2
                    y = Triangles(previous).pnt2.Y
                    Triangles(i).pnt1 = New Point(x, y)
                    Triangles(i).pnt2 = New Point(Triangles(i).pnt1.X + 45, y)
                    x = Triangles(previous).pnt3.X + 47
                    y = Triangles(previous).pnt3.Y
                    Triangles(i).pnt3 = New Point(x, y)
            End Select
            Select Case i
                Case 0 To 11
                    Rectangles(i).pnt3.Y = 379
                    Rectangles(i).pnt4.Y = 379
                    'Rectangles(i).pnt3.Y = 336
                    'Rectangles(i).pnt4.Y = 336
                Case 12 To 23
                    'Rectangles(i).pnt3.Y = 379
                    'Rectangles(i).pnt4.Y = 379
                    Rectangles(i).pnt3.Y = 336
                    Rectangles(i).pnt4.Y = 336
            End Select

            Rectangles(i).pnt1 = Triangles(i).pnt1
            Rectangles(i).pnt2 = Triangles(i).pnt2
            Rectangles(i).pnt3.X = Triangles(i).pnt2.X
            'Rectangles(i).pnt3.Y = Triangles(i).pnt3.Y
            Rectangles(i).pnt4.X = Triangles(i).pnt1.X
            'Rectangles(i).pnt4.Y = Triangles(i).pnt3.Y
        Next

        For i = 0 To Triangles.Length - 1
            TriangleKey = New ArrayList
            TriangleKey.Add(New Point(Triangles(i).pnt1))
            TriangleKey.Add(New Point(Triangles(i).pnt2))
            TriangleKey.Add(New Point(Triangles(i).pnt3))
            Trigwna.Add(TriangleKey)

            RctngleKey = New ArrayList
            RctngleKey.Add(New Point(Rectangles(i).pnt1))
            RctngleKey.Add(New Point(Rectangles(i).pnt2))
            RctngleKey.Add(New Point(Rectangles(i).pnt3))
            RctngleKey.Add(New Point(Rectangles(i).pnt4))
            Squares.Add(RctngleKey)
        Next

        For i = 0 To PstnsTriangles.Length - 1
            cnt = i + 1
            PstnsTriangles(i) = New PosRectangle With {.pos = cnt, .Rect = Rectangles(i), .Triangle = Triangles(i)}
            'PstnsTriangles(i) = New PosRectangle
            'PstnsTriangles(i).pos = cnt
            'PstnsTriangles(i).Rect = Rectangles(i)
            'PstnsTriangles(i).Triangle = Triangles(i)
        Next
    End Sub 

And what I tried to give values to HighlightedTriangles is the following: I am not familiar with graphics, where am I wrong? I would like to test your code. May you help me please?

CODE -->

Public Sub FillHighlightedTriangles()
    Dim myPointArray As Point()
    For i As Byte = 0 To Triangles.Length - 1
       myPointArray = {Triangles(i).pnt1, Triangles(i).pnt2, Triangles(i).pnt3}
       HighlightedTriangles(i) = New System.Drawing.Drawing2D.GraphicsPath 'error system null reference expression
       HighlightedTriangles(i).AddPolygon(myPointArray) 'the same error too, here
    Next
End Sub 

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

You need to initialize the HighlightedTriangles list. Also, I recommend creating a GraphicsPath object, adding the polygon, then adding the object to the list. Your definition for myPointArray is wrong, the parentheses go after the variable name to make it an array, and you also need to initialize it as New Point() before adding the values.

CODE

Public Sub FillHighlightedTriangles()
    Dim myPointArray() As Point

    Dim gp As System.Drawing.Drawing2D.GraphicsPath

    If HighlightedTriangles Is Nothing Then
        HighlightedTriangles = New List(Of System.Drawing.Drawing2D.GraphicsPath)
    Else
        HighlightedTriangles.Clear()
    EndIf

    For i As Byte = 0 To Triangles.Length - 1
       myPointArray = New Point() {Triangles(i).pnt1, Triangles(i).pnt2, Triangles(i).pnt3}
       gp = New System.Drawing.Drawing2D.GraphicsPath
       gp.addPolygon(myPointArray)
       HighlightedTriangles.Add(gp)
    Next
End Sub 

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

Also, I just noticed that your For loop is using byte. Shouldn't that be Integer?

For i As Integer = 0 To Triangles.Length - 1

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: How to change cursor to specific highlighted area (points and coordinates) of a picture box?

(OP)
Thank you so much jebenson, I hadn't understood the way very well. To answer your question, I use byte instead of integer at for statement, because triangles' count is stable, there are 24 triangles as all the positions the game board, so there is no reason to affect them, because i could never be a negative number and because of ram economy. Thank you so much, for all of your effort. Do you know any site, with tutorial at graphics? I am not very familiar with and I would like to learn better.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close