Form_Paint gets decoupled ??? 
Author Message
 Form_Paint gets decoupled ???

I am doing a bit of work in the Paint event on a VB form.  I am finding that after
some indetermined amount of time, the paint event quits getting called, or fails to
link up properly.

Here is code I have that is acting up:

        Dim Bic As Pen
        Dim Fan As Brush

        msgbox("hi")

        Bic = New Pen(color.Black, 3)

        'Rotating background color (by painting it)
        C = (C + 1) Mod 4
        Select Case C
            Case 0
                Fan = New SolidBrush(color.Red)
            Case 1
                Fan = New SolidBrush(color.White)
            Case 2
                Fan = New SolidBrush(color.Blue)
            Case 3
                Fan = New SolidBrush(color.White)
        End Select

        With e.Graphics
            .FillRectangle(Fan, Form1.ClientRectangle)
            .DrawRectangle(Bic, Form1.ClientRectangle)
        End With

While you may be able to paste this in a new form, and get it working,
after working with it a while, (starting and stopping the program, editing
etc.  I havent figured out what causes it other than just using it) eventually
the program starts up but the Paint event does not get called, for anything,
including a form.refresh

I put the msgbox statement in there after the problem started to confirm that
the code is not executing.  After adding the MsgBox, and running the program
(This is ALL there is except for a class level dimensioned variable named C)
the MsgBox did not show.

I did find that if I override the OnPaint method, I can get it back, and then I
commented out the OnPaint, which somehow effected the next run, in that
the paint event started getting called again:

It is an all or nothing issue, either it works when you fire it up, or it doesn't...

Has anyone noticed anything like this?

LFS



Tue, 08 Jul 2003 23:56:57 GMT  
 Form_Paint gets decoupled ???
I don't understand where you are putting this code.
It has to be in a Paint method to be called, right?
So you have to override OnPaint anyway, right? Or am I missing something?

Jim Cooper



Wed, 09 Jul 2003 01:09:39 GMT  
 Form_Paint gets decoupled ???


Quote:
> I don't understand where you are putting this code.

<q>
I am doing a bit of work in the Paint event on a VB form.  I am finding that after
some indetermined amount of time, the paint event quits getting called, or fails to
link up properly.
</q>

Quote:
> It has to be in a Paint method to be called, right?
> So you have to override OnPaint anyway, right? Or am I missing something?

Anyway?  No, I expect I should not 'need' to use OnPaint, if the Form_Paint
event is going to work.  (180 from the way it should be, noted)  I had been
editing code in the paint event, and may have made a few too many pens
without calling Dispose (hindsight) or what not.  In any case, I pasted the
exact code, minus the procedureal declaration, with the inclusion of a
Msgbox.  That code (in the Paint event) caused me problems that looked like
the event was not getting called  (I don't yet know what the cause was)

LFS



Wed, 09 Jul 2003 02:02:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. labels dissapear mysteriously with Form_Paint

2. Strange behavior of Form_Paint and X close button.

3. Form_Paint occurs 3 times?

4. Problem with MDI and Form_Paint

5. How to unload a form while its still busy with Form_Paint

6. Detecting WM_SYSCOLORCHANGE Message in Form_Paint

7. SelectClipRgn fails in Form_Paint()

8. Possible to decouple editbox and dropdown list of combobox?

9. Getting Errors when Access DB gets large

10. Getting image into field (SQL 7) and getting it back out

11. Help!Getting random text strings, and getting random numbers up to a specific number.

12. Getting a file name

 

 
Powered by phpBB® Forum Software