Why use Protected Overide Sub OnPaint rather than the standard Paint_Event ?

I notice many good programmers use this following method rather than the usual Paint_Event when painting to the form.
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Dim g As Graphics = e.Graphics
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
MyBase.OnPaint(e)
End Sub
Can anybody share the reasons why? Thanks 
Top Tip: Toothache? Cut paper towel to 2"square. Smear with olive oil. Sprinkle on Cayenne Pepper. Fold over few times to form small wad. Tuck in between wall of mouth and gum. Leave 1 - 2 hrs. You will thank me!

OK Crazypennie, maybe you are right. I tend to rant on a bit sometimes.
Also, maybe the jumpy graphics is made worse because the animation output is not synced with the video hardware refresh rate. We can get around that slightly by using a very high fps. 
Hi Leon,
I tried modifying your code using a GraphicsFrame class that I wrote a little while back, the class utilizes the bufferedcontext/bufferedgraphics, instead of using the forms graphics directly. In theory, all objects should be rendered to the buffer before
the forms graphics object. Is this less glitchy/faster on your pc? It seemed less glitchy/faster on mine..., and previous benchmarks show that using buffered graphics in this manner improved render time.
You can read the discussion on
this thread.
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form11 ' drawing Code by Paul Ishak Apr 2015 A spinning pie chart. My timing code.
Private Angle As Single = 100
Private NextIncrement As Single = 1
Private Randomizer As New Random(Now.Millisecond)
Private SliceColors As New List(Of Color)
Private SlicesOnWheel As Integer = 24
Private Velocity As Single = 0
Private WheelRadius As Integer = 300
Private WheelLocation As New Point(50, 50)
Private SW As New Stopwatch
Private SFlag As Boolean ' wheel is currently spinning
Private CntMS As Integer ' count the milliseconds
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Dim gFrame As New GraphicsFrame(e.Graphics, Me.ClientRectangle.Size)
Dim g As Graphics = gFrame.Graphics
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.Clear(Me.BackColor)
Dim sliceAngle As Single = CSng(360 / SlicesOnWheel)
Dim rect As New Rectangle(WheelLocation, New Size(WheelRadius, WheelRadius))
Dim curveWidth As Integer = CInt(WheelRadius - (WheelRadius / (2.0! * 0.9)))
Dim rect2 As New Rectangle(rect.Left + curveWidth, rect.Top + curveWidth, rect.Width - curveWidth * 2, rect.Height - curveWidth * 2)
Dim inc As UInteger = UInteger.MaxValue \ 360
For I As Single = 0 To 359 Step sliceAngle
g.FillPie(New SolidBrush(SliceColors(CInt(I / sliceAngle))), rect, I + NormalizeAngle(Angle), sliceAngle)
g.DrawPie(Pens.White, rect, I + NormalizeAngle(Angle), sliceAngle)
Next
g.FillEllipse(Brushes.Black, rect2)
g.DrawEllipse(Pens.White, rect2)
g.DrawEllipse(Pens.White, rect)
MyBase.OnPaint(e)
If SFlag Then
If Me.Text = " " Then Me.Text = "" Else Me.Text = " "
End If
gFrame.Render()
gFrame.Dispose()
MyBase.OnPaint(e)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnSpin.Click
If Not SFlag Then
Velocity = Randomizer.Next(3, 5)
NextIncrement = Velocity
SFlag = True
CntMS = 0 : SW.Reset() : SW.Start()
If Me.Text = " " Then Me.Text = "" Else Me.Text = " "
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.DoubleBuffered = True
SliceColors.Add(Color.Black)
SliceColors.Add(Color.LightBlue)
SliceColors.Add(Color.SeaGreen)
SliceColors.Add(Color.Yellow)
SliceColors.Add(Color.Red)
SliceColors.Add(Color.LightBlue)
SliceColors.Add(Color.Orange)
SliceColors.Add(Color.Violet)
SliceColors.Add(Color.Yellow)
SliceColors.Add(Color.Black)
SliceColors.Add(Color.Green)
SliceColors.Add(Color.Black)
SliceColors.Add(Color.Green)
SliceColors.Add(Color.Red)
SliceColors.Add(Color.Blue)
SliceColors.Add(Color.SeaGreen)
SliceColors.Add(Color.Pink)
SliceColors.Add(Color.Black)
SliceColors.Add(Color.Purple)
SliceColors.Add(Color.SkyBlue)
SliceColors.Add(Color.Aqua)
SliceColors.Add(Color.White)
SliceColors.Add(Color.Red)
SliceColors.Add(Color.Blue)
SliceColors.Add(Color.Pink)
SliceColors.Add(Color.SeaGreen)
SliceColors.Add(Color.Orange)
ClientSize = New Size(375, 375)
Me.Show()
btnSpin.Refresh()
End Sub
Public Function NormalizeAngle(value As Single) As Single
Return value Mod 360.0!
End Function
Private Sub Form11_TextChanged(sender As Object, e As EventArgs) Handles Me.TextChanged
If Not SFlag Then Exit Sub
Angle = NormalizeAngle(Angle + NextIncrement)
NextIncrement = CSng(NextIncrement - 0.0033)
If NextIncrement <= 0.0033 Then
SFlag = False : SW.Stop() : Exit Sub
End If
Invalidate()
CntMS += 5 ' <<< set timer interval here <<<
Do Until SW.ElapsedMilliseconds > CntMS
Loop
End Sub
End Class
Public Class GraphicsFrame
Implements IDisposable
Private disposedValue As Boolean
Private BackBuffer As System.Drawing.BufferedGraphics = Nothing
Public ReadOnly Property Graphics() As System.Drawing.Graphics
Get
Return Me.BackBuffer.Graphics
End Get
End Property
Public Sub New(ByVal canvas As System.Windows.Forms.Control)
BufferedGraphicsManager.Current.MaximumBuffer = New Size(canvas.ClientRectangle.Width + 1, canvas.ClientRectangle.Height + 1)
Me.BackBuffer = BufferedGraphicsManager.Current.Allocate(canvas.CreateGraphics, New Rectangle(0, 0, canvas.ClientRectangle.Width, canvas.ClientRectangle.Height))
End Sub
Public Sub New(ByVal canvasGraphics As Graphics, maximumBuffer As Size)
BufferedGraphicsManager.Current.MaximumBuffer = New Size(maximumBuffer.Width + 1, maximumBuffer.Height + 1)
Me.BackBuffer = BufferedGraphicsManager.Current.Allocate(canvasGraphics, New Rectangle(0, 0, maximumBuffer.Width, maximumBuffer.Height))
End Sub
Public Sub New(ByVal handle As IntPtr, maximumBuffer As Size)
BufferedGraphicsManager.Current.MaximumBuffer = New Size(maximumBuffer.Width + 1, maximumBuffer.Height + 1)
Me.BackBuffer = BufferedGraphicsManager.Current.Allocate(Graphics.FromHwnd(handle), New Rectangle(0, 0, maximumBuffer.Width, maximumBuffer.Height))
End Sub
Public Sub New(ByVal canvas As Image)
BufferedGraphicsManager.Current.MaximumBuffer = New Size(canvas.Width + 1, canvas.Height + 1)
Me.BackBuffer = BufferedGraphicsManager.Current.Allocate(Graphics.FromImage(canvas), New Rectangle(0, 0, canvas.Width, canvas.Height))
End Sub
Public Sub New(ByVal canvas As Bitmap)
BufferedGraphicsManager.Current.MaximumBuffer = New Size(canvas.Size.Width + 1, canvas.Size.Height + 1)
Me.BackBuffer = BufferedGraphicsManager.Current.Allocate(Graphics.FromImage(canvas), New Rectangle(0, 0, canvas.Width, canvas.Height))
End Sub
Public Sub Render()
If Not BackBuffer Is Nothing Then BackBuffer.Render()
End Sub
Protected Overridable Sub Dispose(disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
Me.BackBuffer = Nothing
GC.Collect()
End If
End If
Me.disposedValue = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
End Class
Don't forget to vote for Helpful Posts and
Mark Answers!
*This post does not reflect the opinion of Microsoft, or its employees.

Similar Messages

  • How do I download a campaign font for use in iBooks Authoring rather than the standard fonts available?

    Is it possible to use a campaign font when authoring an iBook rather than the standard font menu?

    The font menu in the toolbar includes supported iOS fonts on the iPad. You are obligated to work with those fonts only.
    While apps have a way to add additional fonts, iBooks Author does not provide support otherwise, sorry.
    As an alternative, you can use any font you like and generate an image instead.

  • My iPhone has suddenly started sending emails in Courier New (rather than the standard Arial).  They appear in Arial when I compose them, but turn to Courier new in the sent folder and when displayed to the recipient.  I use Yahoo Mobile Mail.  Help!

    My iPhone has suddenly started sending emails in Courier New (rather than the standard Arial).  They appear in Arial when I compose them, but turn to Courier new in the sent folder and when displayed to the recipient.  I use Yahoo Mobile Mail.  Help!  How can I change the settings so that the sent emails go back to Arial?  Thank you!

    I'm not sure if it's a Yahoo Mobile mail or an iphone issue... have asked the Yahoo forum but no replies yet...  Any help appreciated!

  • Why does mtab show /dev/root rather than the partition mounted on /

    Sorry if I have missed something I should have read, but can anybody explain please why my mtab no longer contains a reference to the actual partition which is mounted as root.  I have:
    /dev/root / ext3 rw,relatime,errors=continue,data=writeback
    but no reference to the partition.
    TIA

    It's related to this by the looks of it (see the links in post #6).  /etc/mtab is created by copying what's in /proc/mounts.
    https://bbs.archlinux.org/viewtopic.php?id=99417

  • How can I make audio come out of the phone speaker rather than the standard speaker in android?

    just like the title says. is this possible? Has anyone sussessfully done this?

    With AIR 2.7, there is no way to switch between device speaker and phone  earpiece on Android and iOS. All sounds, by default, play through device speaker only.
    The link mentioned by Colin just presents a way to enable phone receiver on iOS. However thats a bug and will be rectified in future releases. So I will not encourage you to use that.

  • I heard some promote use of "Terminal Services(RDS)", rather than App-V application with SCCM 2012 even if you have SCCM licens.

    Hi,
    I heard some promote use of "Terminal Services(RDS)", rather than App-V application with SCCM 2012 even if you have SCCM licens. The reason you dont need to repackage\test the application on an client OS...
    I don't agree and I have not Heard this Before, just that you use TS for some scenario.
    Or is it more likely that "Terminal Services(RDS)", take over the applikation administration?
    /SaiTech

    Surely this all depends on your environment. There's nothing wrong with creating RemoteApps to push to client devices. Maybe you have an environment where RDS is widely used. 
    Why not leverage both solutions and target App-V's at RDS servers and then create App-V based RemoteApps that users can run at home as part of a home working solution via RDWeb.
    Creating apps via RDS will be an admin overhead yes but then so is creating App-V packages in SCCM.
    I don't agree with the arguement re: 'you dont need to repackage\test the application on an client OS...' as
    App-V allows you to run on multple O/S types. 
    To be honest both technologies have their pros and cons. 
    Cheers
    Paul | sccmentor.wordpress.com

  • I presently use iCloud and run a laptop PC plus an iPad2 and an iPhone 4.  I plan to travel and want to take my netbook, rather than the laptop PC for travelling.  How do I get my apple tools to work mwith a new, temporary PC?

    I presently use iCloud and run a laptop PC plus an iPad2 and an iPhone 4.  I plan to travel and want to take my netbook, rather than the laptop PC for travelling.  How do I get my apple tools to work mwith a new, temporary PC?

    ayorico15 wrote:
    It's not the pictures I'm worried about. I can get them off my phone without iTunes. 
    You can export ONLY Camera Roll photos and videos.
    ayorico15 wrote:
    All my apps were downloaded from my new apple ID. Not his.
    Sign in to iTunes Store (on desktop itunes) with your ID. Plug your iphone to itunes, right click on it and choose transfer purchases.Right click again and choose backup. Then you can sync with iTunes.
    ayorico15 wrote:
    It's not the pictures I'm worried about.  It's all my saved conversations
    Your conversations will not deleted if you sync with your iTunes.
    What is the problem with iCloud? iCloud has nothing to do with iTunes syncing.

  • What are the implications of using jquery version 1.10.2 rather than the version (1.7.1) that Adobe

    What are the implications of using jquery version 1.10.2 rather than the version (1.7.1) that Adobe uses? Thanks
    Bob

    I am having trouble when my Edge Animate composition (banner ad) appears on a web page that uses jquery version 1.8.23. Some of the functionality of the host page no longer works. This occurs only when my composition is present & the functionality returns when another ad is displayed (either a Flash ad or a gif). It happens in Chrome Version 31.0.1650.63 m, Chrome Version 33.0.1738.0 canary & IE 11.
    I had edited my Edge Animate files to use the Adobe CDN option & to point to another server (mine) so only the html file was needed to be placed in the ad rotator & on the host's server. I now have edited them again to include the Google CDN locations for version jquery 1.10.2 (http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js). I am waiting for the host site to try this updated html file. When I visit just this new page & the old one that pointed to 1.7.1 for that matter, it works fine.
    Thank you for taking the time to read and answer my message.
    Bob

  • Can I use thumbnails rather than the {sitename} to load different galleries?

    Hi all-
    I'm new to Spry and all things Javascripting but I'm attempting to construct a image gallery using Spry in Dreamweaver CS3. I've used the "Original Photo Gallery" from the Spry Demo folder as a jumping off point and everything works correctly.
    I would like to know if it is possible to use representative thumbnails rather than the select dropdown to launch the different galleries? I'm sure it is, but I'm a total neophyte and have no idea what to do. I'd like to set up a AP Div with 9 thumbnails in a table that would each launch a different gallery. How do I do that?
    Jimmy

    Hello, because you're SELECTing tournament.tourtype in the SELECT list, the answer is not really. If you didn't need t.tourtype in the SELECT list, you could have:
    select m.memberid, m.lastname, m.firstname
    from member m
    where exists (select 1
            from entry e inner join tournament t on (e.tourid=t.tourid)
            where m.memberid=e.memberid
                and upper(t.tourtype)='OPEN');And you know the t.tourtype is 'OPEN' anyway, so you don't need to SELECT it. So you could have this, and the answer is yes:
    select m.memberid, m.lastname, m.firstname, 'OPEN' tourtype
    from member m
    where exists (select 1
            from entry e inner join tournament t on (e.tourid=t.tourid)
            where m.memberid=e.memberid
                and upper(t.tourtype)='OPEN');Edited by: SeánMacGC on May 7, 2009 2:09 AM

  • I created a website with iWeb but use GoDady for hosting it rather than MobileMe. The images on my Gallery page do not show at all on the external domain but they DO show when seen on MobileMe. Has anyone encountered this problem before? Many thanks!

    Hello al!
    I created a website with iWeb but use GoDady for hosting it rather than MobileMe. The images on my Gallery page do not show at all on the external domain but they DO show when seen on MobileMe. Has anyone encountered this problem before? Many thanks!

    Just create a new page (or use the existing photo page) on your external site and use html to add an iframe sized to the page and link it to the mobilme gallery page. Works for me just fine when showing my gallery from a yahoo site.
    like this
    <iframe scrolling="off" allowTransparency="true" frameborder="0" scrolling="yes" style="width:100%;height:100%;border:none" src="http://gallery.me.com/your_account_name"></iframe>

  • HT4314 I have tried to log into clash of clans on my iPad and it just keeps going to a new game rather than the one saved on my iPhone. I have been using the game centre and same user name and password ?

    I have tried to log into clash of clans on my iPad and it just keeps going to a new game rather than the one saved on my iPhone. I have been using the game centre and same user name and password ?

    I have the same problem.. EXACTLY. .  When phoning Apple Support they had trouble understanding my problem and couldnt find any type of solution. No one seems to take responsibility for GameCenter issues. The assistant escalated the problem but no one could find an answer. .
    The only idea was to set up a new apple id, hence a new GameCenter account. . But that would loose all the itunes data. Anyone got ideas ?

  • I am setting up ipads for use in an elementary, and I would like the "home screen" to be the apps, rather than the default with the chat, mail, etc icons.  how do I change that?

    Can anyone answer this question?
    I am setting up ipads for use in an elementary, and I would like the "home screen" to be the apps, rather than the default with the chat, mail, etc icons.  how do I change that?

    Depending on exactly what you want to do, there are a couple of ways of handling this. You may want to access teh user guide for some ideas: http://manuals.info.apple.com/en_US/ipad_user_guide.pdf
    In particular, check the sections on Customizing iPad and Settings > Restrictions.

  • How can I get the App store to use money in my account rather than a credit card when I want to buy something?

    How can I get the App store to use money in my account rather than a credit card when I want to buy something?

    The iTunes/Mac App Stores use credit on an account first. You are asked to supply an additional payment method when the cash credit doesn't cover the complete cost of the purchase.

  • When I click on a website in my reading list, why does top sites open rather than the site I've clicked on?

    When I click on a website in my Reader list in Safari, why does Top Sites open rather than the website I've clicked on?

    Go step by step and test.
    Reset Safari.
    Click Safari in the menu bar.
    From the drop down select "Reset Safari".
    Click "Reset".
    Delete Cookies
    Safari > Preferences > Privacy > Cookies and other website data:
    Click “Remove All Website Data”.
    Empty Caches
    Safari > Preference > Advanced
    Checkmark the box for "Show Develop menu in menu bar".
    Develop menu will appear in the Safari menu bar.
    Click Develop and select "Empty Caches" from the dropdown.
    Turn off Extensions if any, and launch Safari.
    Safari > Preferences > Extensions

  • Why does Firefox 5 open external (internet, SMTP) e-mail in the browser rather than the Lotus Notes Client?

    Using Lotus Notes as the system's primary mail client, '''some''' users experience external mail being opened in the browser rather than the the client. When they revert back to using an older version as the OS default browser, or indeed a different browser altogether, this does not happen.
    Again, this does not happen with all installations of 5.0 - just a few.

    go to "preferences" in Lotus Notes and enable "disable embodded browser for MIME mail" and it shoudn't open the browser anymore

Maybe you are looking for

  • HELP PLEASE- ON A DEADLINE

    Hi- I'm working with some HDV media in a ProRes 422 HQ sequence and while the picture looks great on my computer but when spitting it out via my Canopus box to a TV I'm getting a horrible looking picture (my final output will be DVD). Looks like inte

  • Create Role using SPRO_ADMIN has access to more t-codes then what it shows.

    In SPRO_ADMIN I created a Customizing Project and gave it a scope of: - SAP NetWeaver - Enterprise Structure - Cross-Application Components - SAP xApp Resource and Portfolio Management (SAP xRPM) - Strategic Enterprise Management/Business Analytics -

  • Send report via email as xls file.

    Hello from Spain, Sorry if this is not the correct forum. It's both a forms and reports question, but I think it fits better in the reports forum. I have queried into the forums for similar questions and found some threads without any replies around

  • Adobe Reader doesn't open .pdf files anymore. Error: 213:11.

    Adobe Reader doesn't open .pdf files anymore. It's written Error: 213:11. Details: laptop with Windows XP, Adobe Reader X

  • Bookmark all WINDOWS, not just all tabs in one window

    I have about 40 windows each with between 2 and 15 tabs so, I would like to bookmark them ALL at once and clean up my session is there any way to do that ? NOW, I KNOW ABOUT ctrl+shift+d, but I'm not in the mood to press it 40 times and then make a f