form draw problem

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

Hello,
I have a form in which I draw a grid in the paint event. Works fine, except
when using the scrollbars.
Autoscroll is switched on, I use doublebuffering and userpaint and
AllPaintingInWmPaint are true.
When using the scrollbars sometimes some lines are not drawn or drawn twice.
The gridlines distort in the scrolled region.
As far as I can tell the clipregion is the whole window, so that can't be
it. Besides, it only goes wrong when sliding the bars, not when I click next
to the bars and the whole windowcontents reposition.
What could be the reason? Is there some setting I have to adjust?
Please advice
Thanks
Frank
 
Frank said:
Hello,
I have a form in which I draw a grid in the paint event. Works fine, except
when using the scrollbars.
Autoscroll is switched on, I use doublebuffering and userpaint and
AllPaintingInWmPaint are true.
When using the scrollbars sometimes some lines are not drawn or drawn twice.
The gridlines distort in the scrolled region.
As far as I can tell the clipregion is the whole window, so that can't be
it. Besides, it only goes wrong when sliding the bars, not when I click next
to the bars and the whole windowcontents reposition.
What could be the reason? Is there some setting I have to adjust?


This is the type of problem where a small demo to reproduce the problem
would be a big help. While it may be trivial to draw a grid we can't know
exactly what you are using to do the job, unless you show your work....

LFS
 
Larry Serflaten said:
This is the type of problem where a small demo to reproduce the problem
would be a big help. While it may be trivial to draw a grid we can't know
exactly what you are using to do the job, unless you show your work....

LFS

This is it, remember it works fine, just when sliding the bars I get
distorted lines
Dim pen As New Pen(Color.Black)

For xMM = CSng(startingpointPixel) To Me.Width Step roomPixel

e.Graphics.DrawLine(pen, xMM, 0, xMM, Me.Height)

Next

For yMM = CSng(startingpoint2Pixel) To 0 Step -roomPixel

e.Graphics.DrawLine(pen, 0, yMM, Me.Width, yMM)

Next
 
Frank said:
This is it, remember it works fine, just when sliding the bars I get distorted lines
Dim pen As New Pen(Color.Black)
For xMM = CSng(startingpointPixel) To Me.Width Step roomPixel
e.Graphics.DrawLine(pen, xMM, 0, xMM, Me.Height)
Next

For yMM = CSng(startingpoint2Pixel) To 0 Step -roomPixel
e.Graphics.DrawLine(pen, 0, yMM, Me.Width, yMM)
Next


That won't even compile over here, the starting points are not defined.
Reproduce the problem in a small demo, and post that code.

LFS
 
Larry, below the very simple code. If you resize the window by moving the
lowerright corner you will notice distortion of the lines. Also moving the
bars gives problems. I hope (pray) that you can help.

Thanks

Frank

Option Strict On

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Label1 As System.Windows.Forms.Label

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.Label1 = New System.Windows.Forms.Label()

Me.SuspendLayout()

'

'Label1

'

Me.Label1.Location = New System.Drawing.Point(216, 224)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(56, 24)

Me.Label1.TabIndex = 0

Me.Label1.Text = "Label1"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 266)

Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1})

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.AutoScroll = True

Me.SetStyle(ControlStyles.UserPaint, True)

Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)

Me.SetStyle(ControlStyles.DoubleBuffer, True)

End Sub

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

Dim xmm As Single

Dim ymm As Single

Dim pen As New Pen(Color.Black)

For xmm = CSng(1) To Me.Width Step 40

e.Graphics.DrawLine(pen, xmm, 0, xmm, Me.Height)

Next

For ymm = CSng(Me.height) To 0 Step -40

e.Graphics.DrawLine(pen, 0, ymm, Me.Width, ymm)

Next

End Sub

End Class
 
Hi,
I partly solved the problem by not drawing the horizontal lines from below
to top, but the other way around.
Leaves the problem when using the scrollbars which produces a lot of extra
lines.
Frank
 
Frank said:
Larry, below the very simple code.

Apparently the client chages size as you scroll, so base
your lines off of something that is relatively constant
in respect to the changing client. In this case that is
the label:

For xmm = Label1.Left - 300 To Me.Width Step 40
e.Graphics.DrawLine(pen, xmm, 0, xmm, Me.Height)
Next

For ymm = Label1.Top To 0 Step -40
e.Graphics.DrawLine(pen, 0, ymm, Me.Width, ymm)
Next


That isn't a full solution (it stops at the label) but you can see
the lines appear constant, in respect to the label....

LFS

LFS
 
Great! Thanks Larry.
Frank

Larry Serflaten said:
Apparently the client chages size as you scroll, so base
your lines off of something that is relatively constant
in respect to the changing client. In this case that is
the label:

For xmm = Label1.Left - 300 To Me.Width Step 40
e.Graphics.DrawLine(pen, xmm, 0, xmm, Me.Height)
Next

For ymm = Label1.Top To 0 Step -40
e.Graphics.DrawLine(pen, 0, ymm, Me.Width, ymm)
Next


That isn't a full solution (it stops at the label) but you can see
the lines appear constant, in respect to the label....

LFS

LFS
 

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

Back
Top