Refresh canvas (defaultCanvas) in run-time.

  1. ‹ Older
  2. 5 days ago

    Djamel A

    Jul 15 Oran (Algeria)

    @Eugene D 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

    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

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

  3. Derk J

    Jul 15 Pre-Release Testers, Xojo Pro

    You may want to set a color g.ForeColor =

  4. Markus W

    Jul 15 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...

    Does it really say vanvas in your code?

  5. Djamel A

    Jul 15 Oran (Algeria)

    @Markus W Does it really say vanvas in your code?

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

  6. 4 days ago

    Jeff T

    Jul 16 Midlands of England, Europe
    Edited 4 days ago

    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
  7. Djamel A

    Jul 16 Oran (Algeria)
      '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

    I tried with this wrote, but nothing change.

  8. Kevin G

    Jul 16 Pre-Release Testers, Xojo Pro Gatesheed, England

    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
  9. Jeff T

    Jul 16 Midlands of England, Europe
    Edited 4 days ago

    nothing change.

    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?

    does not work (defaultCanvas1),

    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

    pbuffer = new picture (CnvSkyMap.width,CnvSkyMap.height,32)

    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

  10. Djamel A

    Jul 16 Oran (Algeria)

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

    link text

  11. Jeff T

    Jul 16 Midlands of England, Europe

    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?

  12. 3 days ago

    Djamel A

    Jul 17 Oran (Algeria)

    @Jeff T 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?

    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.

  13. Djamel A

    Jul 17 Oran (Algeria)

    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

  14. Kevin G

    Jul 17 Pre-Release Testers, Xojo Pro Gatesheed, England

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

  15. Djamel A

    Jul 17 Oran (Algeria)

    @Kevin G 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.

  16. Kevin G

    Jul 17 Pre-Release Testers, Xojo Pro Answer Gatesheed, England

    @Djamel A;AMRANE 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.

  17. Djamel A

    Jul 17 Oran (Algeria)

    @Kevin G 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 !

  18. Djamel A

    Jul 17 Oran (Algeria)

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

  19. 2 days ago

    Djamel A

    Jul 18 Oran (Algeria)

    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

  20. Kevin G

    Jul 18 Pre-Release Testers, Xojo Pro Gatesheed, England

    Your project worked for me when I selected the Time Change option.

  21. Djamel A

    2 days ago Oran (Algeria)

    Ah, sorry i forget that i bought Time ctrl and Date ctrl plugins, RB in this time have not .
    I tried with VB6 .ocx DateTimePicker does not run properly under xojo (windows).
    Any way, it is running for time change.
    I was using :

    Dim d as New Date

    extracting time by :
    hrs = d.Date.Hours
    mn = d.Date.Minutes
    ss = d.Date.Seconds

    Instead of :
    hrs = TimeCtrl.Hour
    mn= TimeCtrl.Minute
    ss = TimeCtrl.Second
    Thank you Kevin and others.

or Sign Up to reply!