Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / March 2004



Tip: Looking for answers? Try searching our database.

Paint Event and AutoDraw problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lindsay - 07 Mar 2004 08:54 GMT
What is the best way to draw a picture onto a Usercontrol? I'm using
Paintpicture and Print which works well, but Paintpicture requires
AutoRedraw to be on. Because of this, the Paint event and I get portions of
the picture not being redrawn after an activity such as a Popupmenu or a
MsgBox on the main form. If I switch off AutoRedraw after drawing, it upsets
the drawing that the main form performs. Is there an API or something that
enables me to create a picture (done in sections) without needing AutoRedraw
on so that the Paint event can keep it up to date?
J French - 07 Mar 2004 11:15 GMT
>What is the best way to draw a picture onto a Usercontrol? I'm using
>Paintpicture and Print which works well, but Paintpicture requires
[quoted text clipped - 4 lines]
>enables me to create a picture (done in sections) without needing AutoRedraw
>on so that the Paint event can keep it up to date?

When you turn AutoRedraw on the UserControl ceases to receive Paint
Events

What I tend to do is to put all the drawing stuff in/under one routine
called LS_Refresh
- in the Paint event call LS_Refresh
- give the thing a Refresh property that calls LS_Refresh
- when Properties change call LS_Refresh

but have this code in LS_Refresh

   ' if Compiled (not Form design mode) then turn off Paint Events
   If UserControl.Ambient.UserMode = True Then
      If AutoRedraw = False Then
         AutoRedraw = True ' No more Paint Events - Reduce Flicker
      End If
   End If

However this is simply because I am putting AutoRedraw on at run time
in order to cut down on flicker.

If you put all your code in the Paint event and have the AutoRedraw
off, then you should be Ok
- PaintPicture does /not/ need AutoRedraw on
 (unless I'm missing something)

Here is an example of a UserControl without AutoRedraw
- I've tried putting popup menus (from right click a Textbox) over it
at run time, and it works just fine

Option Explicit

Private mPic As StdPicture
Private mCount As Long

Private Sub UserControl_Initialize()
  Set mPic = LoadPicture("c:\windows\bubbles.bmp")
  AutoRedraw = False
End Sub

Private Sub LS_Refresh()
  If Not mPic Is Nothing Then
     UserControl.PaintPicture mPic, 0, 0
  End If
  UserControl.CurrentX = 0
  UserControl.CurrentY = 0
  UserControl.ForeColor = vbRed
  UserControl.FontTransparent = True
  mCount = mCount + 1
  UserControl.Print "Hullo" + Str$(mCount)
  UserControl.Line (0, 100)-(400, 100)
End Sub

Private Sub UserControl_Paint()
  Call LS_Refresh
End Sub

=======
The only reason why I often use AutoRedraw is because I'm often
setting multiple properties, and it saves hassle if I just repaint
each time,
- although a priming Timer instead of painting works well

- and I must look at using UserControl.Refresh
 (nope - that caused flicker - but I reckon that is down to the way I
am drawing)

HTH
Lindsay - 07 Mar 2004 14:10 GMT
I played a little further myself. I now have AutoRedraw=False and using the
Paint event to call the drawing routine (same way you do it). I swapped the
paintpicture for some APIs to increase speed and all is well. Except, the
control does flicker a bit, even after compiling. The drawing routine paints
the entire control each time so there is no need to worry about what was
there before.

> >What is the best way to draw a picture onto a Usercontrol? I'm using
> >Paintpicture and Print which works well, but Paintpicture requires
[quoted text clipped - 73 lines]
>
> HTH
J French - 07 Mar 2004 16:30 GMT
>I played a little further myself. I now have AutoRedraw=False and using the
>Paint event to call the drawing routine (same way you do it). I swapped the
>paintpicture for some APIs to increase speed and all is well. Except, the
>control does flicker a bit, even after compiling. The drawing routine paints
>the entire control each time so there is no need to worry about what was
>there before.

Yes, the flickering appears to be because one is drawing something,
then drawing over it, which is profoundly annoying

I am toying with the idea of doing all painting to an invisible
Picturebox, then slapping that on the UserControl
- all within the Paint Event
- I think all the Print, PSet and Line statements are being
immediately processed when AutoRedraw = False

I've always reckoned that the PaintPicture was pretty fast

However I think that stuff like FillBox and SetPixel do not trigger an
immediate update, so maybe an 'All API' solution would be flicker free

I'll experiment with the invisible Picturebox method tomorrow
Mike Williams - 07 Mar 2004 16:41 GMT
> However I think that stuff like FillBox and SetPixel do not
> trigger an immediate update, so maybe an 'All API' solution
> would be flicker free . . .

Most of the VB drawing and painting functions trigger an update on on
Autoredraw Picture Box, but the various alternative API routines do not. So
if you use only API drawing and painting methods then there will be no
update at all until you specifically trigger one (Refresh or whatever). Even
a single "VB" method (such as SetPixel, for example) in an otherwise "All
API" drawing routine will trigger an update for the lot. If you want no
updates until you are ready for one then you should use nothing but API
methods.

Mike
Lindsay - 07 Mar 2004 17:48 GMT
Ah! The picture was drawn with APIs and then I printed some text with Print.

I just discovered an interesting error with all this. If I draw on a User
control (method seems irrelevant) and the put that on a form that has been
drawn on and then try to redraw the user control, I get a Blue Screen error!

Example:

User control has been drawn with Paintpicture via Paint event with
AutoRedraw=False. The form is drawn with Paintpicture via Form_Load
event(just once needed) with AutoRedraw=True. The User control triggers a
_Click event when clicked on which also triggers the Paint event within the
user control. As soon as I click the user control, Windows shuts down. The
error shows the file: Win32.sys (I think, from memory).

Quite bizarre!!

> > However I think that stuff like FillBox and SetPixel do not
> > trigger an immediate update, so maybe an 'All API' solution
[quoted text clipped - 10 lines]
>
> Mike
Lindsay - 07 Mar 2004 19:06 GMT
I tried an 'All API' solution but it still flickers. So, I tried your idea
(hope you don't mind me nicking it) of an invisible picturebox using APIs
and it works! The APIs I'm using are StretchBlt and TextOut.

> >I played a little further myself. I now have AutoRedraw=False and using the
> >Paint event to call the drawing routine (same way you do it). I swapped the
[quoted text clipped - 18 lines]
>
> I'll experiment with the invisible Picturebox method tomorrow
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.