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

.NET (Core and Framework)

 
QuestionHow to select multiple objects using mouse? C# .Net Pin
Zar Ni27-Oct-09 21:05
Zar Ni27-Oct-09 21:05 
AnswerRe: How to select multiple objects using mouse? C# .Net Pin
Richard MacCutchan27-Oct-09 22:11
mveRichard MacCutchan27-Oct-09 22:11 
AnswerRe: How to select multiple objects using mouse? C# .Net Pin
freakyit27-Oct-09 22:20
freakyit27-Oct-09 22:20 
QuestionCalling WPF pages in VC++ Pin
kDevloper27-Oct-09 18:37
kDevloper27-Oct-09 18:37 
Questionvb.net handles clause requires a withevents variable Pin
User 540919027-Oct-09 11:12
User 540919027-Oct-09 11:12 
QuestionCLR Profiler - too many objects??? Pin
Member 332970027-Oct-09 8:12
Member 332970027-Oct-09 8:12 
AnswerRe: CLR Profiler - too many objects??? Pin
Member 332970027-Oct-09 22:54
Member 332970027-Oct-09 22:54 
QuestionGDI+ drawing - invalidate big rectangle in one user control then invalidate another user control (problem with big rectangle) [modified] Pin
rudozkv_new27-Oct-09 8:11
rudozkv_new27-Oct-09 8:11 
Hi,
First of all I found lot of article about this. Iam trying to solve it about few days without results.

I work on aplication, which should be something like report editor for printing.
I have a form with two scroll bars, grid and two rulers. Rulers and grid are User Controls.
For both controls I call:
Me.SetStyle(ControlStyles.AllPaintingInWmPaint + ControlStyles.UserPaint + ControlStyles.Opaque _
                    + ControlStyles.OptimizedDoubleBuffer, True)
        UpdateStyles()
befor drawing.

The grid drawing function:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim rcPaper = New Rectangle(nGrid * nPaperOffset, nGrid * nPaperOffset, _
                                     nPaperWidth, _
                                     nPaperHeight)
        Dim bmp As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
        Dim graph As Graphics
        graph = Graphics.FromImage(bmp)
        ' Draw paper
        rcPaper.Location = rcPaper.Location + ptScrollOffset
        graph.Clear(Color.DarkGray)
        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 nGrid
                For y As Integer = 0 To bmp.Height Step nGrid
                    graph.DrawLine(m_PenGrid, x, y, x + 0.5F, y + 0.5F)
                Next y
            Next x
        End If
        e.Graphics.DrawImage(bmp, 0, 0)
        ' Free object added
        bmp.Dispose()
        graph.Dispose()
        Debug.Print("Grid:OnPaint")
    End Sub
Ruler draw function:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        'MyBase.OnPaint(e)
        Dim bmp As New Bitmap(Me.Width, Me.Height)
        Dim graph As Graphics
        graph = Graphics.FromImage(bmp)
        graph.Clear(Color.White)

        Dim rStRect As SizeF
        Dim pOrigin As New PointF
        Dim string_format As New StringFormat

        If eStyle = ERulerStyle.rHorizontal Then
            ' Horizontal ruler
            Dim y1 As Integer = Me.ClientSize.Height
            Dim y2 As Integer = (2 * Me.ClientSize.Height) \ 3
            Dim y3 As Integer = Me.ClientSize.Height \ 3
            Dim y4 As Integer = 0
            Dim x As Integer = 0
            For i As Integer = 0 To Me.ClientSize.Width \ nGrid
                If (i + nPaperOffset) Mod nStepsPerUnit = 0 Then
                    'If i > 0 Then
                    pOrigin.X = x
                    pOrigin.Y = y4
                    string_format.Alignment = StringAlignment.Center
                    rStRect = graph.MeasureString(CStr((i - nPaperOffset) / nStepsPerUnit), dFont, pOrigin, string_format)
                    graph.DrawString(CStr((i - nPaperOffset) / nStepsPerUnit), dFont, dBrush, _
                                          x - rStRect.Width / 2 + 1 + ptScrollOffset.X, _
                                          y4 + ptScrollOffset.Y)
                ElseIf (i + nPaperOffset) Mod (nStepsPerUnit / 2) = 0 Then
                    graph.DrawLine(m_PenGrid, x + ptScrollOffset.X, y1 + ptScrollOffset.Y, _
                                        x + ptScrollOffset.X, y3 + ptScrollOffset.Y)
                ElseIf (i + nPaperOffset) Mod (nStepsPerUnit / nTicksNum) = 0 Then
                    graph.DrawLine(m_PenGrid, x + ptScrollOffset.X, y1 + ptScrollOffset.Y, _
                                        x + ptScrollOffset.X, y2 + ptScrollOffset.Y)
                End If
                x += nGrid
            Next i

            ' Show the mouse position.
            If bSelecting Then
                graph.DrawLine(m_PenRulerDrawing, nX, y1, nX, 0)
            Else
                graph.DrawLine(m_PenRulerNormal, nX, y1, nX, 0)
            End If
        Else
            ' Vertical ruler
            Dim x1 As Integer = Me.ClientSize.Width
            Dim x2 As Integer = (2 * Me.ClientSize.Width) \ 3
            Dim x3 As Integer = Me.ClientSize.Width \ 3
            Dim x4 As Integer = 0
            Dim y As Integer = 0
            For i As Integer = 0 To Me.ClientSize.Height \ nGrid
                If (i + nPaperOffset) Mod nStepsPerUnit = 0 Then
                    If i > 0 Then
                        pOrigin.X = x4
                        pOrigin.Y = y
                        string_format.Alignment = StringAlignment.Center
                        rStRect = graph.MeasureString(CStr((i - nPaperOffset) / nStepsPerUnit), dFont, pOrigin, string_format)
                        graph.DrawString(CStr((i - nPaperOffset) / nStepsPerUnit), dFont, _
                                              dBrush, x4 + (nWidth - rStRect.Width) / 2 - 2 + ptScrollOffset.X, _
                                              y - rStRect.Height / 2 + ptScrollOffset.Y)
                        'e.Graphics.DrawLine(m_PenGrid, x1, y, x4, y)
                    End If
                ElseIf (i + nPaperOffset) Mod (nStepsPerUnit / 2) = 0 Then
                    graph.DrawLine(m_PenGrid, x1 + ptScrollOffset.X, y + ptScrollOffset.Y, _
                                        x3 + ptScrollOffset.X, y + ptScrollOffset.Y)
                ElseIf (i + nPaperOffset) Mod (nStepsPerUnit / nTicksNum) = 0 Then
                    graph.DrawLine(m_PenGrid, x1 + ptScrollOffset.X, y + ptScrollOffset.Y, _
                                        x2 + ptScrollOffset.X, y + ptScrollOffset.Y)
                End If
                y += nGrid
            Next i

            ' Show the mouse position.
            If bSelecting Then
                graph.DrawLine(m_PenRulerDrawing, x1, nY, x4, nY)
            Else
                graph.DrawLine(m_PenRulerNormal, x1, nY, x4, nY)
            End If
        End If
        e.Graphics.DrawImage(bmp, 0, 0, Me.ClientSize.Width, Me.ClientSize.Height)
        ' Free object added
        bmp.Dispose()
        graph.Dispose()
        Debug.Print("Scroll:OnPaint")
    End Sub
I handle scroll event like this:
Private Sub OnVScroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles VScrollBar1.Scroll
        ctrlVRuler.ScrollRuller(, e.NewValue)
        'Debug.Print("Call ctrlVRuler.Invalidate")
        'ctrlVRuler.Invalidate()
        ctrlMyGrid.ScrollPaper(, e.NewValue)
        'Debug.Print("Call ctrlMyGrid.Invalidate")
        'ctrlMyGrid.Invalidate()
        ' Invalidate "parent" control
        Invalidate(true)
    End Sub

Then while I am running appliation and scrolling I get this text in Inmediate window:

Grid:OnPaint
Scroll:OnPaint
Grid:OnPaint
Scroll:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Scroll:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Scroll:OnPaint

The candency of Grid repaint is rapidly bigger.
I am quit sure I call redraw (invalidate) just from scroll event during scrolling.

What do you think about this? How can I tell GDI+ to finish one controls re-drawing and then start other?

modified on Wednesday, October 28, 2009 4:10 AM

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 
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 

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.