Drawing made by DrawLine is unstable

Started by krunch, March 14, 2011, 04:20:13 AM

Previous topic - Next topic

krunch

Hi

I try to use DrawLine to change a PictureBox appearance instead of changing it's Picture property.

But I first meet this problem : the drawing made by DrawLine is erased when the cursor passes over the PictureBox (rollover). It's cleared only the first time...
This problem appears when the PictureBox has a OnClick event

Please try the sample below, then disabled PictureBox_OnClick event, save and run again.

Another thing I wonder (I don't know if it's normal) is why DrawLine doesn't work when called from OnInitialize.. it must be called before to make the "first" drawing ?
Code (autolisp) Select
(defun c:go ()
 (command "OPENDCL")
 (dcl_Project_Load "draw" T)
 (dcl_Form_Show draw_Form1)
 (Draw)
 (princ)
)
(defun c:draw_Form1_OnInitialize (/)
 (Draw) ; this one doesn't work ??
 (princ)
)
(defun c:draw_Form1_TextButton1_OnClicked (/)
 (Draw)
)
(defun Draw ()
 (dcl_PictureBox_DrawLine draw_Form1_PictureBox1 '((22 10 22 34 0) (10 22 34 22 0)))
)

krunch

#1
Something more in a specific case (superposition Picture + drawing with DrawLine) : this is the same sample, but the PictureBox has a Picture
In this case the drawing is also erased by a click on the PictureBox, please try the new sample below.

Same thing : the problem disappears if you disable the OnClick event in the PictureBox (or if you delete the picture in the PictureBox).

Note: OnClick event is enabled and c:draw+_Form1_PictureBox1_OnClicked doesn't exist in Lisp, but no error alert is fired ?

Lisp is the same :
Code (autolisp) Select
(defun c:go ()
  (command "OPENDCL")
  (dcl_Project_Load "draw+" T)
  (dcl_Form_Show draw+_Form1)

  (Draw)
  (princ)
)
(defun c:draw+_Form1_OnInitialize (/)
  (Draw) ; this one doesn't work ??  
  (princ)
)
(defun c:draw+_Form1_TextButton1_OnClicked (/)
  (Draw)
)
(defun Draw ()
  (dcl_PictureBox_DrawLine draw+_Form1_PictureBox1 '((22 10 22 34 0) (10 22 34 22 0)))
)

krunch

Hi
Adding DrawLine onto a picture (post#2) is not what I want : I was just reporting the trouble..

So my main problem is #1 : how to get a stable draw, not erased by the first mouse passage ?

A basic solution is to redraw on each MouseMove (sample below), it works, but I believe that's not a good solution ?
Code (autolisp) Select
(defun c:draw_Form1_PictureBox1_OnMouseMove (Flags X Y /)
  (Draw)
)


Did I miss something ?

Thanks

krunch

OK, I've found it : drawing has to be done in a OnPaint event

Thanks everybody !  ;)


Code (autolisp) Select
(defun c:go ()
  (command "OPENDCL")
  (dcl_Project_Load "draw" T)
  (dcl_Form_Show draw_Form1)
  (princ)
)
(defun c:draw_Form1_PictureBox1_OnPaint (HasFocus /)
  (Draw)
)
(defun Draw ()
  (dcl_PictureBox_DrawLine draw_Form1_PictureBox1 '((22 10 22 34 0) (10 22 34 22 0)))
)

krunch

#4
I notice that the OnPaint event is fired :

- 1 time when the form is initialized
- 1 time the first OnMouseEntered(PictureBox), only the first time
- 2 times OnClick(PictureBox)
- 1 time OnKillFocus(PictureBox) after 1 click, only after 1 click
- 0 time OnRightClick....

::)

Fred Tomke

Hi, OnPaint is fired whenever the form is moved or will be covered by other forms and so on. DrawLine creates temporary graphics. Have a look at StoreImage method.
OnPaint should only contains methods to reproduce graphics and must not contain refresh method. There are other samples in this forum:

http://www.opendcl.com/forum/index.php?topic=1336.msg7150#msg7150
http://www.opendcl.com/forum/index.php?topic=994.0
http://www.opendcl.com/forum/index.php?topic=995.0

Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

krunch

Thanks a lot Fred

So I just needed StoreImage to fasten the graphic, no OnPaint event

The only thing I don't understand is why the initial DrawLine has to be called after(?) OnInitialize (remark below), but it works fine with StoreImage
Thanks

Code (autolisp) Select
(defun c:go ()
  (command "OPENDCL")
  (dcl_Project_Load "draw" T)
  (dcl_Form_Show draw_Form1)
 
  (Draw)        ; initial drawing
 
  (princ)
)
(defun c:draw_Form1_OnInitialize (/)
;;;  (Draw)     ; this one doesn't work ??
  (princ)
)

(defun Draw ()
  (dcl_PictureBox_DrawLine draw_Form1_PictureBox1 '((22 10 22 34 0) (10 22 34 22 0)))
  (dcl_PictureBox_StoreImage draw_Form1_PictureBox1)
)

owenwengerd

The DrawXXX functions draw on the screen, but OnInitialize is called before the control is visible, so there is nowhere to draw.
Owen Wengerd (Outside The Box) / ManuSoft