Reputation: 26414
Problem with my approach is that image, text or line drawn, lags by maybe 0.2 seconds, when resizing the form. So if you need an image in bottom right corner, it takes that 0.2 seconds to come in place after resize. Also, if you do heavy resizing, it starts lagging down to 1-2FPS, while the form expands on a big screen. Sample code looks like this (VB.NET):
Public Class Form1
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim icon As Icon = SystemIcons.Exclamation
Dim imageWidth As Integer = icon.Width
Dim imageHeight As Integer = icon.Height
e.Graphics.DrawIcon(icon, Me.ClientRectangle.Right - imageWidth,
Me.ClientRectangle.Bottom - imageHeight)
End Sub
Private Sub Form1_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
Me.Invalidate()
End Sub
End Class
Is there anything that can be done to make it smoother?
Upvotes: 0
Views: 3743
Reputation: 146
Windows Forms provides a style setting to double buffer the screen. This does a lot of setup for you.
Also, double buffering gets rid of the need to clear the screen so overriding OnPaintBackground
and returning without calling the base class will prevent a lot of work that will not be seen anyway.
For some of the best examples of GDI+ / winforms double buffering check out my animation examples.
Upvotes: 2
Reputation: 55382
Resizing your window is always going to involve redrawing the image in the new location. However, there are some things you can try that may or may not make the redrawing more efficient.
Upvotes: 1