Newbie Paint Question

J

Jon

Hi all,

I am working on a DataGridView that has "merged cells" using a rectangle
placed in a paint routine.
code follows:

Private Sub dgvWalls_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles dgvWalls.Paint

Dim fnt As New Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point)

'setup variables for vertical cells

Dim sdp As System.Drawing.Point '

Dim sds As System.Drawing.Size

Dim str As String

Dim lefts, tops, i, x As Integer

Dim strlen As SizeF

For i = 0 To dgvWalls.RowCount - 1

Dim rct(i) As Rectangle

dgvWalls.CurrentCell = dgvWalls(0, i) 'select first cell

If dgvWalls.CurrentCell.Value <> "" Then 'no string then skip it

str = dgvWalls.CurrentCell.Value.ToString ' put the text in a string

strlen = e.Graphics.MeasureString(str, dgvWalls.Font) ' set string length

sdp.X = dgvWalls.GetRowDisplayRectangle(i, True).X +
dgvWalls.RowHeadersWidth

sdp.Y = dgvWalls.GetRowDisplayRectangle(i, True).Y

sds.Height = dgvWalls.GetRowDisplayRectangle(i, True).Height - 1 ' subtract
1 to show line

x = dgvWalls.Columns(0).Width + dgvWalls.Columns(1).Width

sds.Width = x - 1 ' subtract 1 to show line

rct(i).Location = sdp

rct(i).Size = sds

lefts = (rct(i).Width / 2) - (strlen.Width / 2)

tops = rct(i).Top + ((rct(i).Height / 2) - (strlen.Height / 2))

e.Graphics.FillRectangle(Brushes.White, rct(i)) 'Merge 2 cells

e.Graphics.DrawString(str, fnt, Brushes.Black, lefts, tops)

Else

End If

Next


End Sub

______________________

Routine works fabulous except the paint routine seems to go into a loop.
Can you see my error. For the life of me I can't.



Thanks
 
G

Guest

well, how did you find out its in a loop? because the paint event is raised
whenever the control is told to repaint by windows. are u stepping though the
code?
 
C

Cor Ligthert [MVP]

Jon,

A suggestion as you next time show code, than first copy it in a notebook.
Copy it back again and than paste it in a message. Than it becomes readable
for us.

Cor
 
J

Jon

Sorry..

I yanked the whole concept out...

.... a bit of creeping elegence, I'm afraid.

My original question was how do you suspend the calls to the paint routine
until after you have done a number of things (over 50) that require a
repaint. Is that possible or do you have to wait for a repaint ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top