An event

myblueocean

Well-known member
Joined
Jun 29, 2007
Messages
161
Location
England
Programming Experience
Beginner
Hello.

Can someone please give me a clue as to how to go about doing this?

Lets say you have a blue long thin rectangle on a form, and a triangle, detail doesn't matter.

The triangle passes a certain point on the form whether another part of it or completely leaves the form, out of your sight altogether.

The blue rectangle I spoke of changes to a small square, because of the triangle passing a point, so some kind of event or action occurs?

I would like to try and piece these together, so some clues please.:rolleyes:
 
I've already shown you how to test whether a shape is within a certain bounds in a different thread. I've also shown you how to change the values of the variables controlling where something gets drawn. You're asking basically the same question over again.
 
No. How am I asking the same question that was all about a square moving around, and not going off the form?

I'm talking about a shape turning into another shape, because another piece of graphics hit something...I don't know quite as how to do that specifically, yes I can get some gfx to move around in whatever direction I want to go, but this isn't what I am asking?
 
I have already shown you how to change the values of variables that control what gets drawn. In my previous example I was changing location of the square that was being drawn. That is an EXAMPLE that you can extrapolate. If you can change the location of the square then why can you not just as easily change the size? Why can you not just as easily change the shape?

A triangle would simply be the result of calling DrawLines and passing four points where the first and last are the same.
 
I am completely confused about all this stuff, being honest here.

I don't quite have the mind for programming, I did do a little while at college but found it quite boring. It wasn't what I was focused on doing, which is what I've been asking so far...

Um, I have no idea how to get a shape to change into another shape simutaneously...because of an event, which would be that triangle passing at a point.

It's like I kind of understand the animation code a little, but not in the way you think I should be able to easily progress, sounds funny but I kind of need examples or pieces of code as a clue or the whole lot even...:eek:
 
I've already provided an example in this thread, as I keep telling you. In that code I've shown you how to detect when your shape goes outside the bounds of the form. You can quite easily adapt that to some other area rather than the full area of the form. I've also shown you how to store the data that determines what gets drawn in member variables, then edit the values of those variables and force a repaint to change the drawing. You can quite easily adapt that to change the size of the drawing as well as, or instead of, the location.
 
VB.NET:
'Change the direction of movement if a boundary has been reached.
        If Me.xincrement = 1 AndAlso Me.rect.Right >= Me.ClientSize.Width - 1 Then
            Me.xincrement = 0
            Me.yincrement = 1
        ElseIf Me.yincrement = 1 AndAlso Me.rect.Bottom >= Me.ClientSize.Height - 1 Then
            Me.xincrement = -1
            Me.yincrement = 0
        End If

This is what I should be looking at?

VB.NET:
 'Mark the old rectangle to be erased.
        Me.Invalidate(Rectangle.Inflate(Me.rect, 1, 1))

        'Shift the rectangle.
        Me.rect.Offset(Me.xincrement, Me.yincrement)

        'Mark the new rectangle to be drawn.
        Me.Invalidate(Rectangle.Inflate(Me.rect, 1, 1))

        'Do the drawing.
        Me.Update()

I have to use some of these pieces of code, with differences of course.

"I've also shown you how to store the data that determines what gets drawn in member variables"

"then edit the values of those variables and force a repaint to change the drawing."

Could you expand please on that?:eek:
 
In the code I provided I used a member variable to store the data that controls what gets drawn:
VB.NET:
Private [B][U]rect[/U][/B] As New Rectangle(0, 0, 25, 25)
Every time the form gets repainted the Paint event is raised, that data is read and the corresponding drawing performed:
VB.NET:
Private Sub Form1_Paint(ByVal sender As Object, _
                        ByVal e As PaintEventArgs) Handles Me.Paint
    'Draw the rectangle.
    e.Graphics.DrawRectangle(Pens.Black, [B][U]Me.rect[/U][/B])
End Sub
If ever the drawing needs to be changed you simply change the value stored in the member variable and force the form to repaint:
VB.NET:
Private Sub Timer1_Tick(ByVal sender As Object, _
                        ByVal e As EventArgs) Handles Timer1.Tick
    'Mark the old rectangle to be erased.
    Me.Invalidate(Rectangle.Inflate(Me.rect, 1, 1))

    [B]'Shift the rectangle.[/B]
    [B]Me.rect.Offset(Me.xIncrement, Me.yIncrement)[/B]

    'Mark the new rectangle to be drawn.
    Me.Invalidate(Rectangle.Inflate(Me.rect, 1, 1))

    [B]'Do the drawing.[/B]
    [B]Me.Update()[/B]

    'Change the direction of movement if a boundary has been reached.
    If Me.xIncrement = 1 AndAlso Me.rect.Right >= Me.ClientSize.Width - 1 Then
        Me.xIncrement = 0
        Me.yIncrement = 1
    ElseIf Me.yIncrement = 1 AndAlso Me.rect.Bottom >= Me.ClientSize.Height - 1 Then
        Me.xIncrement = -1
        Me.yIncrement = 0
    ElseIf Me.xIncrement = -1 AndAlso Me.rect.Left <= 0 Then
        Me.xIncrement = 0
        Me.yIncrement = -1
    ElseIf Me.yIncrement = -1 AndAlso Me.rect.Top <= 0 Then
        Me.xIncrement = 1
        Me.yIncrement = 0
    End If
End Sub
All those If statements are what makes sure that the drawing stays within the boundary of the form, which I have clearly stated in the code and you would have seen if/when you ran that code. If you want to use a boundary other than the bounds of the form then you simply have to change the numbers you test against.

The code I provided moves the rectangle by calling its Offset method. You could just as easily have set its Location property. If you want to change its size rather than its location then you can just as easily call its Inflate method or set its Size property.

If you want to draw a different shape then you wouldn't use a member variable of type Rectangle. If you wanted to draw a triangle, for instance, then you'd store three Points instead, then call DrawLines instead of DrawRectangle.
 
Right...Alright then, um what if you want to a piece of graphics to move out of another piece of graphics? via button, like one or two pixel sized graphic, oh and by the way pixels or small squares you would call them data?
 
You already have all the principles you need. You know how to move a drawing: change the values in the member variables that describe that drawing and then force the form to repaint. If you want this to happen when someone clicks a Button then you put the code inside that Button's Click event handler. It's now time for you to apply those principles.
 
So I know enough to be able to produce a triangle and then pixels fire out of it? What about if I want that small pixel to hit an object, like a rectangle, now what has changed?
 
Another thing what about how to create a kind of magnet that draws a piece of graphics into it, and disappeares?

This magnet could just be a few lines, and also how about an explosion, it doesn't have to be like some kind of image repetition animation thingi?
 
Last edited:
Could a procedure or piece of code that is running and you're interacting with that code, which is that piece of graphics.

Can that then turn into an animation? With out pressing anything, just some sort of timer?
 
From the looks of things, creating a triangle isn't a possibility, like easily a rectangle.

I have made a triangle using the "Draw line"? I did try and declare it and try to some how get it to move. But then I couldn't since it isn't listed in the library.
 
Back
Top