Guidance
指路人
g.yi.org
software / rapidq / Examples / QObject / Customized Event.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'From:  b_j0  Sat Feb 22, 2003  5:34 am
' extend your component from QObject so that your main
' component's features cannot be directly accessed. If you do this then
' no one will be able to directly use the routines you described
' (unless someone were to directly modify your code), and *you* will be
' able to implement your own subs/functions.


     DECLARE SUB QNewCanvas_OnPaintEvent ' Event template

' Create the component Type QNewCanvas extends QObject: With This
Private:
     MainComponent AS QCANVAS ' Keep your main component private

Public:
     OnPaint AS EVENT(QNewCanvas_OnPaintEvent) ' Implement your own OnPaint event

' Property sets are being used so an initialization routine for this
' component isn't necessary. They're all simplified because this is
' just an example.
     Top AS LONG PROPERTY SET SetTop
     PROPERTY SET SetTop(Top AS LONG)
      .Top=Top
      .MainComponent.Top=.Top
     END PROPERTY

     Left AS LONG PROPERTY SET SetLeft
     PROPERTY SET SetLeft(Left AS LONG)
      .Left=Left
      .MainComponent.Left=.Left
     END PROPERTY

     Width AS LONG PROPERTY SET SetWidth
     PROPERTY SET SetWidth(Width AS LONG)
      .Width=Width
      .MainComponent.Width=.Width
     END PROPERTY

     Height AS LONG PROPERTY SET SetHeight
     PROPERTY SET SetHeight(Height AS LONG)
      .Height=Height
      .MainComponent.Height=.Height
     END PROPERTY

     COLOR AS LONG

     PARENT AS QFORM PROPERTY SET SetParent
     PROPERTY SET SetParent(ParentForm AS QFORM)
      .MainComponent.PARENT=ParentForm
     END PROPERTY

' See, you can implement similar routines and control exactly what happens
     SUB TextOut(X%, Y%, S$, FC%, BC%)
      .MainComponent.TextOut(X%, Y%, S$, FC%, BC%)
     END SUB

' Here's the main reason for this example. This is how to handle events
' yourself without the user overriding them.
     EVENT MainComponent.OnPaint
      .MainComponent.FillRect(0, 0, .Width, .Height, .COLOR)
      CALLFUNC .OnPaint
     END EVENT

     CONSTRUCTOR
      SetWidth(100)
      SetHeight(100)
      COLOR=&H0000FF
     END CONSTRUCTOR
     END WITH: END TYPE


' Demo it :)
     DECLARE SUB OnNewCanvasPaint

     CREATE Form AS QFORM
      CAPTION="QNewCanvas"
      Center
      CREATE NewCanvas AS QNewCanvas
       Top=10
       Left=10
       OnPaint=OnNewCanvasPaint
      END CREATE
     END CREATE

     SUB OnNewCanvasPaint
      NewCanvas.TextOut(3, 3, "Hello!", 0, NewCanvas.COLOR)
     END SUB

     Form.SHOWMODAL
掌柜推荐
 
 
¥860.00 ·
 
 
¥900.00 ·
 
 
¥810.00 ·
 
 
¥317.00 ·
 
 
¥1,370.00 ·
 
 
¥660.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-02-23 09:59:53