473,383 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Please help, more scrollbar questions. CODE INCLUDED.

I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether the
user autoscrolls the usercontrol (other things that are on the
usercontrol I want to scroll, but haven't included any here).

Here are the steps to reproduce my problem.

1. Launch Visual Studio and create a new Windows
application with "Form1".
2. Paste the following in (remember to include
your "Windows Form Designer generated code).
3. Run - instructions are in the program that runs.

I am using "Microsoft Development Environment 2003, Version 7.1.3088".
I am using "Microsoft .NET Framework 1.1, Version 1.1.4322"

Thank you for your patience with me.
Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class
Nov 20 '05 #1
22 2322
What happens then ?
Colin McGuire wrote:
I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether the
user autoscrolls the usercontrol (other things that are on the
usercontrol I want to scroll, but haven't included any here).

Here are the steps to reproduce my problem.

1. Launch Visual Studio and create a new Windows
application with "Form1".
2. Paste the following in (remember to include
your "Windows Form Designer generated code).
3. Run - instructions are in the program that runs.

I am using "Microsoft Development Environment 2003, Version 7.1.3088".
I am using "Microsoft .NET Framework 1.1, Version 1.1.4322"

Thank you for your patience with me.
Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class

Nov 20 '05 #2
You're not going to make me thank you again I hope :)

Here is some more elaboration of my problem.

What I see is:

1. When I move the vertical scrollbar by clicking "in"
the scrollbar (ie between the up arrow and down arrow),
the diagonal line is drawn properly (diagram below).

+----------+
|\ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
+----------+

2. When I click the "down arrow" button on the vertical
scrollbar, the diagonal scrolls, but I can see a tiny
bit of the new diagonal showing up - sort of looks like

+---\-------+
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
| |
| |
| \|
+-----------+

3. When I add a Debug.WriteLine("OnPaint") inside
the OnPaint method, both clicking "in" the scrollbar
and clicking the up or down arrow of the scrollbar
appear produce "OnPaint" in the IDE debug window.

4. When I minimise this (corrupted window, step 2), then
maximize it again, then it redraws properly with
the diagonal from (0,0) to (width,height) as shown
in Step 1.

BTW: I forgot to paste in the

p.Graphics.Clear(BackColor)

in my original post before the
p.Graphics.DrawLine .... but
it doesn't make any difference if I do.

Thank you
Colin


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
What happens then ?
Colin McGuire wrote:
I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether the
user autoscrolls the usercontrol (other things that are on the
usercontrol I want to scroll, but haven't included any here).

Here are the steps to reproduce my problem.

1. Launch Visual Studio and create a new Windows
application with "Form1".
2. Paste the following in (remember to include
your "Windows Form Designer generated code).
3. Run - instructions are in the program that runs.

I am using "Microsoft Development Environment 2003, Version 7.1.3088".
I am using "Microsoft .NET Framework 1.1, Version 1.1.4322"

Thank you for your patience with me.
Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class



Nov 20 '05 #3
You need to repaint on VScroll. Your user control inherits from Scrollable
class and this event is protected so as you have inherited this you should
be able to add a handler and force the control to repaint.


Colin McGuire wrote:
You're not going to make me thank you again I hope :)

Here is some more elaboration of my problem.

What I see is:

1. When I move the vertical scrollbar by clicking "in"
the scrollbar (ie between the up arrow and down arrow),
the diagonal line is drawn properly (diagram below).

+----------+
|\ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
+----------+

2. When I click the "down arrow" button on the vertical
scrollbar, the diagonal scrolls, but I can see a tiny
bit of the new diagonal showing up - sort of looks like

+---\-------+
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
| |
| |
| \|
+-----------+

3. When I add a Debug.WriteLine("OnPaint") inside
the OnPaint method, both clicking "in" the scrollbar
and clicking the up or down arrow of the scrollbar
appear produce "OnPaint" in the IDE debug window.

4. When I minimise this (corrupted window, step 2), then
maximize it again, then it redraws properly with
the diagonal from (0,0) to (width,height) as shown
in Step 1.

BTW: I forgot to paste in the

p.Graphics.Clear(BackColor)

in my original post before the
p.Graphics.DrawLine .... but
it doesn't make any difference if I do.

Thank you
Colin


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
What happens then ?
Colin McGuire wrote:
I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether the
user autoscrolls the usercontrol (other things that are on the
usercontrol I want to scroll, but haven't included any here).

Here are the steps to reproduce my problem.

1. Launch Visual Studio and create a new Windows
application with "Form1".
2. Paste the following in (remember to include
your "Windows Form Designer generated code).
3. Run - instructions are in the program that runs.

I am using "Microsoft Development Environment 2003, Version
7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
1.1.4322"

Thank you for your patience with me.
Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As
System.Object, _ ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" +
_ " drawn from(0,0) to (width,height).
2.Minimize" + _ " this form. 3. Restore the form
size,now the " + _ "line does go from (0,0) to
(width,height). " + _ "Why, why isn't the
diagonal line and " + _ "control background
cleared as you scroll?" Me.Controls.Add(lb)
End Sub
End Class

Nov 20 '05 #4
OHM, I am sorry - I have seen this mentioned before and have never
understood it. I know I'm close and the cigar eludes me. Any chance of
coaching me on just a little further?
Here is what I think what you mean from your latest post, and as I have
implemented it is wrong because I get an a box showing up in my IDE saying
"'VScroll' is not an event of WindowsApplication15.Form1.UserControl1'".

What I did to my original code was

Step 1: Added the following to UserControl1_Load

AddHandler VScroll, AddressOf capturedVScroll

Step 2: Added the following to the code in UserControl1

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub
My final code therefore looks like this, but just one more tweak is
necessary before I can get it to compile and work.

Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.Clear(BackColor)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
AddHandler VScroll, AddressOf capturedVScroll 'ERROR HERE
End Sub

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub

End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
You need to repaint on VScroll. Your user control inherits from Scrollable class and this event is protected so as you have inherited this you should
be able to add a handler and force the control to repaint.


Colin McGuire wrote:
You're not going to make me thank you again I hope :)

Here is some more elaboration of my problem.

What I see is:

1. When I move the vertical scrollbar by clicking "in"
the scrollbar (ie between the up arrow and down arrow),
the diagonal line is drawn properly (diagram below).

+----------+
|\ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
+----------+

2. When I click the "down arrow" button on the vertical
scrollbar, the diagonal scrolls, but I can see a tiny
bit of the new diagonal showing up - sort of looks like

+---\-------+
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
| |
| |
| \|
+-----------+

3. When I add a Debug.WriteLine("OnPaint") inside
the OnPaint method, both clicking "in" the scrollbar
and clicking the up or down arrow of the scrollbar
appear produce "OnPaint" in the IDE debug window.

4. When I minimise this (corrupted window, step 2), then
maximize it again, then it redraws properly with
the diagonal from (0,0) to (width,height) as shown
in Step 1.

BTW: I forgot to paste in the

p.Graphics.Clear(BackColor)

in my original post before the
p.Graphics.DrawLine .... but
it doesn't make any difference if I do.

Thank you
Colin


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
What happens then ?
Colin McGuire wrote:
I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether the
user autoscrolls the usercontrol (other things that are on the
usercontrol I want to scroll, but haven't included any here).

Here are the steps to reproduce my problem.

1. Launch Visual Studio and create a new Windows
application with "Form1".
2. Paste the following in (remember to include
your "Windows Form Designer generated code).
3. Run - instructions are in the program that runs.

I am using "Microsoft Development Environment 2003, Version
7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
1.1.4322"

Thank you for your patience with me.
Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As
System.Object, _ ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" +
_ " drawn from(0,0) to (width,height).
2.Minimize" + _ " this form. 3. Restore the form
size,now the " + _ "line does go from (0,0) to
(width,height). " + _ "Why, why isn't the
diagonal line and " + _ "control background
cleared as you scroll?" Me.Controls.Add(lb)
End Sub
End Class



Nov 20 '05 #5
Actually, I was wrong. It is not an event. However, logic tells us that an
event has taken place because otherwise it could not have scrolled.

I suggest you post this exact question as a new thread and this will get you
your answer. I dont know it at present.

Colin McGuire wrote:
OHM, I am sorry - I have seen this mentioned before and have never
understood it. I know I'm close and the cigar eludes me. Any chance of
coaching me on just a little further?
Here is what I think what you mean from your latest post, and as I
have implemented it is wrong because I get an a box showing up in my
IDE saying "'VScroll' is not an event of
WindowsApplication15.Form1.UserControl1'".

What I did to my original code was

Step 1: Added the following to UserControl1_Load

AddHandler VScroll, AddressOf capturedVScroll

Step 2: Added the following to the code in UserControl1

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub
My final code therefore looks like this, but just one more tweak is
necessary before I can get it to compile and work.

Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.Clear(BackColor)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
AddHandler VScroll, AddressOf capturedVScroll 'ERROR HERE
End Sub

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub

End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
You need to repaint on VScroll. Your user control inherits from
Scrollable class and this event is protected so as you have
inherited this you should be able to add a handler and force the
control to repaint.


Colin McGuire wrote:
You're not going to make me thank you again I hope :)

Here is some more elaboration of my problem.

What I see is:

1. When I move the vertical scrollbar by clicking "in"
the scrollbar (ie between the up arrow and down arrow),
the diagonal line is drawn properly (diagram below).

+----------+
|\ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
+----------+

2. When I click the "down arrow" button on the vertical
scrollbar, the diagonal scrolls, but I can see a tiny
bit of the new diagonal showing up - sort of looks like

+---\-------+
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
| |
| |
| \|
+-----------+

3. When I add a Debug.WriteLine("OnPaint") inside
the OnPaint method, both clicking "in" the scrollbar
and clicking the up or down arrow of the scrollbar
appear produce "OnPaint" in the IDE debug window.

4. When I minimise this (corrupted window, step 2), then
maximize it again, then it redraws properly with
the diagonal from (0,0) to (width,height) as shown
in Step 1.

BTW: I forgot to paste in the

p.Graphics.Clear(BackColor)

in my original post before the
p.Graphics.DrawLine .... but
it doesn't make any difference if I do.

Thank you
Colin


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
What happens then ?
Colin McGuire wrote:
> I apologize for posting yet another scrollbar question. Here is my
> code. All I want is for a diagonal line to appear from coordinates
> (0,0) to (width,height) in a usercontrol regardless of whether the
> user autoscrolls the usercontrol (other things that are on the
> usercontrol I want to scroll, but haven't included any here).
>
> Here are the steps to reproduce my problem.
>
> 1. Launch Visual Studio and create a new Windows
> application with "Form1".
> 2. Paste the following in (remember to include
> your "Windows Form Designer generated code).
> 3. Run - instructions are in the program that runs.
>
> I am using "Microsoft Development Environment 2003, Version
> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
> 1.1.4322"
>
> Thank you for your patience with me.
> Colin
>
>
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
>
> '======================
> ' Windows Form Designer generated code
> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
> '======================
>
> Public Class UserControl1
> Inherits System.Windows.Forms.UserControl
> Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
> MyBase.OnPaint(p)
> p.Graphics.DrawLine(New Pen(Color.Black), _
> clientRectangle.Width, _
> ClientRectangle.Height, _
> 0, 0)
> End Sub
>
> Private Sub UserControl1_Load(ByVal sender As
> System.Object, _ ByVal e As System.EventArgs) _
> Handles MyBase.Load
> Me.BackColor = Color.Yellow
> End Sub
> End Class
>
>
> Private Sub Form1_Load(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim uc As New UserControl1
> uc.Location = New Point(0, 0)
> uc.Size = New System.Drawing.Size(New Point(100, 100))
> uc.BackColor = Color.Yellow
> uc.AutoScroll = True
> uc.AutoScrollMinSize = New Size(New Point(200, 300))
> uc.Visible = True
> Me.Controls.Add(uc)
> Size = New Size(New Point(300, 300))
>
> Dim lb As New Label
> lb.Location = New Point(0, 150)
> lb.Size = New Size(290, 80)
> lb.Text = "1.Move the scrollbars,the diagonal line isn't"
> + _ " drawn from(0,0) to (width,height).
> 2.Minimize" + _ " this form. 3. Restore the form
> size,now the " + _ "line does go from (0,0) to
> (width,height). " + _ "Why, why isn't the
> diagonal line and " + _ "control background
> cleared as you scroll?" Me.Controls.Add(lb)
> End Sub
> End Class

Nov 20 '05 #6
Paste the following code into UserControl1
Hexathioorthooxalate
'Putting a Debug.WriteLine(m.ToString) in the subroutine below
'shows that the order that messages are received/processed is
'WM_PAINT and then WM_XSCROLL. The usercontrol appears to be
'being painted first, and then scrolled, and this is why you
'are not seeing the diagonal. This code will ensure that
'after a scroll, a repaint (through Invalidate()) will
'occur - messy and probably overkill but I cannot currently
'see another way around your dilemma.

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
End Sub


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
Actually, I was wrong. It is not an event. However, logic tells us that an
event has taken place because otherwise it could not have scrolled.

I suggest you post this exact question as a new thread and this will get you your answer. I dont know it at present.

Colin McGuire wrote:
OHM, I am sorry - I have seen this mentioned before and have never
understood it. I know I'm close and the cigar eludes me. Any chance of
coaching me on just a little further?
Here is what I think what you mean from your latest post, and as I
have implemented it is wrong because I get an a box showing up in my
IDE saying "'VScroll' is not an event of
WindowsApplication15.Form1.UserControl1'".

What I did to my original code was

Step 1: Added the following to UserControl1_Load

AddHandler VScroll, AddressOf capturedVScroll

Step 2: Added the following to the code in UserControl1

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub
My final code therefore looks like this, but just one more tweak is
necessary before I can get it to compile and work.

Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.Clear(BackColor)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
AddHandler VScroll, AddressOf capturedVScroll 'ERROR HERE
End Sub

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub

End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
You need to repaint on VScroll. Your user control inherits from
Scrollable class and this event is protected so as you have
inherited this you should be able to add a handler and force the
control to repaint.


Colin McGuire wrote:
You're not going to make me thank you again I hope :)

Here is some more elaboration of my problem.

What I see is:

1. When I move the vertical scrollbar by clicking "in"
the scrollbar (ie between the up arrow and down arrow),
the diagonal line is drawn properly (diagram below).

+----------+
|\ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
+----------+

2. When I click the "down arrow" button on the vertical
scrollbar, the diagonal scrolls, but I can see a tiny
bit of the new diagonal showing up - sort of looks like

+---\-------+
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
| |
| |
| \|
+-----------+

3. When I add a Debug.WriteLine("OnPaint") inside
the OnPaint method, both clicking "in" the scrollbar
and clicking the up or down arrow of the scrollbar
appear produce "OnPaint" in the IDE debug window.

4. When I minimise this (corrupted window, step 2), then
maximize it again, then it redraws properly with
the diagonal from (0,0) to (width,height) as shown
in Step 1.

BTW: I forgot to paste in the

p.Graphics.Clear(BackColor)

in my original post before the
p.Graphics.DrawLine .... but
it doesn't make any difference if I do.

Thank you
Colin


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
> What happens then ?
>
>
> Colin McGuire wrote:
>> I apologize for posting yet another scrollbar question. Here is my
>> code. All I want is for a diagonal line to appear from coordinates
>> (0,0) to (width,height) in a usercontrol regardless of whether the
>> user autoscrolls the usercontrol (other things that are on the
>> usercontrol I want to scroll, but haven't included any here).
>>
>> Here are the steps to reproduce my problem.
>>
>> 1. Launch Visual Studio and create a new Windows
>> application with "Form1".
>> 2. Paste the following in (remember to include
>> your "Windows Form Designer generated code).
>> 3. Run - instructions are in the program that runs.
>>
>> I am using "Microsoft Development Environment 2003, Version
>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>> 1.1.4322"
>>
>> Thank you for your patience with me.
>> Colin
>>
>>
>>
>> Public Class Form1
>> Inherits System.Windows.Forms.Form
>>
>> '======================
>> ' Windows Form Designer generated code
>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>> '======================
>>
>> Public Class UserControl1
>> Inherits System.Windows.Forms.UserControl
>> Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
>> MyBase.OnPaint(p)
>> p.Graphics.DrawLine(New Pen(Color.Black), _
>> clientRectangle.Width, _
>> ClientRectangle.Height, _
>> 0, 0)
>> End Sub
>>
>> Private Sub UserControl1_Load(ByVal sender As
>> System.Object, _ ByVal e As System.EventArgs) _
>> Handles MyBase.Load
>> Me.BackColor = Color.Yellow
>> End Sub
>> End Class
>>
>>
>> Private Sub Form1_Load(ByVal sender As System.Object, _
>> ByVal e As System.EventArgs) Handles MyBase.Load
>> Dim uc As New UserControl1
>> uc.Location = New Point(0, 0)
>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>> uc.BackColor = Color.Yellow
>> uc.AutoScroll = True
>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>> uc.Visible = True
>> Me.Controls.Add(uc)
>> Size = New Size(New Point(300, 300))
>>
>> Dim lb As New Label
>> lb.Location = New Point(0, 150)
>> lb.Size = New Size(290, 80)
>> lb.Text = "1.Move the scrollbars,the diagonal line isn't"
>> + _ " drawn from(0,0) to (width,height).
>> 2.Minimize" + _ " this form. 3. Restore the form
>> size,now the " + _ "line does go from (0,0) to
>> (width,height). " + _ "Why, why isn't the
>> diagonal line and " + _ "control background
>> cleared as you scroll?" Me.Controls.Add(lb)
>> End Sub
>> End Class



Nov 20 '05 #7
This is not a workable solution. The reason being that once you invalidate ,
it causes a paint event, which causes . . . . Flashing forms, lines etc

Recursive.

OHM
hexathioorthooxalate wrote:
Paste the following code into UserControl1
Hexathioorthooxalate
'Putting a Debug.WriteLine(m.ToString) in the subroutine below
'shows that the order that messages are received/processed is
'WM_PAINT and then WM_XSCROLL. The usercontrol appears to be
'being painted first, and then scrolled, and this is why you
'are not seeing the diagonal. This code will ensure that
'after a scroll, a repaint (through Invalidate()) will
'occur - messy and probably overkill but I cannot currently
'see another way around your dilemma.

Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message) MyBase.WndProc(m)
'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
End Sub


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
Actually, I was wrong. It is not an event. However, logic tells us
that an event has taken place because otherwise it could not have
scrolled.

I suggest you post this exact question as a new thread and this will
get you your answer. I dont know it at present.

Colin McGuire wrote:
OHM, I am sorry - I have seen this mentioned before and have never
understood it. I know I'm close and the cigar eludes me. Any chance
of coaching me on just a little further?
Here is what I think what you mean from your latest post, and as I
have implemented it is wrong because I get an a box showing up in my
IDE saying "'VScroll' is not an event of
WindowsApplication15.Form1.UserControl1'".

What I did to my original code was

Step 1: Added the following to UserControl1_Load

AddHandler VScroll, AddressOf capturedVScroll

Step 2: Added the following to the code in UserControl1

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub
My final code therefore looks like this, but just one more tweak is
necessary before I can get it to compile and work.

Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.Clear(BackColor)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As
System.Object, _ ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
AddHandler VScroll, AddressOf capturedVScroll 'ERROR
HERE End Sub

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub

End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" +
_ " drawn from(0,0) to (width,height).
2.Minimize" + _ " this form. 3. Restore the form
size,now the " + _ "line does go from (0,0) to
(width,height). " + _ "Why, why isn't the
diagonal line and " + _ "control background
cleared as you scroll?" Me.Controls.Add(lb)
End Sub
End Class

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
You need to repaint on VScroll. Your user control inherits from
Scrollable class and this event is protected so as you have
inherited this you should be able to add a handler and force the
control to repaint.


Colin McGuire wrote:
> You're not going to make me thank you again I hope :)
>
> Here is some more elaboration of my problem.
>
> What I see is:
>
> 1. When I move the vertical scrollbar by clicking "in"
> the scrollbar (ie between the up arrow and down arrow),
> the diagonal line is drawn properly (diagram below).
>
> +----------+
> |\ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \|
> +----------+
>
> 2. When I click the "down arrow" button on the vertical
> scrollbar, the diagonal scrolls, but I can see a tiny
> bit of the new diagonal showing up - sort of looks like
>
> +---\-------+
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \|
> | |
> | |
> | \|
> +-----------+
>
> 3. When I add a Debug.WriteLine("OnPaint") inside
> the OnPaint method, both clicking "in" the scrollbar
> and clicking the up or down arrow of the scrollbar
> appear produce "OnPaint" in the IDE debug window.
>
> 4. When I minimise this (corrupted window, step 2), then
> maximize it again, then it redraws properly with
> the diagonal from (0,0) to (width,height) as shown
> in Step 1.
>
> BTW: I forgot to paste in the
>
> p.Graphics.Clear(BackColor)
>
> in my original post before the
> p.Graphics.DrawLine .... but
> it doesn't make any difference if I do.
>
> Thank you
> Colin
>
>
>
>
>
>
> "One Handed Man" <Bo****@Duck.net> wrote in message
> news:bl**********@hercules.btinternet.com...
>> What happens then ?
>>
>>
>> Colin McGuire wrote:
>>> I apologize for posting yet another scrollbar question. Here is
>>> my code. All I want is for a diagonal line to appear from
>>> coordinates (0,0) to (width,height) in a usercontrol regardless
>>> of whether the user autoscrolls the usercontrol (other things
>>> that are on the usercontrol I want to scroll, but haven't
>>> included any here).
>>>
>>> Here are the steps to reproduce my problem.
>>>
>>> 1. Launch Visual Studio and create a new Windows
>>> application with "Form1".
>>> 2. Paste the following in (remember to include
>>> your "Windows Form Designer generated code).
>>> 3. Run - instructions are in the program that runs.
>>>
>>> I am using "Microsoft Development Environment 2003, Version
>>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>>> 1.1.4322"
>>>
>>> Thank you for your patience with me.
>>> Colin
>>>
>>>
>>>
>>> Public Class Form1
>>> Inherits System.Windows.Forms.Form
>>>
>>> '======================
>>> ' Windows Form Designer generated code
>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>> '======================
>>>
>>> Public Class UserControl1
>>> Inherits System.Windows.Forms.UserControl
>>> Protected Overrides Sub OnPaint(ByVal p As
>>> PaintEventArgs) MyBase.OnPaint(p)
>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>> clientRectangle.Width, _
>>> ClientRectangle.Height, _
>>> 0, 0)
>>> End Sub
>>>
>>> Private Sub UserControl1_Load(ByVal sender As
>>> System.Object, _ ByVal e As System.EventArgs) _
>>> Handles MyBase.Load
>>> Me.BackColor = Color.Yellow
>>> End Sub
>>> End Class
>>>
>>>
>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>> Dim uc As New UserControl1
>>> uc.Location = New Point(0, 0)
>>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>>> uc.BackColor = Color.Yellow
>>> uc.AutoScroll = True
>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>> uc.Visible = True
>>> Me.Controls.Add(uc)
>>> Size = New Size(New Point(300, 300))
>>>
>>> Dim lb As New Label
>>> lb.Location = New Point(0, 150)
>>> lb.Size = New Size(290, 80)
>>> lb.Text = "1.Move the scrollbars,the diagonal line
>>> isn't" + _ " drawn from(0,0) to
>>> (width,height).
>>> 2.Minimize" + _ " this form. 3. Restore the
>>> form size,now the " + _ "line does go from
>>> (0,0) to (width,height). " + _ "Why, why
>>> isn't the diagonal line and " + _ "control
>>> background cleared as you scroll?" Me.Controls.Add(lb)
>>> End Sub
>>> End Class

Nov 20 '05 #8
Colin, put this in your New()

Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)

Tihis will force the control to repaint the entire surface. What is
happening is that your control is painting only the uncover part and not the
whole window.



"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether the
user autoscrolls the usercontrol (other things that are on the
usercontrol I want to scroll, but haven't included any here).

Here are the steps to reproduce my problem.

1. Launch Visual Studio and create a new Windows
application with "Form1".
2. Paste the following in (remember to include
your "Windows Form Designer generated code).
3. Run - instructions are in the program that runs.

I am using "Microsoft Development Environment 2003, Version 7.1.3088".
I am using "Microsoft .NET Framework 1.1, Version 1.1.4322"

Thank you for your patience with me.
Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class

Nov 20 '05 #9
Flickering: reverse the methods (modified below)
Recursive: no.
Protected Overrides Sub WndProc(ByRef m As _
System.Windows.Forms.Message)

'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
MyBase.WndProc(m)
End Sub

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
This is not a workable solution. The reason being that once you invalidate , it causes a paint event, which causes . . . . Flashing forms, lines etc

Recursive.

OHM
hexathioorthooxalate wrote:
Paste the following code into UserControl1
Hexathioorthooxalate
'Putting a Debug.WriteLine(m.ToString) in the subroutine below
'shows that the order that messages are received/processed is
'WM_PAINT and then WM_XSCROLL. The usercontrol appears to be
'being painted first, and then scrolled, and this is why you
'are not seeing the diagonal. This code will ensure that
'after a scroll, a repaint (through Invalidate()) will
'occur - messy and probably overkill but I cannot currently
'see another way around your dilemma.

Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message) MyBase.WndProc(m)
'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
End Sub


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
Actually, I was wrong. It is not an event. However, logic tells us
that an event has taken place because otherwise it could not have
scrolled.

I suggest you post this exact question as a new thread and this will
get you your answer. I dont know it at present.

Colin McGuire wrote:
OHM, I am sorry - I have seen this mentioned before and have never
understood it. I know I'm close and the cigar eludes me. Any chance
of coaching me on just a little further?
Here is what I think what you mean from your latest post, and as I
have implemented it is wrong because I get an a box showing up in my
IDE saying "'VScroll' is not an event of
WindowsApplication15.Form1.UserControl1'".

What I did to my original code was

Step 1: Added the following to UserControl1_Load

AddHandler VScroll, AddressOf capturedVScroll

Step 2: Added the following to the code in UserControl1

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub
My final code therefore looks like this, but just one more tweak is
necessary before I can get it to compile and work.

Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.Clear(BackColor)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As
System.Object, _ ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
AddHandler VScroll, AddressOf capturedVScroll 'ERROR
HERE End Sub

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub

End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" +
_ " drawn from(0,0) to (width,height).
2.Minimize" + _ " this form. 3. Restore the form
size,now the " + _ "line does go from (0,0) to
(width,height). " + _ "Why, why isn't the
diagonal line and " + _ "control background
cleared as you scroll?" Me.Controls.Add(lb)
End Sub
End Class

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
> You need to repaint on VScroll. Your user control inherits from
> Scrollable class and this event is protected so as you have
> inherited this you should be able to add a handler and force the
> control to repaint.
>
>
>
>
>
>
> Colin McGuire wrote:
>> You're not going to make me thank you again I hope :)
>>
>> Here is some more elaboration of my problem.
>>
>> What I see is:
>>
>> 1. When I move the vertical scrollbar by clicking "in"
>> the scrollbar (ie between the up arrow and down arrow),
>> the diagonal line is drawn properly (diagram below).
>>
>> +----------+
>> |\ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \|
>> +----------+
>>
>> 2. When I click the "down arrow" button on the vertical
>> scrollbar, the diagonal scrolls, but I can see a tiny
>> bit of the new diagonal showing up - sort of looks like
>>
>> +---\-------+
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \|
>> | |
>> | |
>> | \|
>> +-----------+
>>
>> 3. When I add a Debug.WriteLine("OnPaint") inside
>> the OnPaint method, both clicking "in" the scrollbar
>> and clicking the up or down arrow of the scrollbar
>> appear produce "OnPaint" in the IDE debug window.
>>
>> 4. When I minimise this (corrupted window, step 2), then
>> maximize it again, then it redraws properly with
>> the diagonal from (0,0) to (width,height) as shown
>> in Step 1.
>>
>> BTW: I forgot to paste in the
>>
>> p.Graphics.Clear(BackColor)
>>
>> in my original post before the
>> p.Graphics.DrawLine .... but
>> it doesn't make any difference if I do.
>>
>> Thank you
>> Colin
>>
>>
>>
>>
>>
>>
>> "One Handed Man" <Bo****@Duck.net> wrote in message
>> news:bl**********@hercules.btinternet.com...
>>> What happens then ?
>>>
>>>
>>> Colin McGuire wrote:
>>>> I apologize for posting yet another scrollbar question. Here is
>>>> my code. All I want is for a diagonal line to appear from
>>>> coordinates (0,0) to (width,height) in a usercontrol regardless
>>>> of whether the user autoscrolls the usercontrol (other things
>>>> that are on the usercontrol I want to scroll, but haven't
>>>> included any here).
>>>>
>>>> Here are the steps to reproduce my problem.
>>>>
>>>> 1. Launch Visual Studio and create a new Windows
>>>> application with "Form1".
>>>> 2. Paste the following in (remember to include
>>>> your "Windows Form Designer generated code).
>>>> 3. Run - instructions are in the program that runs.
>>>>
>>>> I am using "Microsoft Development Environment 2003, Version
>>>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>>>> 1.1.4322"
>>>>
>>>> Thank you for your patience with me.
>>>> Colin
>>>>
>>>>
>>>>
>>>> Public Class Form1
>>>> Inherits System.Windows.Forms.Form
>>>>
>>>> '======================
>>>> ' Windows Form Designer generated code
>>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>>> '======================
>>>>
>>>> Public Class UserControl1
>>>> Inherits System.Windows.Forms.UserControl
>>>> Protected Overrides Sub OnPaint(ByVal p As
>>>> PaintEventArgs) MyBase.OnPaint(p)
>>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>>> clientRectangle.Width, _
>>>> ClientRectangle.Height, _
>>>> 0, 0)
>>>> End Sub
>>>>
>>>> Private Sub UserControl1_Load(ByVal sender As
>>>> System.Object, _ ByVal e As System.EventArgs) _
>>>> Handles MyBase.Load
>>>> Me.BackColor = Color.Yellow
>>>> End Sub
>>>> End Class
>>>>
>>>>
>>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>>> Dim uc As New UserControl1
>>>> uc.Location = New Point(0, 0)
>>>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>>>> uc.BackColor = Color.Yellow
>>>> uc.AutoScroll = True
>>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>>> uc.Visible = True
>>>> Me.Controls.Add(uc)
>>>> Size = New Size(New Point(300, 300))
>>>>
>>>> Dim lb As New Label
>>>> lb.Location = New Point(0, 150)
>>>> lb.Size = New Size(290, 80)
>>>> lb.Text = "1.Move the scrollbars,the diagonal line
>>>> isn't" + _ " drawn from(0,0) to
>>>> (width,height).
>>>> 2.Minimize" + _ " this form. 3. Restore the
>>>> form size,now the " + _ "line does go from
>>>> (0,0) to (width,height). " + _ "Why, why
>>>> isn't the diagonal line and " + _ "control
>>>> background cleared as you scroll?" Me.Controls.Add(lb)
>>>> End Sub
>>>> End Class



Nov 20 '05 #10
Yes, a much better solution.
"Brian" <no****@prairie.lakes.com> wrote in message
news:vn************@corp.supernews.com...
Colin, put this in your New()

Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)

Tihis will force the control to repaint the entire surface. What is
happening is that your control is painting only the uncover part and not the whole window.



"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether the
user autoscrolls the usercontrol (other things that are on the
usercontrol I want to scroll, but haven't included any here).

Here are the steps to reproduce my problem.

1. Launch Visual Studio and create a new Windows
application with "Form1".
2. Paste the following in (remember to include
your "Windows Form Designer generated code).
3. Run - instructions are in the program that runs.

I am using "Microsoft Development Environment 2003, Version 7.1.3088".
I am using "Microsoft .NET Framework 1.1, Version 1.1.4322"

Thank you for your patience with me.
Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class



Nov 20 '05 #11
Nope sorry. The line flickes all the time because the paint events are
continually firing.

OHM

hexathioorthooxalate wrote:
Flickering: reverse the methods (modified below)
Recursive: no.
Protected Overrides Sub WndProc(ByRef m As _
System.Windows.Forms.Message)

'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
MyBase.WndProc(m)
End Sub

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
This is not a workable solution. The reason being that once you
invalidate , it causes a paint event, which causes . . . . Flashing
forms, lines etc

Recursive.

OHM
hexathioorthooxalate wrote:
Paste the following code into UserControl1
Hexathioorthooxalate
'Putting a Debug.WriteLine(m.ToString) in the subroutine below
'shows that the order that messages are received/processed is
'WM_PAINT and then WM_XSCROLL. The usercontrol appears to be
'being painted first, and then scrolled, and this is why you
'are not seeing the diagonal. This code will ensure that
'after a scroll, a repaint (through Invalidate()) will
'occur - messy and probably overkill but I cannot currently
'see another way around your dilemma.

Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message) MyBase.WndProc(m)
'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
End Sub


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
Actually, I was wrong. It is not an event. However, logic tells us
that an event has taken place because otherwise it could not have
scrolled.

I suggest you post this exact question as a new thread and this
will get you your answer. I dont know it at present.

Colin McGuire wrote:
> OHM, I am sorry - I have seen this mentioned before and have never
> understood it. I know I'm close and the cigar eludes me. Any
> chance of coaching me on just a little further?
>
>
> Here is what I think what you mean from your latest post, and as I
> have implemented it is wrong because I get an a box showing up in
> my IDE saying "'VScroll' is not an event of
> WindowsApplication15.Form1.UserControl1'".
>
> What I did to my original code was
>
> Step 1: Added the following to UserControl1_Load
>
> AddHandler VScroll, AddressOf capturedVScroll
>
> Step 2: Added the following to the code in UserControl1
>
> Private Sub capturedVScroll(ByVal sender As Object, _
> ByVal e As System.EventArgs)
> Debug.WriteLine("capturedVScroll")
> End Sub
>
>
> My final code therefore looks like this, but just one more tweak
> is necessary before I can get it to compile and work.
>
> Colin
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
>
> '======================
> ' Windows Form Designer generated code
> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
> '======================
>
> Public Class UserControl1
> Inherits System.Windows.Forms.UserControl
> Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
> MyBase.OnPaint(p)
> p.Graphics.Clear(BackColor)
> p.Graphics.DrawLine(New Pen(Color.Black), _
> clientRectangle.Width, _
> ClientRectangle.Height, _
> 0, 0)
> End Sub
>
> Private Sub UserControl1_Load(ByVal sender As
> System.Object, _ ByVal e As System.EventArgs) _
> Handles MyBase.Load
> Me.BackColor = Color.Yellow
> AddHandler VScroll, AddressOf capturedVScroll 'ERROR
> HERE End Sub
>
> Private Sub capturedVScroll(ByVal sender As Object, _
> ByVal e As System.EventArgs)
> Debug.WriteLine("capturedVScroll")
> End Sub
>
> End Class
>
>
> Private Sub Form1_Load(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim uc As New UserControl1
> uc.Location = New Point(0, 0)
> uc.Size = New System.Drawing.Size(New Point(100, 100))
> uc.BackColor = Color.Yellow
> uc.AutoScroll = True
> uc.AutoScrollMinSize = New Size(New Point(200, 300))
> uc.Visible = True
> Me.Controls.Add(uc)
> Size = New Size(New Point(300, 300))
>
> Dim lb As New Label
> lb.Location = New Point(0, 150)
> lb.Size = New Size(290, 80)
> lb.Text = "1.Move the scrollbars,the diagonal line isn't"
> + _ " drawn from(0,0) to (width,height).
> 2.Minimize" + _ " this form. 3. Restore the form
> size,now the " + _ "line does go from (0,0) to
> (width,height). " + _ "Why, why isn't the
> diagonal line and " + _ "control background
> cleared as you scroll?" Me.Controls.Add(lb)
> End Sub
> End Class
>
>
>
> "One Handed Man" <Bo****@Duck.net> wrote in message
> news:bl**********@titan.btinternet.com...
>> You need to repaint on VScroll. Your user control inherits from
>> Scrollable class and this event is protected so as you have
>> inherited this you should be able to add a handler and force the
>> control to repaint.
>>
>>
>>
>>
>>
>>
>> Colin McGuire wrote:
>>> You're not going to make me thank you again I hope :)
>>>
>>> Here is some more elaboration of my problem.
>>>
>>> What I see is:
>>>
>>> 1. When I move the vertical scrollbar by clicking "in"
>>> the scrollbar (ie between the up arrow and down arrow),
>>> the diagonal line is drawn properly (diagram below).
>>>
>>> +----------+
>>> |\ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \|
>>> +----------+
>>>
>>> 2. When I click the "down arrow" button on the vertical
>>> scrollbar, the diagonal scrolls, but I can see a tiny
>>> bit of the new diagonal showing up - sort of looks like
>>>
>>> +---\-------+
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \|
>>> | |
>>> | |
>>> | \|
>>> +-----------+
>>>
>>> 3. When I add a Debug.WriteLine("OnPaint") inside
>>> the OnPaint method, both clicking "in" the scrollbar
>>> and clicking the up or down arrow of the scrollbar
>>> appear produce "OnPaint" in the IDE debug window.
>>>
>>> 4. When I minimise this (corrupted window, step 2), then
>>> maximize it again, then it redraws properly with
>>> the diagonal from (0,0) to (width,height) as shown
>>> in Step 1.
>>>
>>> BTW: I forgot to paste in the
>>>
>>> p.Graphics.Clear(BackColor)
>>>
>>> in my original post before the
>>> p.Graphics.DrawLine .... but
>>> it doesn't make any difference if I do.
>>>
>>> Thank you
>>> Colin
>>>
>>>
>>>
>>>
>>>
>>>
>>> "One Handed Man" <Bo****@Duck.net> wrote in message
>>> news:bl**********@hercules.btinternet.com...
>>>> What happens then ?
>>>>
>>>>
>>>> Colin McGuire wrote:
>>>>> I apologize for posting yet another scrollbar question. Here
>>>>> is my code. All I want is for a diagonal line to appear from
>>>>> coordinates (0,0) to (width,height) in a usercontrol
>>>>> regardless of whether the user autoscrolls the usercontrol
>>>>> (other things that are on the usercontrol I want to scroll,
>>>>> but haven't included any here).
>>>>>
>>>>> Here are the steps to reproduce my problem.
>>>>>
>>>>> 1. Launch Visual Studio and create a new Windows
>>>>> application with "Form1".
>>>>> 2. Paste the following in (remember to include
>>>>> your "Windows Form Designer generated code).
>>>>> 3. Run - instructions are in the program that runs.
>>>>>
>>>>> I am using "Microsoft Development Environment 2003, Version
>>>>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>>>>> 1.1.4322"
>>>>>
>>>>> Thank you for your patience with me.
>>>>> Colin
>>>>>
>>>>>
>>>>>
>>>>> Public Class Form1
>>>>> Inherits System.Windows.Forms.Form
>>>>>
>>>>> '======================
>>>>> ' Windows Form Designer generated code
>>>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>>>> '======================
>>>>>
>>>>> Public Class UserControl1
>>>>> Inherits System.Windows.Forms.UserControl
>>>>> Protected Overrides Sub OnPaint(ByVal p As
>>>>> PaintEventArgs) MyBase.OnPaint(p)
>>>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>>>> clientRectangle.Width, _
>>>>> ClientRectangle.Height, _
>>>>> 0, 0)
>>>>> End Sub
>>>>>
>>>>> Private Sub UserControl1_Load(ByVal sender As
>>>>> System.Object, _ ByVal e As System.EventArgs) _
>>>>> Handles MyBase.Load
>>>>> Me.BackColor = Color.Yellow
>>>>> End Sub
>>>>> End Class
>>>>>
>>>>>
>>>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>>>> Dim uc As New UserControl1
>>>>> uc.Location = New Point(0, 0)
>>>>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>>>>> uc.BackColor = Color.Yellow
>>>>> uc.AutoScroll = True
>>>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>>>> uc.Visible = True
>>>>> Me.Controls.Add(uc)
>>>>> Size = New Size(New Point(300, 300))
>>>>>
>>>>> Dim lb As New Label
>>>>> lb.Location = New Point(0, 150)
>>>>> lb.Size = New Size(290, 80)
>>>>> lb.Text = "1.Move the scrollbars,the diagonal line
>>>>> isn't" + _ " drawn from(0,0) to
>>>>> (width,height).
>>>>> 2.Minimize" + _ " this form. 3. Restore the
>>>>> form size,now the " + _ "line does go from
>>>>> (0,0) to (width,height). " + _ "Why, why
>>>>> isn't the diagonal line and " + _ "control
>>>>> background cleared as you scroll?" Me.Controls.Add(lb)
>>>>> End Sub
>>>>> End Class

Nov 20 '05 #12
Sorry, I forgot to take out a refresh in the paint event.
Yes, it works a treat. Thanks for your help
Regards OHM
One Handed Man wrote:
Nope sorry. The line flickes all the time because the paint events are
continually firing.

OHM

hexathioorthooxalate wrote:
Flickering: reverse the methods (modified below)
Recursive: no.
Protected Overrides Sub WndProc(ByRef m As _
System.Windows.Forms.Message)

'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
MyBase.WndProc(m)
End Sub

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
This is not a workable solution. The reason being that once you
invalidate , it causes a paint event, which causes . . . . Flashing
forms, lines etc

Recursive.

OHM
hexathioorthooxalate wrote:
Paste the following code into UserControl1
Hexathioorthooxalate
'Putting a Debug.WriteLine(m.ToString) in the subroutine below
'shows that the order that messages are received/processed is
'WM_PAINT and then WM_XSCROLL. The usercontrol appears to be
'being painted first, and then scrolled, and this is why you
'are not seeing the diagonal. This code will ensure that
'after a scroll, a repaint (through Invalidate()) will
'occur - messy and probably overkill but I cannot currently
'see another way around your dilemma.

Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message) MyBase.WndProc(m)
'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
End Sub


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
> Actually, I was wrong. It is not an event. However, logic tells us
> that an event has taken place because otherwise it could not have
> scrolled.
>
> I suggest you post this exact question as a new thread and this
> will get you your answer. I dont know it at present.
>
>
>
>
>
> Colin McGuire wrote:
>> OHM, I am sorry - I have seen this mentioned before and have
>> never understood it. I know I'm close and the cigar eludes me.
>> Any chance of coaching me on just a little further?
>>
>>
>> Here is what I think what you mean from your latest post, and as
>> I have implemented it is wrong because I get an a box showing up
>> in my IDE saying "'VScroll' is not an event of
>> WindowsApplication15.Form1.UserControl1'".
>>
>> What I did to my original code was
>>
>> Step 1: Added the following to UserControl1_Load
>>
>> AddHandler VScroll, AddressOf capturedVScroll
>>
>> Step 2: Added the following to the code in UserControl1
>>
>> Private Sub capturedVScroll(ByVal sender As Object, _
>> ByVal e As System.EventArgs)
>> Debug.WriteLine("capturedVScroll")
>> End Sub
>>
>>
>> My final code therefore looks like this, but just one more tweak
>> is necessary before I can get it to compile and work.
>>
>> Colin
>>
>> Public Class Form1
>> Inherits System.Windows.Forms.Form
>>
>> '======================
>> ' Windows Form Designer generated code
>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>> '======================
>>
>> Public Class UserControl1
>> Inherits System.Windows.Forms.UserControl
>> Protected Overrides Sub OnPaint(ByVal p As
>> PaintEventArgs) MyBase.OnPaint(p)
>> p.Graphics.Clear(BackColor)
>> p.Graphics.DrawLine(New Pen(Color.Black), _
>> clientRectangle.Width, _
>> ClientRectangle.Height, _
>> 0, 0)
>> End Sub
>>
>> Private Sub UserControl1_Load(ByVal sender As
>> System.Object, _ ByVal e As System.EventArgs) _
>> Handles MyBase.Load
>> Me.BackColor = Color.Yellow
>> AddHandler VScroll, AddressOf capturedVScroll 'ERROR
>> HERE End Sub
>>
>> Private Sub capturedVScroll(ByVal sender As Object, _
>> ByVal e As System.EventArgs)
>> Debug.WriteLine("capturedVScroll")
>> End Sub
>>
>> End Class
>>
>>
>> Private Sub Form1_Load(ByVal sender As System.Object, _
>> ByVal e As System.EventArgs) Handles MyBase.Load
>> Dim uc As New UserControl1
>> uc.Location = New Point(0, 0)
>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>> uc.BackColor = Color.Yellow
>> uc.AutoScroll = True
>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>> uc.Visible = True
>> Me.Controls.Add(uc)
>> Size = New Size(New Point(300, 300))
>>
>> Dim lb As New Label
>> lb.Location = New Point(0, 150)
>> lb.Size = New Size(290, 80)
>> lb.Text = "1.Move the scrollbars,the diagonal line isn't"
>> + _ " drawn from(0,0) to (width,height).
>> 2.Minimize" + _ " this form. 3. Restore the
>> form size,now the " + _ "line does go from
>> (0,0) to (width,height). " + _ "Why, why isn't
>> the diagonal line and " + _ "control background
>> cleared as you scroll?" Me.Controls.Add(lb)
>> End Sub
>> End Class
>>
>>
>>
>> "One Handed Man" <Bo****@Duck.net> wrote in message
>> news:bl**********@titan.btinternet.com...
>>> You need to repaint on VScroll. Your user control inherits
>>> from Scrollable class and this event is protected so as you have
>>> inherited this you should be able to add a handler and force the
>>> control to repaint.
>>>
>>>
>>>
>>>
>>>
>>>
>>> Colin McGuire wrote:
>>>> You're not going to make me thank you again I hope :)
>>>>
>>>> Here is some more elaboration of my problem.
>>>>
>>>> What I see is:
>>>>
>>>> 1. When I move the vertical scrollbar by clicking "in"
>>>> the scrollbar (ie between the up arrow and down arrow),
>>>> the diagonal line is drawn properly (diagram below).
>>>>
>>>> +----------+
>>>> |\ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \|
>>>> +----------+
>>>>
>>>> 2. When I click the "down arrow" button on the vertical
>>>> scrollbar, the diagonal scrolls, but I can see a tiny
>>>> bit of the new diagonal showing up - sort of looks like
>>>>
>>>> +---\-------+
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \|
>>>> | |
>>>> | |
>>>> | \|
>>>> +-----------+
>>>>
>>>> 3. When I add a Debug.WriteLine("OnPaint") inside
>>>> the OnPaint method, both clicking "in" the scrollbar
>>>> and clicking the up or down arrow of the scrollbar
>>>> appear produce "OnPaint" in the IDE debug window.
>>>>
>>>> 4. When I minimise this (corrupted window, step 2), then
>>>> maximize it again, then it redraws properly with
>>>> the diagonal from (0,0) to (width,height) as shown
>>>> in Step 1.
>>>>
>>>> BTW: I forgot to paste in the
>>>>
>>>> p.Graphics.Clear(BackColor)
>>>>
>>>> in my original post before the
>>>> p.Graphics.DrawLine .... but
>>>> it doesn't make any difference if I do.
>>>>
>>>> Thank you
>>>> Colin
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> "One Handed Man" <Bo****@Duck.net> wrote in message
>>>> news:bl**********@hercules.btinternet.com...
>>>>> What happens then ?
>>>>>
>>>>>
>>>>> Colin McGuire wrote:
>>>>>> I apologize for posting yet another scrollbar question. Here
>>>>>> is my code. All I want is for a diagonal line to appear from
>>>>>> coordinates (0,0) to (width,height) in a usercontrol
>>>>>> regardless of whether the user autoscrolls the usercontrol
>>>>>> (other things that are on the usercontrol I want to scroll,
>>>>>> but haven't included any here).
>>>>>>
>>>>>> Here are the steps to reproduce my problem.
>>>>>>
>>>>>> 1. Launch Visual Studio and create a new Windows
>>>>>> application with "Form1".
>>>>>> 2. Paste the following in (remember to include
>>>>>> your "Windows Form Designer generated code).
>>>>>> 3. Run - instructions are in the program that runs.
>>>>>>
>>>>>> I am using "Microsoft Development Environment 2003, Version
>>>>>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>>>>>> 1.1.4322"
>>>>>>
>>>>>> Thank you for your patience with me.
>>>>>> Colin
>>>>>>
>>>>>>
>>>>>>
>>>>>> Public Class Form1
>>>>>> Inherits System.Windows.Forms.Form
>>>>>>
>>>>>> '======================
>>>>>> ' Windows Form Designer generated code
>>>>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>>>>> '======================
>>>>>>
>>>>>> Public Class UserControl1
>>>>>> Inherits System.Windows.Forms.UserControl
>>>>>> Protected Overrides Sub OnPaint(ByVal p As
>>>>>> PaintEventArgs) MyBase.OnPaint(p)
>>>>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>>>>> clientRectangle.Width, _
>>>>>> ClientRectangle.Height, _
>>>>>> 0, 0)
>>>>>> End Sub
>>>>>>
>>>>>> Private Sub UserControl1_Load(ByVal sender As
>>>>>> System.Object, _ ByVal e As System.EventArgs) _
>>>>>> Handles MyBase.Load
>>>>>> Me.BackColor = Color.Yellow
>>>>>> End Sub
>>>>>> End Class
>>>>>>
>>>>>>
>>>>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>>>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>>>>> Dim uc As New UserControl1
>>>>>> uc.Location = New Point(0, 0)
>>>>>> uc.Size = New System.Drawing.Size(New Point(100,
>>>>>> 100)) uc.BackColor = Color.Yellow
>>>>>> uc.AutoScroll = True
>>>>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>>>>> uc.Visible = True
>>>>>> Me.Controls.Add(uc)
>>>>>> Size = New Size(New Point(300, 300))
>>>>>>
>>>>>> Dim lb As New Label
>>>>>> lb.Location = New Point(0, 150)
>>>>>> lb.Size = New Size(290, 80)
>>>>>> lb.Text = "1.Move the scrollbars,the diagonal line
>>>>>> isn't" + _ " drawn from(0,0) to
>>>>>> (width,height).
>>>>>> 2.Minimize" + _ " this form. 3. Restore the
>>>>>> form size,now the " + _ "line does go from
>>>>>> (0,0) to (width,height). " + _ "Why, why
>>>>>> isn't the diagonal line and " + _ "control
>>>>>> background cleared as you scroll?"
>>>>>> Me.Controls.Add(lb) End Sub
>>>>>> End Class

Nov 20 '05 #13
Are you sure? Not for me? You might be right but I can't see it. Why would
continually refresh?
The WndProc only causes a repaint when via WM_VSCROLL and WM_HSCROLL
messages are detected, which isn't every time. I don't see how it can be
continually firing.
"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
Nope sorry. The line flickes all the time because the paint events are
continually firing.

OHM

hexathioorthooxalate wrote:
Flickering: reverse the methods (modified below)
Recursive: no.
Protected Overrides Sub WndProc(ByRef m As _
System.Windows.Forms.Message)

'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
MyBase.WndProc(m)
End Sub

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
This is not a workable solution. The reason being that once you
invalidate , it causes a paint event, which causes . . . . Flashing
forms, lines etc

Recursive.

OHM
hexathioorthooxalate wrote:
Paste the following code into UserControl1
Hexathioorthooxalate
'Putting a Debug.WriteLine(m.ToString) in the subroutine below
'shows that the order that messages are received/processed is
'WM_PAINT and then WM_XSCROLL. The usercontrol appears to be
'being painted first, and then scrolled, and this is why you
'are not seeing the diagonal. This code will ensure that
'after a scroll, a repaint (through Invalidate()) will
'occur - messy and probably overkill but I cannot currently
'see another way around your dilemma.

Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message) MyBase.WndProc(m)
'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
End Sub


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
> Actually, I was wrong. It is not an event. However, logic tells us
> that an event has taken place because otherwise it could not have
> scrolled.
>
> I suggest you post this exact question as a new thread and this
> will get you your answer. I dont know it at present.
>
>
>
>
>
> Colin McGuire wrote:
>> OHM, I am sorry - I have seen this mentioned before and have never
>> understood it. I know I'm close and the cigar eludes me. Any
>> chance of coaching me on just a little further?
>>
>>
>> Here is what I think what you mean from your latest post, and as I
>> have implemented it is wrong because I get an a box showing up in
>> my IDE saying "'VScroll' is not an event of
>> WindowsApplication15.Form1.UserControl1'".
>>
>> What I did to my original code was
>>
>> Step 1: Added the following to UserControl1_Load
>>
>> AddHandler VScroll, AddressOf capturedVScroll
>>
>> Step 2: Added the following to the code in UserControl1
>>
>> Private Sub capturedVScroll(ByVal sender As Object, _
>> ByVal e As System.EventArgs)
>> Debug.WriteLine("capturedVScroll")
>> End Sub
>>
>>
>> My final code therefore looks like this, but just one more tweak
>> is necessary before I can get it to compile and work.
>>
>> Colin
>>
>> Public Class Form1
>> Inherits System.Windows.Forms.Form
>>
>> '======================
>> ' Windows Form Designer generated code
>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>> '======================
>>
>> Public Class UserControl1
>> Inherits System.Windows.Forms.UserControl
>> Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
>> MyBase.OnPaint(p)
>> p.Graphics.Clear(BackColor)
>> p.Graphics.DrawLine(New Pen(Color.Black), _
>> clientRectangle.Width, _
>> ClientRectangle.Height, _
>> 0, 0)
>> End Sub
>>
>> Private Sub UserControl1_Load(ByVal sender As
>> System.Object, _ ByVal e As System.EventArgs) _
>> Handles MyBase.Load
>> Me.BackColor = Color.Yellow
>> AddHandler VScroll, AddressOf capturedVScroll 'ERROR
>> HERE End Sub
>>
>> Private Sub capturedVScroll(ByVal sender As Object, _
>> ByVal e As System.EventArgs)
>> Debug.WriteLine("capturedVScroll")
>> End Sub
>>
>> End Class
>>
>>
>> Private Sub Form1_Load(ByVal sender As System.Object, _
>> ByVal e As System.EventArgs) Handles MyBase.Load
>> Dim uc As New UserControl1
>> uc.Location = New Point(0, 0)
>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>> uc.BackColor = Color.Yellow
>> uc.AutoScroll = True
>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>> uc.Visible = True
>> Me.Controls.Add(uc)
>> Size = New Size(New Point(300, 300))
>>
>> Dim lb As New Label
>> lb.Location = New Point(0, 150)
>> lb.Size = New Size(290, 80)
>> lb.Text = "1.Move the scrollbars,the diagonal line isn't"
>> + _ " drawn from(0,0) to (width,height).
>> 2.Minimize" + _ " this form. 3. Restore the form
>> size,now the " + _ "line does go from (0,0) to
>> (width,height). " + _ "Why, why isn't the
>> diagonal line and " + _ "control background
>> cleared as you scroll?" Me.Controls.Add(lb)
>> End Sub
>> End Class
>>
>>
>>
>> "One Handed Man" <Bo****@Duck.net> wrote in message
>> news:bl**********@titan.btinternet.com...
>>> You need to repaint on VScroll. Your user control inherits from
>>> Scrollable class and this event is protected so as you have
>>> inherited this you should be able to add a handler and force the
>>> control to repaint.
>>>
>>>
>>>
>>>
>>>
>>>
>>> Colin McGuire wrote:
>>>> You're not going to make me thank you again I hope :)
>>>>
>>>> Here is some more elaboration of my problem.
>>>>
>>>> What I see is:
>>>>
>>>> 1. When I move the vertical scrollbar by clicking "in"
>>>> the scrollbar (ie between the up arrow and down arrow),
>>>> the diagonal line is drawn properly (diagram below).
>>>>
>>>> +----------+
>>>> |\ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \|
>>>> +----------+
>>>>
>>>> 2. When I click the "down arrow" button on the vertical
>>>> scrollbar, the diagonal scrolls, but I can see a tiny
>>>> bit of the new diagonal showing up - sort of looks like
>>>>
>>>> +---\-------+
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \|
>>>> | |
>>>> | |
>>>> | \|
>>>> +-----------+
>>>>
>>>> 3. When I add a Debug.WriteLine("OnPaint") inside
>>>> the OnPaint method, both clicking "in" the scrollbar
>>>> and clicking the up or down arrow of the scrollbar
>>>> appear produce "OnPaint" in the IDE debug window.
>>>>
>>>> 4. When I minimise this (corrupted window, step 2), then
>>>> maximize it again, then it redraws properly with
>>>> the diagonal from (0,0) to (width,height) as shown
>>>> in Step 1.
>>>>
>>>> BTW: I forgot to paste in the
>>>>
>>>> p.Graphics.Clear(BackColor)
>>>>
>>>> in my original post before the
>>>> p.Graphics.DrawLine .... but
>>>> it doesn't make any difference if I do.
>>>>
>>>> Thank you
>>>> Colin
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> "One Handed Man" <Bo****@Duck.net> wrote in message
>>>> news:bl**********@hercules.btinternet.com...
>>>>> What happens then ?
>>>>>
>>>>>
>>>>> Colin McGuire wrote:
>>>>>> I apologize for posting yet another scrollbar question. Here
>>>>>> is my code. All I want is for a diagonal line to appear from
>>>>>> coordinates (0,0) to (width,height) in a usercontrol
>>>>>> regardless of whether the user autoscrolls the usercontrol
>>>>>> (other things that are on the usercontrol I want to scroll,
>>>>>> but haven't included any here).
>>>>>>
>>>>>> Here are the steps to reproduce my problem.
>>>>>>
>>>>>> 1. Launch Visual Studio and create a new Windows
>>>>>> application with "Form1".
>>>>>> 2. Paste the following in (remember to include
>>>>>> your "Windows Form Designer generated code).
>>>>>> 3. Run - instructions are in the program that runs.
>>>>>>
>>>>>> I am using "Microsoft Development Environment 2003, Version
>>>>>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>>>>>> 1.1.4322"
>>>>>>
>>>>>> Thank you for your patience with me.
>>>>>> Colin
>>>>>>
>>>>>>
>>>>>>
>>>>>> Public Class Form1
>>>>>> Inherits System.Windows.Forms.Form
>>>>>>
>>>>>> '======================
>>>>>> ' Windows Form Designer generated code
>>>>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>>>>> '======================
>>>>>>
>>>>>> Public Class UserControl1
>>>>>> Inherits System.Windows.Forms.UserControl
>>>>>> Protected Overrides Sub OnPaint(ByVal p As
>>>>>> PaintEventArgs) MyBase.OnPaint(p)
>>>>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>>>>> clientRectangle.Width, _
>>>>>> ClientRectangle.Height, _
>>>>>> 0, 0)
>>>>>> End Sub
>>>>>>
>>>>>> Private Sub UserControl1_Load(ByVal sender As
>>>>>> System.Object, _ ByVal e As System.EventArgs) _
>>>>>> Handles MyBase.Load
>>>>>> Me.BackColor = Color.Yellow
>>>>>> End Sub
>>>>>> End Class
>>>>>>
>>>>>>
>>>>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>>>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>>>>> Dim uc As New UserControl1
>>>>>> uc.Location = New Point(0, 0)
>>>>>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>>>>>> uc.BackColor = Color.Yellow
>>>>>> uc.AutoScroll = True
>>>>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>>>>> uc.Visible = True
>>>>>> Me.Controls.Add(uc)
>>>>>> Size = New Size(New Point(300, 300))
>>>>>>
>>>>>> Dim lb As New Label
>>>>>> lb.Location = New Point(0, 150)
>>>>>> lb.Size = New Size(290, 80)
>>>>>> lb.Text = "1.Move the scrollbars,the diagonal line
>>>>>> isn't" + _ " drawn from(0,0) to
>>>>>> (width,height).
>>>>>> 2.Minimize" + _ " this form. 3. Restore the
>>>>>> form size,now the " + _ "line does go from
>>>>>> (0,0) to (width,height). " + _ "Why, why
>>>>>> isn't the diagonal line and " + _ "control
>>>>>> background cleared as you scroll?" Me.Controls.Add(lb)
>>>>>> End Sub
>>>>>> End Class



Nov 20 '05 #14
We posted at the same time, just read what you had written.
Glad to be of help - Brian's solution is nicer though.
Hexathioorthooxalate.


"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message
news:10****************@doris.uk.clara.net...
Are you sure? Not for me? You might be right but I can't see it. Why would
continually refresh?
The WndProc only causes a repaint when via WM_VSCROLL and WM_HSCROLL
messages are detected, which isn't every time. I don't see how it can be
continually firing.
"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
Nope sorry. The line flickes all the time because the paint events are
continually firing.

OHM

hexathioorthooxalate wrote:
Flickering: reverse the methods (modified below)
Recursive: no.
Protected Overrides Sub WndProc(ByRef m As _
System.Windows.Forms.Message)

'0x115=WM_VSCROLL, 0x114=WM_HSCROLL
If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
MyBase.WndProc(m)
End Sub

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
> This is not a workable solution. The reason being that once you
> invalidate , it causes a paint event, which causes . . . . Flashing
> forms, lines etc
>
> Recursive.
>
> OHM
>
>
> hexathioorthooxalate wrote:
>> Paste the following code into UserControl1
>> Hexathioorthooxalate
>>
>>
>> 'Putting a Debug.WriteLine(m.ToString) in the subroutine below
>> 'shows that the order that messages are received/processed is
>> 'WM_PAINT and then WM_XSCROLL. The usercontrol appears to be
>> 'being painted first, and then scrolled, and this is why you
>> 'are not seeing the diagonal. This code will ensure that
>> 'after a scroll, a repaint (through Invalidate()) will
>> 'occur - messy and probably overkill but I cannot currently
>> 'see another way around your dilemma.
>>
>> Protected Overrides Sub WndProc(ByRef m As
>> System.Windows.Forms.Message) MyBase.WndProc(m)
>> '0x115=WM_VSCROLL, 0x114=WM_HSCROLL
>> If m.Msg = &H115 Or m.Msg = &H114 Then Invalidate()
>> End Sub
>>
>>
>>
>>
>> "One Handed Man" <Bo****@Duck.net> wrote in message
>> news:bl**********@hercules.btinternet.com...
>>> Actually, I was wrong. It is not an event. However, logic tells us
>>> that an event has taken place because otherwise it could not have
>>> scrolled.
>>>
>>> I suggest you post this exact question as a new thread and this
>>> will get you your answer. I dont know it at present.
>>>
>>>
>>>
>>>
>>>
>>> Colin McGuire wrote:
>>>> OHM, I am sorry - I have seen this mentioned before and have never
>>>> understood it. I know I'm close and the cigar eludes me. Any
>>>> chance of coaching me on just a little further?
>>>>
>>>>
>>>> Here is what I think what you mean from your latest post, and as I
>>>> have implemented it is wrong because I get an a box showing up in
>>>> my IDE saying "'VScroll' is not an event of
>>>> WindowsApplication15.Form1.UserControl1'".
>>>>
>>>> What I did to my original code was
>>>>
>>>> Step 1: Added the following to UserControl1_Load
>>>>
>>>> AddHandler VScroll, AddressOf capturedVScroll
>>>>
>>>> Step 2: Added the following to the code in UserControl1
>>>>
>>>> Private Sub capturedVScroll(ByVal sender As Object, _
>>>> ByVal e As System.EventArgs)
>>>> Debug.WriteLine("capturedVScroll")
>>>> End Sub
>>>>
>>>>
>>>> My final code therefore looks like this, but just one more tweak
>>>> is necessary before I can get it to compile and work.
>>>>
>>>> Colin
>>>>
>>>> Public Class Form1
>>>> Inherits System.Windows.Forms.Form
>>>>
>>>> '======================
>>>> ' Windows Form Designer generated code
>>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>>> '======================
>>>>
>>>> Public Class UserControl1
>>>> Inherits System.Windows.Forms.UserControl
>>>> Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
>>>> MyBase.OnPaint(p)
>>>> p.Graphics.Clear(BackColor)
>>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>>> clientRectangle.Width, _
>>>> ClientRectangle.Height, _
>>>> 0, 0)
>>>> End Sub
>>>>
>>>> Private Sub UserControl1_Load(ByVal sender As
>>>> System.Object, _ ByVal e As System.EventArgs) _
>>>> Handles MyBase.Load
>>>> Me.BackColor = Color.Yellow
>>>> AddHandler VScroll, AddressOf capturedVScroll 'ERROR
>>>> HERE End Sub
>>>>
>>>> Private Sub capturedVScroll(ByVal sender As Object, _
>>>> ByVal e As System.EventArgs)
>>>> Debug.WriteLine("capturedVScroll")
>>>> End Sub
>>>>
>>>> End Class
>>>>
>>>>
>>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>>> Dim uc As New UserControl1
>>>> uc.Location = New Point(0, 0)
>>>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>>>> uc.BackColor = Color.Yellow
>>>> uc.AutoScroll = True
>>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>>> uc.Visible = True
>>>> Me.Controls.Add(uc)
>>>> Size = New Size(New Point(300, 300))
>>>>
>>>> Dim lb As New Label
>>>> lb.Location = New Point(0, 150)
>>>> lb.Size = New Size(290, 80)
>>>> lb.Text = "1.Move the scrollbars,the diagonal line isn't"
>>>> + _ " drawn from(0,0) to (width,height).
>>>> 2.Minimize" + _ " this form. 3. Restore the form
>>>> size,now the " + _ "line does go from (0,0) to
>>>> (width,height). " + _ "Why, why isn't the
>>>> diagonal line and " + _ "control background
>>>> cleared as you scroll?" Me.Controls.Add(lb)
>>>> End Sub
>>>> End Class
>>>>
>>>>
>>>>
>>>> "One Handed Man" <Bo****@Duck.net> wrote in message
>>>> news:bl**********@titan.btinternet.com...
>>>>> You need to repaint on VScroll. Your user control inherits from
>>>>> Scrollable class and this event is protected so as you have
>>>>> inherited this you should be able to add a handler and force the
>>>>> control to repaint.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Colin McGuire wrote:
>>>>>> You're not going to make me thank you again I hope :)
>>>>>>
>>>>>> Here is some more elaboration of my problem.
>>>>>>
>>>>>> What I see is:
>>>>>>
>>>>>> 1. When I move the vertical scrollbar by clicking "in"
>>>>>> the scrollbar (ie between the up arrow and down arrow),
>>>>>> the diagonal line is drawn properly (diagram below).
>>>>>>
>>>>>> +----------+
>>>>>> |\ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \|
>>>>>> +----------+
>>>>>>
>>>>>> 2. When I click the "down arrow" button on the vertical
>>>>>> scrollbar, the diagonal scrolls, but I can see a tiny
>>>>>> bit of the new diagonal showing up - sort of looks like
>>>>>>
>>>>>> +---\-------+
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \ |
>>>>>> | \|
>>>>>> | |
>>>>>> | |
>>>>>> | \|
>>>>>> +-----------+
>>>>>>
>>>>>> 3. When I add a Debug.WriteLine("OnPaint") inside
>>>>>> the OnPaint method, both clicking "in" the scrollbar
>>>>>> and clicking the up or down arrow of the scrollbar
>>>>>> appear produce "OnPaint" in the IDE debug window.
>>>>>>
>>>>>> 4. When I minimise this (corrupted window, step 2), then
>>>>>> maximize it again, then it redraws properly with
>>>>>> the diagonal from (0,0) to (width,height) as shown
>>>>>> in Step 1.
>>>>>>
>>>>>> BTW: I forgot to paste in the
>>>>>>
>>>>>> p.Graphics.Clear(BackColor)
>>>>>>
>>>>>> in my original post before the
>>>>>> p.Graphics.DrawLine .... but
>>>>>> it doesn't make any difference if I do.
>>>>>>
>>>>>> Thank you
>>>>>> Colin
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> "One Handed Man" <Bo****@Duck.net> wrote in message
>>>>>> news:bl**********@hercules.btinternet.com...
>>>>>>> What happens then ?
>>>>>>>
>>>>>>>
>>>>>>> Colin McGuire wrote:
>>>>>>>> I apologize for posting yet another scrollbar question. Here
>>>>>>>> is my code. All I want is for a diagonal line to appear from
>>>>>>>> coordinates (0,0) to (width,height) in a usercontrol
>>>>>>>> regardless of whether the user autoscrolls the usercontrol
>>>>>>>> (other things that are on the usercontrol I want to scroll,
>>>>>>>> but haven't included any here).
>>>>>>>>
>>>>>>>> Here are the steps to reproduce my problem.
>>>>>>>>
>>>>>>>> 1. Launch Visual Studio and create a new Windows
>>>>>>>> application with "Form1".
>>>>>>>> 2. Paste the following in (remember to include
>>>>>>>> your "Windows Form Designer generated code).
>>>>>>>> 3. Run - instructions are in the program that runs.
>>>>>>>>
>>>>>>>> I am using "Microsoft Development Environment 2003, Version
>>>>>>>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>>>>>>>> 1.1.4322"
>>>>>>>>
>>>>>>>> Thank you for your patience with me.
>>>>>>>> Colin
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Public Class Form1
>>>>>>>> Inherits System.Windows.Forms.Form
>>>>>>>>
>>>>>>>> '======================
>>>>>>>> ' Windows Form Designer generated code
>>>>>>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>>>>>>> '======================
>>>>>>>>
>>>>>>>> Public Class UserControl1
>>>>>>>> Inherits System.Windows.Forms.UserControl
>>>>>>>> Protected Overrides Sub OnPaint(ByVal p As
>>>>>>>> PaintEventArgs) MyBase.OnPaint(p)
>>>>>>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>>>>>>> clientRectangle.Width, _
>>>>>>>> ClientRectangle.Height, _
>>>>>>>> 0, 0)
>>>>>>>> End Sub
>>>>>>>>
>>>>>>>> Private Sub UserControl1_Load(ByVal sender As
>>>>>>>> System.Object, _ ByVal e As System.EventArgs) _
>>>>>>>> Handles MyBase.Load
>>>>>>>> Me.BackColor = Color.Yellow
>>>>>>>> End Sub
>>>>>>>> End Class
>>>>>>>>
>>>>>>>>
>>>>>>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>>>>>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>>>>>>> Dim uc As New UserControl1
>>>>>>>> uc.Location = New Point(0, 0)
>>>>>>>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>>>>>>>> uc.BackColor = Color.Yellow
>>>>>>>> uc.AutoScroll = True
>>>>>>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>>>>>>> uc.Visible = True
>>>>>>>> Me.Controls.Add(uc)
>>>>>>>> Size = New Size(New Point(300, 300))
>>>>>>>>
>>>>>>>> Dim lb As New Label
>>>>>>>> lb.Location = New Point(0, 150)
>>>>>>>> lb.Size = New Size(290, 80)
>>>>>>>> lb.Text = "1.Move the scrollbars,the diagonal line
>>>>>>>> isn't" + _ " drawn from(0,0) to
>>>>>>>> (width,height).
>>>>>>>> 2.Minimize" + _ " this form. 3. Restore the
>>>>>>>> form size,now the " + _ "line does go from
>>>>>>>> (0,0) to (width,height). " + _ "Why, why
>>>>>>>> isn't the diagonal line and " + _ "control
>>>>>>>> background cleared as you scroll?" Me.Controls.Add(lb)
>>>>>>>> End Sub
>>>>>>>> End Class



Nov 20 '05 #15
hexathioorthooxalate solution DOES not work for me, unfortunatley, Brian's
didnt

OHM


Yes, a much better solution.
"Brian" <no****@prairie.lakes.com> wrote in message
news:vn************@corp.supernews.com...
Colin, put this in your New()

Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)

Tihis will force the control to repaint the entire surface. What is
happening is that your control is painting only the uncover part and
not the whole window.



"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether the
user autoscrolls the usercontrol (other things that are on the
usercontrol I want to scroll, but haven't included any here).

Here are the steps to reproduce my problem.

1. Launch Visual Studio and create a new Windows
application with "Form1".
2. Paste the following in (remember to include
your "Windows Form Designer generated code).
3. Run - instructions are in the program that runs.

I am using "Microsoft Development Environment 2003, Version
7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
1.1.4322"

Thank you for your patience with me.
Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As
System.Object, _ ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" +
_ " drawn from(0,0) to (width,height).
2.Minimize" + _ " this form. 3. Restore the form
size,now the " + _ "line does go from (0,0) to
(width,height). " + _ "Why, why isn't the
diagonal line and " + _ "control background
cleared as you scroll?" Me.Controls.Add(lb)
End Sub
End Class

Nov 20 '05 #16
Just out of curiosity, was this requirement to demonstrate to the UI user
that this control was disabled in some way ?

Colin McGuire wrote:
OHM, I am sorry - I have seen this mentioned before and have never
understood it. I know I'm close and the cigar eludes me. Any chance of
coaching me on just a little further?
Here is what I think what you mean from your latest post, and as I
have implemented it is wrong because I get an a box showing up in my
IDE saying "'VScroll' is not an event of
WindowsApplication15.Form1.UserControl1'".

What I did to my original code was

Step 1: Added the following to UserControl1_Load

AddHandler VScroll, AddressOf capturedVScroll

Step 2: Added the following to the code in UserControl1

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub
My final code therefore looks like this, but just one more tweak is
necessary before I can get it to compile and work.

Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.Clear(BackColor)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
AddHandler VScroll, AddressOf capturedVScroll 'ERROR HERE
End Sub

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub

End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
You need to repaint on VScroll. Your user control inherits from
Scrollable class and this event is protected so as you have
inherited this you should be able to add a handler and force the
control to repaint.


Colin McGuire wrote:
You're not going to make me thank you again I hope :)

Here is some more elaboration of my problem.

What I see is:

1. When I move the vertical scrollbar by clicking "in"
the scrollbar (ie between the up arrow and down arrow),
the diagonal line is drawn properly (diagram below).

+----------+
|\ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
+----------+

2. When I click the "down arrow" button on the vertical
scrollbar, the diagonal scrolls, but I can see a tiny
bit of the new diagonal showing up - sort of looks like

+---\-------+
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
| |
| |
| \|
+-----------+

3. When I add a Debug.WriteLine("OnPaint") inside
the OnPaint method, both clicking "in" the scrollbar
and clicking the up or down arrow of the scrollbar
appear produce "OnPaint" in the IDE debug window.

4. When I minimise this (corrupted window, step 2), then
maximize it again, then it redraws properly with
the diagonal from (0,0) to (width,height) as shown
in Step 1.

BTW: I forgot to paste in the

p.Graphics.Clear(BackColor)

in my original post before the
p.Graphics.DrawLine .... but
it doesn't make any difference if I do.

Thank you
Colin


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
What happens then ?
Colin McGuire wrote:
> I apologize for posting yet another scrollbar question. Here is my
> code. All I want is for a diagonal line to appear from coordinates
> (0,0) to (width,height) in a usercontrol regardless of whether the
> user autoscrolls the usercontrol (other things that are on the
> usercontrol I want to scroll, but haven't included any here).
>
> Here are the steps to reproduce my problem.
>
> 1. Launch Visual Studio and create a new Windows
> application with "Form1".
> 2. Paste the following in (remember to include
> your "Windows Form Designer generated code).
> 3. Run - instructions are in the program that runs.
>
> I am using "Microsoft Development Environment 2003, Version
> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
> 1.1.4322"
>
> Thank you for your patience with me.
> Colin
>
>
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
>
> '======================
> ' Windows Form Designer generated code
> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
> '======================
>
> Public Class UserControl1
> Inherits System.Windows.Forms.UserControl
> Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
> MyBase.OnPaint(p)
> p.Graphics.DrawLine(New Pen(Color.Black), _
> clientRectangle.Width, _
> ClientRectangle.Height, _
> 0, 0)
> End Sub
>
> Private Sub UserControl1_Load(ByVal sender As
> System.Object, _ ByVal e As System.EventArgs) _
> Handles MyBase.Load
> Me.BackColor = Color.Yellow
> End Sub
> End Class
>
>
> Private Sub Form1_Load(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim uc As New UserControl1
> uc.Location = New Point(0, 0)
> uc.Size = New System.Drawing.Size(New Point(100, 100))
> uc.BackColor = Color.Yellow
> uc.AutoScroll = True
> uc.AutoScrollMinSize = New Size(New Point(200, 300))
> uc.Visible = True
> Me.Controls.Add(uc)
> Size = New Size(New Point(300, 300))
>
> Dim lb As New Label
> lb.Location = New Point(0, 150)
> lb.Size = New Size(290, 80)
> lb.Text = "1.Move the scrollbars,the diagonal line isn't"
> + _ " drawn from(0,0) to (width,height).
> 2.Minimize" + _ " this form. 3. Restore the form
> size,now the " + _ "line does go from (0,0) to
> (width,height). " + _ "Why, why isn't the
> diagonal line and " + _ "control background
> cleared as you scroll?" Me.Controls.Add(lb)
> End Sub
> End Class

Nov 20 '05 #17
The diagonal was just a line to use for testing purposes. Really what I am
doing is drawing a ruler at the top of the usercontrol, everything in the
usercontrol should appear to scroll except the ruler at the top which should
appear to stay in the same position.

On my system
hexathioorthooxalate's solution works
Brians does not, when I add

Public Sub New()
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

it behaves the same and doesn't draw the diagonal correctly.
Never-the-less, it is working now and thank you OHM, hexathioorthooxalate,
and Brian.

Colin

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
Just out of curiosity, was this requirement to demonstrate to the UI user
that this control was disabled in some way ?

Colin McGuire wrote:
OHM, I am sorry - I have seen this mentioned before and have never
understood it. I know I'm close and the cigar eludes me. Any chance of
coaching me on just a little further?
Here is what I think what you mean from your latest post, and as I
have implemented it is wrong because I get an a box showing up in my
IDE saying "'VScroll' is not an event of
WindowsApplication15.Form1.UserControl1'".

What I did to my original code was

Step 1: Added the following to UserControl1_Load

AddHandler VScroll, AddressOf capturedVScroll

Step 2: Added the following to the code in UserControl1

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub
My final code therefore looks like this, but just one more tweak is
necessary before I can get it to compile and work.

Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.Clear(BackColor)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
AddHandler VScroll, AddressOf capturedVScroll 'ERROR HERE
End Sub

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub

End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
You need to repaint on VScroll. Your user control inherits from
Scrollable class and this event is protected so as you have
inherited this you should be able to add a handler and force the
control to repaint.


Colin McGuire wrote:
You're not going to make me thank you again I hope :)

Here is some more elaboration of my problem.

What I see is:

1. When I move the vertical scrollbar by clicking "in"
the scrollbar (ie between the up arrow and down arrow),
the diagonal line is drawn properly (diagram below).

+----------+
|\ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
+----------+

2. When I click the "down arrow" button on the vertical
scrollbar, the diagonal scrolls, but I can see a tiny
bit of the new diagonal showing up - sort of looks like

+---\-------+
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
| |
| |
| \|
+-----------+

3. When I add a Debug.WriteLine("OnPaint") inside
the OnPaint method, both clicking "in" the scrollbar
and clicking the up or down arrow of the scrollbar
appear produce "OnPaint" in the IDE debug window.

4. When I minimise this (corrupted window, step 2), then
maximize it again, then it redraws properly with
the diagonal from (0,0) to (width,height) as shown
in Step 1.

BTW: I forgot to paste in the

p.Graphics.Clear(BackColor)

in my original post before the
p.Graphics.DrawLine .... but
it doesn't make any difference if I do.

Thank you
Colin


"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@hercules.btinternet.com...
> What happens then ?
>
>
> Colin McGuire wrote:
>> I apologize for posting yet another scrollbar question. Here is my
>> code. All I want is for a diagonal line to appear from coordinates
>> (0,0) to (width,height) in a usercontrol regardless of whether the
>> user autoscrolls the usercontrol (other things that are on the
>> usercontrol I want to scroll, but haven't included any here).
>>
>> Here are the steps to reproduce my problem.
>>
>> 1. Launch Visual Studio and create a new Windows
>> application with "Form1".
>> 2. Paste the following in (remember to include
>> your "Windows Form Designer generated code).
>> 3. Run - instructions are in the program that runs.
>>
>> I am using "Microsoft Development Environment 2003, Version
>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>> 1.1.4322"
>>
>> Thank you for your patience with me.
>> Colin
>>
>>
>>
>> Public Class Form1
>> Inherits System.Windows.Forms.Form
>>
>> '======================
>> ' Windows Form Designer generated code
>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>> '======================
>>
>> Public Class UserControl1
>> Inherits System.Windows.Forms.UserControl
>> Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
>> MyBase.OnPaint(p)
>> p.Graphics.DrawLine(New Pen(Color.Black), _
>> clientRectangle.Width, _
>> ClientRectangle.Height, _
>> 0, 0)
>> End Sub
>>
>> Private Sub UserControl1_Load(ByVal sender As
>> System.Object, _ ByVal e As System.EventArgs) _
>> Handles MyBase.Load
>> Me.BackColor = Color.Yellow
>> End Sub
>> End Class
>>
>>
>> Private Sub Form1_Load(ByVal sender As System.Object, _
>> ByVal e As System.EventArgs) Handles MyBase.Load
>> Dim uc As New UserControl1
>> uc.Location = New Point(0, 0)
>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>> uc.BackColor = Color.Yellow
>> uc.AutoScroll = True
>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>> uc.Visible = True
>> Me.Controls.Add(uc)
>> Size = New Size(New Point(300, 300))
>>
>> Dim lb As New Label
>> lb.Location = New Point(0, 150)
>> lb.Size = New Size(290, 80)
>> lb.Text = "1.Move the scrollbars,the diagonal line isn't"
>> + _ " drawn from(0,0) to (width,height).
>> 2.Minimize" + _ " this form. 3. Restore the form
>> size,now the " + _ "line does go from (0,0) to
>> (width,height). " + _ "Why, why isn't the
>> diagonal line and " + _ "control background
>> cleared as you scroll?" Me.Controls.Add(lb)
>> End Sub
>> End Class



Nov 20 '05 #18
Oops, I should have mentioned that the code I gave you is for when the
control is being resized. It's basically used to prevent flickering
of the control. I don't believe it has any effect during runtime
(except during the controls resize event). That's why you said it didn't
work, it's because it didn't. Using Invalidate() will erase the entire form.



"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether the
user autoscrolls the usercontrol (other things that are on the
usercontrol I want to scroll, but haven't included any here).

Here are the steps to reproduce my problem.

1. Launch Visual Studio and create a new Windows
application with "Form1".
2. Paste the following in (remember to include
your "Windows Form Designer generated code).
3. Run - instructions are in the program that runs.

I am using "Microsoft Development Environment 2003, Version 7.1.3088".
I am using "Microsoft .NET Framework 1.1, Version 1.1.4322"

Thank you for your patience with me.
Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" + _
" drawn from(0,0) to (width,height). 2.Minimize" + _
" this form. 3. Restore the form size,now the " + _
"line does go from (0,0) to (width,height). " + _
"Why, why isn't the diagonal line and " + _
"control background cleared as you scroll?"
Me.Controls.Add(lb)
End Sub
End Class

Nov 20 '05 #19
Top marks to hexathioorthooxalate's for this. This is something i've learnt
and wont forget.

BTW hex, what does you name mean exactly. "hex =HEX 'athioorthoo'
xalate's = TRANSLATES"
Have you run some algorithm against your name which is in the centre ?

OHM

Colin McGuire wrote:
The diagonal was just a line to use for testing purposes. Really what
I am doing is drawing a ruler at the top of the usercontrol,
everything in the usercontrol should appear to scroll except the
ruler at the top which should appear to stay in the same position.

On my system
hexathioorthooxalate's solution works
Brians does not, when I add

Public Sub New()
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

it behaves the same and doesn't draw the diagonal correctly.
Never-the-less, it is working now and thank you OHM,
hexathioorthooxalate, and Brian.

Colin

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
Just out of curiosity, was this requirement to demonstrate to the UI
user that this control was disabled in some way ?

Colin McGuire wrote:
OHM, I am sorry - I have seen this mentioned before and have never
understood it. I know I'm close and the cigar eludes me. Any chance
of coaching me on just a little further?
Here is what I think what you mean from your latest post, and as I
have implemented it is wrong because I get an a box showing up in my
IDE saying "'VScroll' is not an event of
WindowsApplication15.Form1.UserControl1'".

What I did to my original code was

Step 1: Added the following to UserControl1_Load

AddHandler VScroll, AddressOf capturedVScroll

Step 2: Added the following to the code in UserControl1

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub
My final code therefore looks like this, but just one more tweak is
necessary before I can get it to compile and work.

Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.Clear(BackColor)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As
System.Object, _ ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
AddHandler VScroll, AddressOf capturedVScroll 'ERROR
HERE End Sub

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub

End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" +
_ " drawn from(0,0) to (width,height).
2.Minimize" + _ " this form. 3. Restore the form
size,now the " + _ "line does go from (0,0) to
(width,height). " + _ "Why, why isn't the
diagonal line and " + _ "control background
cleared as you scroll?" Me.Controls.Add(lb)
End Sub
End Class

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
You need to repaint on VScroll. Your user control inherits from
Scrollable class and this event is protected so as you have
inherited this you should be able to add a handler and force the
control to repaint.


Colin McGuire wrote:
> You're not going to make me thank you again I hope :)
>
> Here is some more elaboration of my problem.
>
> What I see is:
>
> 1. When I move the vertical scrollbar by clicking "in"
> the scrollbar (ie between the up arrow and down arrow),
> the diagonal line is drawn properly (diagram below).
>
> +----------+
> |\ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \|
> +----------+
>
> 2. When I click the "down arrow" button on the vertical
> scrollbar, the diagonal scrolls, but I can see a tiny
> bit of the new diagonal showing up - sort of looks like
>
> +---\-------+
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \ |
> | \|
> | |
> | |
> | \|
> +-----------+
>
> 3. When I add a Debug.WriteLine("OnPaint") inside
> the OnPaint method, both clicking "in" the scrollbar
> and clicking the up or down arrow of the scrollbar
> appear produce "OnPaint" in the IDE debug window.
>
> 4. When I minimise this (corrupted window, step 2), then
> maximize it again, then it redraws properly with
> the diagonal from (0,0) to (width,height) as shown
> in Step 1.
>
> BTW: I forgot to paste in the
>
> p.Graphics.Clear(BackColor)
>
> in my original post before the
> p.Graphics.DrawLine .... but
> it doesn't make any difference if I do.
>
> Thank you
> Colin
>
>
>
>
>
>
> "One Handed Man" <Bo****@Duck.net> wrote in message
> news:bl**********@hercules.btinternet.com...
>> What happens then ?
>>
>>
>> Colin McGuire wrote:
>>> I apologize for posting yet another scrollbar question. Here is
>>> my code. All I want is for a diagonal line to appear from
>>> coordinates (0,0) to (width,height) in a usercontrol regardless
>>> of whether the user autoscrolls the usercontrol (other things
>>> that are on the usercontrol I want to scroll, but haven't
>>> included any here).
>>>
>>> Here are the steps to reproduce my problem.
>>>
>>> 1. Launch Visual Studio and create a new Windows
>>> application with "Form1".
>>> 2. Paste the following in (remember to include
>>> your "Windows Form Designer generated code).
>>> 3. Run - instructions are in the program that runs.
>>>
>>> I am using "Microsoft Development Environment 2003, Version
>>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>>> 1.1.4322"
>>>
>>> Thank you for your patience with me.
>>> Colin
>>>
>>>
>>>
>>> Public Class Form1
>>> Inherits System.Windows.Forms.Form
>>>
>>> '======================
>>> ' Windows Form Designer generated code
>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>> '======================
>>>
>>> Public Class UserControl1
>>> Inherits System.Windows.Forms.UserControl
>>> Protected Overrides Sub OnPaint(ByVal p As
>>> PaintEventArgs) MyBase.OnPaint(p)
>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>> clientRectangle.Width, _
>>> ClientRectangle.Height, _
>>> 0, 0)
>>> End Sub
>>>
>>> Private Sub UserControl1_Load(ByVal sender As
>>> System.Object, _ ByVal e As System.EventArgs) _
>>> Handles MyBase.Load
>>> Me.BackColor = Color.Yellow
>>> End Sub
>>> End Class
>>>
>>>
>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>> Dim uc As New UserControl1
>>> uc.Location = New Point(0, 0)
>>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>>> uc.BackColor = Color.Yellow
>>> uc.AutoScroll = True
>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>> uc.Visible = True
>>> Me.Controls.Add(uc)
>>> Size = New Size(New Point(300, 300))
>>>
>>> Dim lb As New Label
>>> lb.Location = New Point(0, 150)
>>> lb.Size = New Size(290, 80)
>>> lb.Text = "1.Move the scrollbars,the diagonal line
>>> isn't" + _ " drawn from(0,0) to
>>> (width,height).
>>> 2.Minimize" + _ " this form. 3. Restore the
>>> form size,now the " + _ "line does go from
>>> (0,0) to (width,height). " + _ "Why, why
>>> isn't the diagonal line and " + _ "control
>>> background cleared as you scroll?" Me.Controls.Add(lb)
>>> End Sub
>>> End Class

Nov 20 '05 #20
Thanks for the compiliment.

The name, just a non de plume - a class of compound I used to make as a
chemistry undergraduate.

Bye.

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@sparta.btinternet.com...
Top marks to hexathioorthooxalate's for this. This is something i've learnt and wont forget.

BTW hex, what does you name mean exactly. "hex =HEX 'athioorthoo'
xalate's = TRANSLATES"
Have you run some algorithm against your name which is in the centre ?

OHM

Colin McGuire wrote:
The diagonal was just a line to use for testing purposes. Really what
I am doing is drawing a ruler at the top of the usercontrol,
everything in the usercontrol should appear to scroll except the
ruler at the top which should appear to stay in the same position.

On my system
hexathioorthooxalate's solution works
Brians does not, when I add

Public Sub New()
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

it behaves the same and doesn't draw the diagonal correctly.
Never-the-less, it is working now and thank you OHM,
hexathioorthooxalate, and Brian.

Colin

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
Just out of curiosity, was this requirement to demonstrate to the UI
user that this control was disabled in some way ?

Colin McGuire wrote:
OHM, I am sorry - I have seen this mentioned before and have never
understood it. I know I'm close and the cigar eludes me. Any chance
of coaching me on just a little further?
Here is what I think what you mean from your latest post, and as I
have implemented it is wrong because I get an a box showing up in my
IDE saying "'VScroll' is not an event of
WindowsApplication15.Form1.UserControl1'".

What I did to my original code was

Step 1: Added the following to UserControl1_Load

AddHandler VScroll, AddressOf capturedVScroll

Step 2: Added the following to the code in UserControl1

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub
My final code therefore looks like this, but just one more tweak is
necessary before I can get it to compile and work.

Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'======================
' Windows Form Designer generated code
' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
'======================

Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
MyBase.OnPaint(p)
p.Graphics.Clear(BackColor)
p.Graphics.DrawLine(New Pen(Color.Black), _
clientRectangle.Width, _
ClientRectangle.Height, _
0, 0)
End Sub

Private Sub UserControl1_Load(ByVal sender As
System.Object, _ ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.BackColor = Color.Yellow
AddHandler VScroll, AddressOf capturedVScroll 'ERROR
HERE End Sub

Private Sub capturedVScroll(ByVal sender As Object, _
ByVal e As System.EventArgs)
Debug.WriteLine("capturedVScroll")
End Sub

End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim uc As New UserControl1
uc.Location = New Point(0, 0)
uc.Size = New System.Drawing.Size(New Point(100, 100))
uc.BackColor = Color.Yellow
uc.AutoScroll = True
uc.AutoScrollMinSize = New Size(New Point(200, 300))
uc.Visible = True
Me.Controls.Add(uc)
Size = New Size(New Point(300, 300))

Dim lb As New Label
lb.Location = New Point(0, 150)
lb.Size = New Size(290, 80)
lb.Text = "1.Move the scrollbars,the diagonal line isn't" +
_ " drawn from(0,0) to (width,height).
2.Minimize" + _ " this form. 3. Restore the form
size,now the " + _ "line does go from (0,0) to
(width,height). " + _ "Why, why isn't the
diagonal line and " + _ "control background
cleared as you scroll?" Me.Controls.Add(lb)
End Sub
End Class

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
> You need to repaint on VScroll. Your user control inherits from
> Scrollable class and this event is protected so as you have
> inherited this you should be able to add a handler and force the
> control to repaint.
>
>
>
>
>
>
> Colin McGuire wrote:
>> You're not going to make me thank you again I hope :)
>>
>> Here is some more elaboration of my problem.
>>
>> What I see is:
>>
>> 1. When I move the vertical scrollbar by clicking "in"
>> the scrollbar (ie between the up arrow and down arrow),
>> the diagonal line is drawn properly (diagram below).
>>
>> +----------+
>> |\ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \|
>> +----------+
>>
>> 2. When I click the "down arrow" button on the vertical
>> scrollbar, the diagonal scrolls, but I can see a tiny
>> bit of the new diagonal showing up - sort of looks like
>>
>> +---\-------+
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \ |
>> | \|
>> | |
>> | |
>> | \|
>> +-----------+
>>
>> 3. When I add a Debug.WriteLine("OnPaint") inside
>> the OnPaint method, both clicking "in" the scrollbar
>> and clicking the up or down arrow of the scrollbar
>> appear produce "OnPaint" in the IDE debug window.
>>
>> 4. When I minimise this (corrupted window, step 2), then
>> maximize it again, then it redraws properly with
>> the diagonal from (0,0) to (width,height) as shown
>> in Step 1.
>>
>> BTW: I forgot to paste in the
>>
>> p.Graphics.Clear(BackColor)
>>
>> in my original post before the
>> p.Graphics.DrawLine .... but
>> it doesn't make any difference if I do.
>>
>> Thank you
>> Colin
>>
>>
>>
>>
>>
>>
>> "One Handed Man" <Bo****@Duck.net> wrote in message
>> news:bl**********@hercules.btinternet.com...
>>> What happens then ?
>>>
>>>
>>> Colin McGuire wrote:
>>>> I apologize for posting yet another scrollbar question. Here is
>>>> my code. All I want is for a diagonal line to appear from
>>>> coordinates (0,0) to (width,height) in a usercontrol regardless
>>>> of whether the user autoscrolls the usercontrol (other things
>>>> that are on the usercontrol I want to scroll, but haven't
>>>> included any here).
>>>>
>>>> Here are the steps to reproduce my problem.
>>>>
>>>> 1. Launch Visual Studio and create a new Windows
>>>> application with "Form1".
>>>> 2. Paste the following in (remember to include
>>>> your "Windows Form Designer generated code).
>>>> 3. Run - instructions are in the program that runs.
>>>>
>>>> I am using "Microsoft Development Environment 2003, Version
>>>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>>>> 1.1.4322"
>>>>
>>>> Thank you for your patience with me.
>>>> Colin
>>>>
>>>>
>>>>
>>>> Public Class Form1
>>>> Inherits System.Windows.Forms.Form
>>>>
>>>> '======================
>>>> ' Windows Form Designer generated code
>>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>>> '======================
>>>>
>>>> Public Class UserControl1
>>>> Inherits System.Windows.Forms.UserControl
>>>> Protected Overrides Sub OnPaint(ByVal p As
>>>> PaintEventArgs) MyBase.OnPaint(p)
>>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>>> clientRectangle.Width, _
>>>> ClientRectangle.Height, _
>>>> 0, 0)
>>>> End Sub
>>>>
>>>> Private Sub UserControl1_Load(ByVal sender As
>>>> System.Object, _ ByVal e As System.EventArgs) _
>>>> Handles MyBase.Load
>>>> Me.BackColor = Color.Yellow
>>>> End Sub
>>>> End Class
>>>>
>>>>
>>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>>> Dim uc As New UserControl1
>>>> uc.Location = New Point(0, 0)
>>>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>>>> uc.BackColor = Color.Yellow
>>>> uc.AutoScroll = True
>>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>>> uc.Visible = True
>>>> Me.Controls.Add(uc)
>>>> Size = New Size(New Point(300, 300))
>>>>
>>>> Dim lb As New Label
>>>> lb.Location = New Point(0, 150)
>>>> lb.Size = New Size(290, 80)
>>>> lb.Text = "1.Move the scrollbars,the diagonal line
>>>> isn't" + _ " drawn from(0,0) to
>>>> (width,height).
>>>> 2.Minimize" + _ " this form. 3. Restore the
>>>> form size,now the " + _ "line does go from
>>>> (0,0) to (width,height). " + _ "Why, why
>>>> isn't the diagonal line and " + _ "control
>>>> background cleared as you scroll?" Me.Controls.Add(lb)
>>>> End Sub
>>>> End Class



Nov 20 '05 #21
Cheers Mate
hexathioorthooxalate wrote:
Thanks for the compiliment.

The name, just a non de plume - a class of compound I used to make as
a chemistry undergraduate.

Bye.

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@sparta.btinternet.com...
Top marks to hexathioorthooxalate's for this. This is something i've
learnt and wont forget.

BTW hex, what does you name mean exactly. "hex =HEX 'athioorthoo'
xalate's = TRANSLATES"
Have you run some algorithm against your name which is in the centre
?

OHM

Colin McGuire wrote:
The diagonal was just a line to use for testing purposes. Really
what I am doing is drawing a ruler at the top of the usercontrol,
everything in the usercontrol should appear to scroll except the
ruler at the top which should appear to stay in the same position.

On my system
hexathioorthooxalate's solution works
Brians does not, when I add

Public Sub New()
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

it behaves the same and doesn't draw the diagonal correctly.
Never-the-less, it is working now and thank you OHM,
hexathioorthooxalate, and Brian.

Colin

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
Just out of curiosity, was this requirement to demonstrate to the
UI user that this control was disabled in some way ?

Colin McGuire wrote:
> OHM, I am sorry - I have seen this mentioned before and have never
> understood it. I know I'm close and the cigar eludes me. Any
> chance of coaching me on just a little further?
>
>
> Here is what I think what you mean from your latest post, and as I
> have implemented it is wrong because I get an a box showing up in
> my IDE saying "'VScroll' is not an event of
> WindowsApplication15.Form1.UserControl1'".
>
> What I did to my original code was
>
> Step 1: Added the following to UserControl1_Load
>
> AddHandler VScroll, AddressOf capturedVScroll
>
> Step 2: Added the following to the code in UserControl1
>
> Private Sub capturedVScroll(ByVal sender As Object, _
> ByVal e As System.EventArgs)
> Debug.WriteLine("capturedVScroll")
> End Sub
>
>
> My final code therefore looks like this, but just one more tweak
> is necessary before I can get it to compile and work.
>
> Colin
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
>
> '======================
> ' Windows Form Designer generated code
> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
> '======================
>
> Public Class UserControl1
> Inherits System.Windows.Forms.UserControl
> Protected Overrides Sub OnPaint(ByVal p As PaintEventArgs)
> MyBase.OnPaint(p)
> p.Graphics.Clear(BackColor)
> p.Graphics.DrawLine(New Pen(Color.Black), _
> clientRectangle.Width, _
> ClientRectangle.Height, _
> 0, 0)
> End Sub
>
> Private Sub UserControl1_Load(ByVal sender As
> System.Object, _ ByVal e As System.EventArgs) _
> Handles MyBase.Load
> Me.BackColor = Color.Yellow
> AddHandler VScroll, AddressOf capturedVScroll 'ERROR
> HERE End Sub
>
> Private Sub capturedVScroll(ByVal sender As Object, _
> ByVal e As System.EventArgs)
> Debug.WriteLine("capturedVScroll")
> End Sub
>
> End Class
>
>
> Private Sub Form1_Load(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim uc As New UserControl1
> uc.Location = New Point(0, 0)
> uc.Size = New System.Drawing.Size(New Point(100, 100))
> uc.BackColor = Color.Yellow
> uc.AutoScroll = True
> uc.AutoScrollMinSize = New Size(New Point(200, 300))
> uc.Visible = True
> Me.Controls.Add(uc)
> Size = New Size(New Point(300, 300))
>
> Dim lb As New Label
> lb.Location = New Point(0, 150)
> lb.Size = New Size(290, 80)
> lb.Text = "1.Move the scrollbars,the diagonal line isn't"
> + _ " drawn from(0,0) to (width,height).
> 2.Minimize" + _ " this form. 3. Restore the form
> size,now the " + _ "line does go from (0,0) to
> (width,height). " + _ "Why, why isn't the
> diagonal line and " + _ "control background
> cleared as you scroll?" Me.Controls.Add(lb)
> End Sub
> End Class
>
>
>
> "One Handed Man" <Bo****@Duck.net> wrote in message
> news:bl**********@titan.btinternet.com...
>> You need to repaint on VScroll. Your user control inherits from
>> Scrollable class and this event is protected so as you have
>> inherited this you should be able to add a handler and force the
>> control to repaint.
>>
>>
>>
>>
>>
>>
>> Colin McGuire wrote:
>>> You're not going to make me thank you again I hope :)
>>>
>>> Here is some more elaboration of my problem.
>>>
>>> What I see is:
>>>
>>> 1. When I move the vertical scrollbar by clicking "in"
>>> the scrollbar (ie between the up arrow and down arrow),
>>> the diagonal line is drawn properly (diagram below).
>>>
>>> +----------+
>>> |\ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \|
>>> +----------+
>>>
>>> 2. When I click the "down arrow" button on the vertical
>>> scrollbar, the diagonal scrolls, but I can see a tiny
>>> bit of the new diagonal showing up - sort of looks like
>>>
>>> +---\-------+
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \ |
>>> | \|
>>> | |
>>> | |
>>> | \|
>>> +-----------+
>>>
>>> 3. When I add a Debug.WriteLine("OnPaint") inside
>>> the OnPaint method, both clicking "in" the scrollbar
>>> and clicking the up or down arrow of the scrollbar
>>> appear produce "OnPaint" in the IDE debug window.
>>>
>>> 4. When I minimise this (corrupted window, step 2), then
>>> maximize it again, then it redraws properly with
>>> the diagonal from (0,0) to (width,height) as shown
>>> in Step 1.
>>>
>>> BTW: I forgot to paste in the
>>>
>>> p.Graphics.Clear(BackColor)
>>>
>>> in my original post before the
>>> p.Graphics.DrawLine .... but
>>> it doesn't make any difference if I do.
>>>
>>> Thank you
>>> Colin
>>>
>>>
>>>
>>>
>>>
>>>
>>> "One Handed Man" <Bo****@Duck.net> wrote in message
>>> news:bl**********@hercules.btinternet.com...
>>>> What happens then ?
>>>>
>>>>
>>>> Colin McGuire wrote:
>>>>> I apologize for posting yet another scrollbar question. Here
>>>>> is my code. All I want is for a diagonal line to appear from
>>>>> coordinates (0,0) to (width,height) in a usercontrol
>>>>> regardless of whether the user autoscrolls the usercontrol
>>>>> (other things that are on the usercontrol I want to scroll,
>>>>> but haven't included any here).
>>>>>
>>>>> Here are the steps to reproduce my problem.
>>>>>
>>>>> 1. Launch Visual Studio and create a new Windows
>>>>> application with "Form1".
>>>>> 2. Paste the following in (remember to include
>>>>> your "Windows Form Designer generated code).
>>>>> 3. Run - instructions are in the program that runs.
>>>>>
>>>>> I am using "Microsoft Development Environment 2003, Version
>>>>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>>>>> 1.1.4322"
>>>>>
>>>>> Thank you for your patience with me.
>>>>> Colin
>>>>>
>>>>>
>>>>>
>>>>> Public Class Form1
>>>>> Inherits System.Windows.Forms.Form
>>>>>
>>>>> '======================
>>>>> ' Windows Form Designer generated code
>>>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>>>> '======================
>>>>>
>>>>> Public Class UserControl1
>>>>> Inherits System.Windows.Forms.UserControl
>>>>> Protected Overrides Sub OnPaint(ByVal p As
>>>>> PaintEventArgs) MyBase.OnPaint(p)
>>>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>>>> clientRectangle.Width, _
>>>>> ClientRectangle.Height, _
>>>>> 0, 0)
>>>>> End Sub
>>>>>
>>>>> Private Sub UserControl1_Load(ByVal sender As
>>>>> System.Object, _ ByVal e As System.EventArgs) _
>>>>> Handles MyBase.Load
>>>>> Me.BackColor = Color.Yellow
>>>>> End Sub
>>>>> End Class
>>>>>
>>>>>
>>>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>>>> Dim uc As New UserControl1
>>>>> uc.Location = New Point(0, 0)
>>>>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>>>>> uc.BackColor = Color.Yellow
>>>>> uc.AutoScroll = True
>>>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>>>> uc.Visible = True
>>>>> Me.Controls.Add(uc)
>>>>> Size = New Size(New Point(300, 300))
>>>>>
>>>>> Dim lb As New Label
>>>>> lb.Location = New Point(0, 150)
>>>>> lb.Size = New Size(290, 80)
>>>>> lb.Text = "1.Move the scrollbars,the diagonal line
>>>>> isn't" + _ " drawn from(0,0) to
>>>>> (width,height).
>>>>> 2.Minimize" + _ " this form. 3. Restore the
>>>>> form size,now the " + _ "line does go from
>>>>> (0,0) to (width,height). " + _ "Why, why
>>>>> isn't the diagonal line and " + _ "control
>>>>> background cleared as you scroll?" Me.Controls.Add(lb)
>>>>> End Sub
>>>>> End Class

Nov 20 '05 #22
Nope, forget that. he already did.

OHM
One Handed Man wrote:
Cheers Mate
hexathioorthooxalate wrote:
Thanks for the compiliment.

The name, just a non de plume - a class of compound I used to make as
a chemistry undergraduate.

Bye.

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@sparta.btinternet.com...
Top marks to hexathioorthooxalate's for this. This is something i've
learnt and wont forget.

BTW hex, what does you name mean exactly. "hex =HEX
'athioorthoo' xalate's = TRANSLATES"
Have you run some algorithm against your name which is in the centre
?

OHM

Colin McGuire wrote:
The diagonal was just a line to use for testing purposes. Really
what I am doing is drawing a ruler at the top of the usercontrol,
everything in the usercontrol should appear to scroll except the
ruler at the top which should appear to stay in the same position.

On my system
hexathioorthooxalate's solution works
Brians does not, when I add

Public Sub New()
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

it behaves the same and doesn't draw the diagonal correctly.
Never-the-less, it is working now and thank you OHM,
hexathioorthooxalate, and Brian.

Colin

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
> Just out of curiosity, was this requirement to demonstrate to the
> UI user that this control was disabled in some way ?
>
> Colin McGuire wrote:
>> OHM, I am sorry - I have seen this mentioned before and have
>> never understood it. I know I'm close and the cigar eludes me.
>> Any chance of coaching me on just a little further?
>>
>>
>> Here is what I think what you mean from your latest post, and as
>> I have implemented it is wrong because I get an a box showing up
>> in my IDE saying "'VScroll' is not an event of
>> WindowsApplication15.Form1.UserControl1'".
>>
>> What I did to my original code was
>>
>> Step 1: Added the following to UserControl1_Load
>>
>> AddHandler VScroll, AddressOf capturedVScroll
>>
>> Step 2: Added the following to the code in UserControl1
>>
>> Private Sub capturedVScroll(ByVal sender As Object, _
>> ByVal e As System.EventArgs)
>> Debug.WriteLine("capturedVScroll")
>> End Sub
>>
>>
>> My final code therefore looks like this, but just one more tweak
>> is necessary before I can get it to compile and work.
>>
>> Colin
>>
>> Public Class Form1
>> Inherits System.Windows.Forms.Form
>>
>> '======================
>> ' Windows Form Designer generated code
>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>> '======================
>>
>> Public Class UserControl1
>> Inherits System.Windows.Forms.UserControl
>> Protected Overrides Sub OnPaint(ByVal p As
>> PaintEventArgs) MyBase.OnPaint(p)
>> p.Graphics.Clear(BackColor)
>> p.Graphics.DrawLine(New Pen(Color.Black), _
>> clientRectangle.Width, _
>> ClientRectangle.Height, _
>> 0, 0)
>> End Sub
>>
>> Private Sub UserControl1_Load(ByVal sender As
>> System.Object, _ ByVal e As System.EventArgs) _
>> Handles MyBase.Load
>> Me.BackColor = Color.Yellow
>> AddHandler VScroll, AddressOf capturedVScroll 'ERROR
>> HERE End Sub
>>
>> Private Sub capturedVScroll(ByVal sender As Object, _
>> ByVal e As System.EventArgs)
>> Debug.WriteLine("capturedVScroll")
>> End Sub
>>
>> End Class
>>
>>
>> Private Sub Form1_Load(ByVal sender As System.Object, _
>> ByVal e As System.EventArgs) Handles MyBase.Load
>> Dim uc As New UserControl1
>> uc.Location = New Point(0, 0)
>> uc.Size = New System.Drawing.Size(New Point(100, 100))
>> uc.BackColor = Color.Yellow
>> uc.AutoScroll = True
>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>> uc.Visible = True
>> Me.Controls.Add(uc)
>> Size = New Size(New Point(300, 300))
>>
>> Dim lb As New Label
>> lb.Location = New Point(0, 150)
>> lb.Size = New Size(290, 80)
>> lb.Text = "1.Move the scrollbars,the diagonal line isn't"
>> + _ " drawn from(0,0) to (width,height).
>> 2.Minimize" + _ " this form. 3. Restore the
>> form size,now the " + _ "line does go from
>> (0,0) to (width,height). " + _ "Why, why isn't
>> the diagonal line and " + _ "control background
>> cleared as you scroll?" Me.Controls.Add(lb)
>> End Sub
>> End Class
>>
>>
>>
>> "One Handed Man" <Bo****@Duck.net> wrote in message
>> news:bl**********@titan.btinternet.com...
>>> You need to repaint on VScroll. Your user control inherits
>>> from Scrollable class and this event is protected so as you have
>>> inherited this you should be able to add a handler and force the
>>> control to repaint.
>>>
>>>
>>>
>>>
>>>
>>>
>>> Colin McGuire wrote:
>>>> You're not going to make me thank you again I hope :)
>>>>
>>>> Here is some more elaboration of my problem.
>>>>
>>>> What I see is:
>>>>
>>>> 1. When I move the vertical scrollbar by clicking "in"
>>>> the scrollbar (ie between the up arrow and down arrow),
>>>> the diagonal line is drawn properly (diagram below).
>>>>
>>>> +----------+
>>>> |\ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \|
>>>> +----------+
>>>>
>>>> 2. When I click the "down arrow" button on the vertical
>>>> scrollbar, the diagonal scrolls, but I can see a tiny
>>>> bit of the new diagonal showing up - sort of looks like
>>>>
>>>> +---\-------+
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \ |
>>>> | \|
>>>> | |
>>>> | |
>>>> | \|
>>>> +-----------+
>>>>
>>>> 3. When I add a Debug.WriteLine("OnPaint") inside
>>>> the OnPaint method, both clicking "in" the scrollbar
>>>> and clicking the up or down arrow of the scrollbar
>>>> appear produce "OnPaint" in the IDE debug window.
>>>>
>>>> 4. When I minimise this (corrupted window, step 2), then
>>>> maximize it again, then it redraws properly with
>>>> the diagonal from (0,0) to (width,height) as shown
>>>> in Step 1.
>>>>
>>>> BTW: I forgot to paste in the
>>>>
>>>> p.Graphics.Clear(BackColor)
>>>>
>>>> in my original post before the
>>>> p.Graphics.DrawLine .... but
>>>> it doesn't make any difference if I do.
>>>>
>>>> Thank you
>>>> Colin
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> "One Handed Man" <Bo****@Duck.net> wrote in message
>>>> news:bl**********@hercules.btinternet.com...
>>>>> What happens then ?
>>>>>
>>>>>
>>>>> Colin McGuire wrote:
>>>>>> I apologize for posting yet another scrollbar question. Here
>>>>>> is my code. All I want is for a diagonal line to appear from
>>>>>> coordinates (0,0) to (width,height) in a usercontrol
>>>>>> regardless of whether the user autoscrolls the usercontrol
>>>>>> (other things that are on the usercontrol I want to scroll,
>>>>>> but haven't included any here).
>>>>>>
>>>>>> Here are the steps to reproduce my problem.
>>>>>>
>>>>>> 1. Launch Visual Studio and create a new Windows
>>>>>> application with "Form1".
>>>>>> 2. Paste the following in (remember to include
>>>>>> your "Windows Form Designer generated code).
>>>>>> 3. Run - instructions are in the program that runs.
>>>>>>
>>>>>> I am using "Microsoft Development Environment 2003, Version
>>>>>> 7.1.3088". I am using "Microsoft .NET Framework 1.1, Version
>>>>>> 1.1.4322"
>>>>>>
>>>>>> Thank you for your patience with me.
>>>>>> Colin
>>>>>>
>>>>>>
>>>>>>
>>>>>> Public Class Form1
>>>>>> Inherits System.Windows.Forms.Form
>>>>>>
>>>>>> '======================
>>>>>> ' Windows Form Designer generated code
>>>>>> ' (INCLUDE HERE FOR FORM1 FROM YOUR IDE, NOT POSTED HERE)
>>>>>> '======================
>>>>>>
>>>>>> Public Class UserControl1
>>>>>> Inherits System.Windows.Forms.UserControl
>>>>>> Protected Overrides Sub OnPaint(ByVal p As
>>>>>> PaintEventArgs) MyBase.OnPaint(p)
>>>>>> p.Graphics.DrawLine(New Pen(Color.Black), _
>>>>>> clientRectangle.Width, _
>>>>>> ClientRectangle.Height, _
>>>>>> 0, 0)
>>>>>> End Sub
>>>>>>
>>>>>> Private Sub UserControl1_Load(ByVal sender As
>>>>>> System.Object, _ ByVal e As System.EventArgs) _
>>>>>> Handles MyBase.Load
>>>>>> Me.BackColor = Color.Yellow
>>>>>> End Sub
>>>>>> End Class
>>>>>>
>>>>>>
>>>>>> Private Sub Form1_Load(ByVal sender As System.Object, _
>>>>>> ByVal e As System.EventArgs) Handles MyBase.Load
>>>>>> Dim uc As New UserControl1
>>>>>> uc.Location = New Point(0, 0)
>>>>>> uc.Size = New System.Drawing.Size(New Point(100,
>>>>>> 100)) uc.BackColor = Color.Yellow
>>>>>> uc.AutoScroll = True
>>>>>> uc.AutoScrollMinSize = New Size(New Point(200, 300))
>>>>>> uc.Visible = True
>>>>>> Me.Controls.Add(uc)
>>>>>> Size = New Size(New Point(300, 300))
>>>>>>
>>>>>> Dim lb As New Label
>>>>>> lb.Location = New Point(0, 150)
>>>>>> lb.Size = New Size(290, 80)
>>>>>> lb.Text = "1.Move the scrollbars,the diagonal line
>>>>>> isn't" + _ " drawn from(0,0) to
>>>>>> (width,height).
>>>>>> 2.Minimize" + _ " this form. 3. Restore the
>>>>>> form size,now the " + _ "line does go from
>>>>>> (0,0) to (width,height). " + _ "Why, why
>>>>>> isn't the diagonal line and " + _ "control
>>>>>> background cleared as you scroll?"
>>>>>> Me.Controls.Add(lb) End Sub
>>>>>> End Class

Nov 20 '05 #23

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Don Schneider | last post by:
I tried to setup a frameset which consists of 4 different subframes. Each of these subframes should fetch a different web page from the internet and display it completely (!). BUT: the vertical...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
5
by: Spondishy | last post by:
Hi, I am using the following in my stylesheet to center divs in firefox. html>body { font-size: 13px; } div.centerdiv {
0
by: Scott Meddows | last post by:
I'm having trouble scrolling some datagrids so they sync up... I have two identical datagrids on a form, filled with eh same dataset. I want a user to be able to scroll on the datasets and the...
2
by: rockermommie | last post by:
so I have this code for my blogger layout and it says that something is not properly closed, I was wondering if someone could find where to fix this. Heres the code: <html> <head> ...
3
by: Tom | last post by:
My user defined vertical scroll bar does not respond properly. :( public VScrollBar vs; .... vs = new VScrollBar(); vs.Parent = this; vs.Dock = DockStyle.Right; I intercept the scrollbar...
1
by: Tom | last post by:
First, I posted a similar request for help in another group and now don't find the posting. Problem with my newsreader perhaps ... but apologies if this appears as a cross posting. My code is...
0
by: AAaron123 | last post by:
hree questions. Number 3 is the tough one! { var htmlStyle = document.getElementsByTagName('html').style; var x = document.body.style; x.scrollbarShadowColor = htmlStyle.scrollbarShadowColor...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.