Refresh canvas (defaultCanvas) in run-time.

Hello,
graphics drawn on canvas control move with time system, it means that TimeCtrl ChangeValue event : “Canvas.Refresh” is done.
unfortunately with Class Canvas this way does not work (defaultCanvas1), graph does not move with time change.

HI Djamel,

Usually Canvas.Invalidate is the correct call to try and refresh an image that is drawn on the canvas.

I am going to guess that your drawing code is in the Canvas.Paint event, and looks something like this:

Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint 'Draw the picture to the graphics layer If PBuffer <> Nil then g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height) End If 'Draw a rectangle around the canvas g.DrawRect(0,0,me.Width, me.Height) End Sub

This takes a picture called PBuffer and draws it to the canvas.

If you want to update the picture based on time, then redraw the new PBuffer picture from the new time, and then call the Canvas1.Invalidate to update the picture in the canvas to the user.

[code]//Make changes to date/time
//change variables to draw your new picture based on the time
//Once the new picture has been drawn for your new time then
//call Canvas1.invalidate to shown the new picture on the canvas:

Canvas1.invalidate
[/code]

I hope this helps :slight_smile:

Unfortunately it does not work (Buffer), unlike :

[code]Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
g.DrawRect(0,0,Canvas1.Width,vanvas1.Height)

End Sub[/code]

Instead of Buffer, all controls runs properly, date and time change, CheckBox , …, but graphic is not so better !

You may want to set a color g.ForeColor =

Does it really say vanvas in your code?

g.DrawRect(0,0,Canvas1.Width,canvas1.Height)

pBuffer is a picture property of the Window.
Initialise it when the window opens. Draw something on it , even if it is a line.

Any time you have new data, draw it on the pBuffer.graphics
And then invalidate Canvas1 with canvas1.invalidate

Canvas1 will paint at the next opportunity.
nb: Even if you have called invalidate 7 times, Canvas1 will paint itself once.

The code supplied was correct to make this work… I have added a few lines here

'Canvas1 Paint event Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint 'Draw the picture to the graphics layer If PBuffer <> Nil then g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height) End If 'Draw a rectangle around the canvas g.DrawRect(0,0,me.Width, me.Height) //possibly me.width -1, me.height -1 else pbuffer = new picture (canvas1.width,canvas1.height,32) pbuffer.graphics.drawrect 20,20,30,30 'do something me.invalidate ' paint again at next opportunity so you can see the rectangle End Sub

[code] 'Draw the picture to the graphics layer
If PBuffer <> Nil then
g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height)
//End If
'Draw a rectangle around the canvas
g.DrawRect(0,0,me.Width, me.Height)
//possibly me.width -1, me.height -1
else
pbuffer = new picture (CnvSkyMap.width,CnvSkyMap.height,32)
pbuffer.graphics.drawrect 0,0,700,700 'do something

end if
me.Invalidate[/code]

I tried with this wrote, but nothing change.

Would it not be something like:

'Draw the picture to the graphics layer
  If PBuffer = Nil then
    pbuffer = new picture (CnvSkyMap.width,CnvSkyMap.height,32)
    pbuffer.graphics.drawrect  0,0,700,700  'do something
  end if
  
g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height)

    'Draw a rectangle around the canvas
    g.DrawRect(0,0,me.Width, me.Height)
    //possibly me.width -1, me.height -1

I know this works, I use code like it all the time.
Where /when do you draw on PBuffer?

Can you decide what your canvas is called?

[quote]Unfortunately it does not work (Buffer), unlike :

Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
g.DrawRect(0,0,Canvas1.Width,vanvas1.Height)

End Sub[/quote]

[quote]
pbuffer = new picture (CnvSkyMap.width,CnvSkyMap.height,32)[/quote]

try this, and do not alter it, and make sure it is in the paint event of the actual canvas, whatever it happens to be called.

Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
  'Draw the picture to the graphics layer
  If PBuffer <> Nil then
    g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height)
  End If
  'Draw a rectangle around the canvas
  g.DrawRect(0,0,me.Width, me.Height)   
  //possibly me.width -1, me.height -1
else
//pbuffer is nil, so draw anything
g.forecolor = &cff0000
g.drawrect   10,10,20,90   


End Sub

if you get a red rectangle, pBuffer is nil, and you need to have initialised it and drawn on it.
If you get nothing, then pBuffer is blank (have you drawn on it yet?) or it is 1 x 1 pixel in size

I think that it will be better to see this simple example (windows with out buffer) attached to this msg.

link text

OK.
It draws a moon. The moon is different when you type numbers.
There is no timer, there is no animation, there is no TimeCtrl , but there is a moon.

What is the problem?

[quote=396554:@Jeff Tullin]OK.
It draws a moon. The moon is different when you type numbers.
There is no timer, there is no animation, there is no TimeCtrl , but there is a moon.

What is the problem?[/quote]
I gave a simple example with txtPhaseAngle textChange event , moon is just for test (change value).
This drawing is done with out buffer (see Paint event), adding buffer nothing done.
It seems that when i use buffer, the controls does not respond.

This attached example is wrote with Buffer property it seems running by calling DrawMoon in the PhaseAngle textchange event.
Is it a good way ?link text

Try clearing PBuffer before you commence drawing otherwise you will be drawing over the top of the previous content.

Init method is called to clear.

The init method seems to be getting called once to create the picture.

You need to clear the content every time you want to draw a new version PBuffer.Graphics.ClearRect(0, 0, PBuffer.Width, PBuffer.Height) otherwise you are just going to draw on top of what is already there.

Perfect, going properly !

Kevin,
Unlike to textchange, timeCtrl change does not respond.
an example is attached this msg.
link text

Now it take account of time control change, it seems Ok, any suggestion or remark ?
It will be helpful and welcome !
example attached in this msg "moonphase(TimeChange)_2.rar"link text