|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie Paint QuestionI 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 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? -- -iwdu15 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 Show quoteHide quote "Jon" <jon_ol***@msn.com> schreef in bericht news:%23$wvdzn5GHA.1248@TK2MSFTNGP03.phx.gbl... > 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 > > 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 ? Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:OSWQyup5GHA.1252@TK2MSFTNGP04.phx.gbl... > 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 > > "Jon" <jon_ol***@msn.com> schreef in bericht > news:%23$wvdzn5GHA.1248@TK2MSFTNGP03.phx.gbl... >> 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 >> >> > >
MDI Min Max - still there
Q: closing forms da.update bool--> yes/no RuntimeHelpers.GetObjectValue Discussion Re: Reading a list of users from XP Writing Custom DLLs in VB.net 2 Accessing the Class Name of a Shared Method copy and paste into webbrowser VS 2005: Forms Designer Clears CancelButton and AcceptButton on Compile use try catch to check a text box |
|||||||||||||||||||||||