Click here to Skip to main content
15,911,531 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: GDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) Pin
Henry Minute27-Oct-09 10:51
Henry Minute27-Oct-09 10:51 
GeneralRe: GDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) Pin
rudozkv_new27-Oct-09 22:36
rudozkv_new27-Oct-09 22:36 
AnswerRe: GDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) Pin
freakyit27-Oct-09 21:35
freakyit27-Oct-09 21:35 
GeneralRe: GDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) Pin
rudozkv_new27-Oct-09 22:35
rudozkv_new27-Oct-09 22:35 
GeneralRe: GDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) Pin
freakyit27-Oct-09 23:01
freakyit27-Oct-09 23:01 
GeneralRe: GDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) Pin
rudozkv_new27-Oct-09 23:18
rudozkv_new27-Oct-09 23:18 
GeneralRe: GDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) Pin
freakyit27-Oct-09 23:34
freakyit27-Oct-09 23:34 
GeneralRe: GDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) Pin
rudozkv_new28-Oct-09 3:16
rudozkv_new28-Oct-09 3:16 
I think to upload code here, I need to create an article.
So I created another simple example.
I have Form1.vb and UserControl1.vb.
Form1 size is 980x700.
On Form1 are two UserControl1 Picture1 (300x600) and Picture2(600x600).

Code for Form1:
Public Class Form1
    'Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    '    Invalidate(True)
    'End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        HScrollBar1.Minimum = 1
        HScrollBar1.Maximum = Me.ClientSize.Width
        HScrollBar1.LargeChange = 100
    End Sub

    Private Sub MyScroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll    
        'Static t_start As DateTime = Now
        'Dim t_span As TimeSpan
        'Debug.Print("Elapsed time: " && t_span.Milliseconds)
        't_start = Now
        Invalidate(True)
    End Sub
End Class


For usercontrol1
Public Class UserControl1

    Private Sub OnPaintPic1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim rcPaper = Me.ClientRectangle
        Dim time_start As DateTime = Now
        Dim t_span As TimeSpan

        Dim bmp As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
        Dim graph As Graphics
        graph = Graphics.FromImage(bmp)
        'Graphics* graph = Graphics::FromImage(&bmp);
        ' Draw paper
        rcPaper.Location = rcPaper.Location '+ ptScrollOffset
        graph.Clear(Color.DarkGray)
        'Debug.Print("Grid size: " & Me.ClientSize.Width & "x" & Me.ClientSize.Height)
        'Debug.Print("Parent size: " & Parent.ClientSize.Width & "x" & Parent.ClientSize.Height)
        'graph.FillRectangle(Brushes.White, rcPaper)
        graph.DrawRectangle(Pens.Black, rcPaper)
        ' Draw the grid.
        ' If bShowGrid Then
        For x As Integer = 0 To bmp.Width Step 10
            For y As Integer = 0 To bmp.Height Step 10
                graph.DrawLine(Pens.Azure, x, y, x + 0.5F, y + 0.5F)
            Next y
        Next x
        'End If
        e.Graphics.DrawImage(bmp, 0, 0)
        t_span = Now - time_start
        bmp.Dispose()
        graph.Dispose()
        Debug.Print("OnPaint: " && Me.Name && " elapsed time: " && t_span.Milliseconds)
    End Sub
End Class


From this example I know this:
Elapsed time for scroll message is about 0 milliseconds.

Elapsed time for draw usercontrol is about 30 ms.

When I call invalidate from timer with 100ms period immediate window shows something like this:
OnPaint: Picture1 elapsed time: 15
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture1 elapsed time: 15
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture1 elapsed time: 15
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture1 elapsed time: 15
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture1 elapsed time: 15
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture1 elapsed time: 15

When I disable timer and repaint from scroll event it looks like this:
OnPaint: Picture2 elapsed time: 31
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture2 elapsed time: 31
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture2 elapsed time: 31
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture1 elapsed time: 15
OnPaint: Picture2 elapsed time: 46
OnPaint: Picture1 elapsed time: 31
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture1 elapsed time: 15
OnPaint: Picture2 elapsed time: 31
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture2 elapsed time: 31
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture2 elapsed time: 31
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture2 elapsed time: 31
OnPaint: Picture2 elapsed time: 15
OnPaint: Picture2 elapsed time: 31
OnPaint: Picture2 elapsed time: 15

From these results I think I need somehow to reduce OnScroll events or call another set of repaints after previous set of repaint has finished.
GeneralRe: GDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) Pin
freakyit29-Oct-09 1:13
freakyit29-Oct-09 1:13 
AnswerRe: GDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) Pin
rudozkv_new28-Oct-09 23:09
rudozkv_new28-Oct-09 23:09 
Questionc#.net Pin
Amit Spadez26-Oct-09 23:38
professionalAmit Spadez26-Oct-09 23:38 
AnswerRe: c#.net Pin
Shameel26-Oct-09 23:59
professionalShameel26-Oct-09 23:59 
GeneralRe: c#.net Pin
Amit Spadez27-Oct-09 0:03
professionalAmit Spadez27-Oct-09 0:03 
GeneralRe: c#.net Pin
Covean27-Oct-09 0:16
Covean27-Oct-09 0:16 
GeneralRe: c#.net Pin
Amit Spadez27-Oct-09 0:17
professionalAmit Spadez27-Oct-09 0:17 
GeneralRe: c#.net Pin
Covean27-Oct-09 0:20
Covean27-Oct-09 0:20 
GeneralRe: c#.net Pin
Amit Spadez27-Oct-09 0:24
professionalAmit Spadez27-Oct-09 0:24 
GeneralRe: c#.net Pin
Covean27-Oct-09 0:34
Covean27-Oct-09 0:34 
QuestionTabbed ListBox in a Web Page Pin
MarkyMark196126-Oct-09 8:21
MarkyMark196126-Oct-09 8:21 
AnswerRe: Tabbed ListBox in a Web Page Pin
Not Active26-Oct-09 8:31
mentorNot Active26-Oct-09 8:31 
GeneralRe: Tabbed ListBox in a Web Page Pin
MarkyMark196126-Oct-09 8:41
MarkyMark196126-Oct-09 8:41 
GeneralRe: Tabbed ListBox in a Web Page Pin
Not Active26-Oct-09 8:52
mentorNot Active26-Oct-09 8:52 
GeneralRe: Tabbed ListBox in a Web Page Pin
MarkyMark196126-Oct-09 9:00
MarkyMark196126-Oct-09 9:00 
GeneralRe: Tabbed ListBox in a Web Page Pin
Not Active26-Oct-09 9:05
mentorNot Active26-Oct-09 9:05 
GeneralRe: Tabbed ListBox in a Web Page Pin
MarkyMark196126-Oct-09 9:09
MarkyMark196126-Oct-09 9:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.