473,396 Members | 1,816 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,396 software developers and data experts.

Label_Paint event causing a continuous loop. Help needed.

I am having problems with a Label_Paint event causing a continuous loop.
Here is an explanation of the code.

I right click on a label and a context menu pops up.

I then select a menu item named "cmLSolidColor". Here is its code:

Private Sub cmLSolidColor_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmLSolidColor.Click

LabelBackColorSolid()

End Sub

It calls a sub named "LabelBackColorSolid". Here is its code:

Private Sub LabelBackColorSolid()

If ColorDialog1.ShowDialog() = DialogResult.OK Then

If bCMTrigger = True Then

If strCMTrigger = "lblP1JoyUp" Then

lblP1JoyUp.BackColor = (ColorDialog1.Color)

ElseIf strCMTrigger = "lblP1JoyRight" Then

lblP1JoyRight.BackColor = (ColorDialog1.Color)

End if

End if

End if

End Sub

The problem is that the label I'm right clicking on has a Label_Paint event.
Execution goes to the line "LabelBackColorSolid" in the cmlSolidColor_Click
event properly. Then It enters the Private Sub, "LabelBackColorSolid". When
it attempts to read the first line, "If ColorDialog1..." and launch the
dialog box, It immediately triggers the Label_Paint event and enter a
continuous loop. If I pause it in the debugger and then continue the loop
ends, the dialog box pops up, I pick my color, it applies it and all is
well. What can I do to stop this behavior. Is there a way to force it now to
do the Label_Paint event at this point, say, until the end of the
"LabelBackColorSolid" sub is complete?

Thank you,

John
Nov 20 '05 #1
6 1635
No ideas here?

John

"jcrouse" <me> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
I am having problems with a Label_Paint event causing a continuous loop.
Here is an explanation of the code.

I right click on a label and a context menu pops up.

I then select a menu item named "cmLSolidColor". Here is its code:

Private Sub cmLSolidColor_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmLSolidColor.Click

LabelBackColorSolid()

End Sub

It calls a sub named "LabelBackColorSolid". Here is its code:

Private Sub LabelBackColorSolid()

If ColorDialog1.ShowDialog() = DialogResult.OK Then

If bCMTrigger = True Then

If strCMTrigger = "lblP1JoyUp" Then

lblP1JoyUp.BackColor = (ColorDialog1.Color)

ElseIf strCMTrigger = "lblP1JoyRight" Then

lblP1JoyRight.BackColor = (ColorDialog1.Color)

End if

End if

End if

End Sub

The problem is that the label I'm right clicking on has a Label_Paint event. Execution goes to the line "LabelBackColorSolid" in the cmlSolidColor_Click event properly. Then It enters the Private Sub, "LabelBackColorSolid". When it attempts to read the first line, "If ColorDialog1..." and launch the
dialog box, It immediately triggers the Label_Paint event and enter a
continuous loop. If I pause it in the debugger and then continue the loop
ends, the dialog box pops up, I pick my color, it applies it and all is
well. What can I do to stop this behavior. Is there a way to force it now to do the Label_Paint event at this point, say, until the end of the
"LabelBackColorSolid" sub is complete?

Thank you,

John

Nov 20 '05 #2
John,

What is the code in your label paint event? I cannot see how the continuous
loop is happening from what you posted.
do the Label_Paint event at this point, say, until the end of the
"LabelBackColorSolid" sub is complete?

This will temporarily turn off the paint event, but something seems amiss to
have to do this...

Private Sub LabelBackColorSolid()
RemoveHandler Label1.Paint, AddressOf Label1_Paint ' Stop handling
events.

If ColorDialog1.ShowDialog() = DialogResult.OK Then
' do stuff
End If

AddHandler Label1.Paint, AddressOf Label1_Paint
End Sub

HTH,
Greg

"jcrouse" <me> wrote in message
news:e1**************@TK2MSFTNGP09.phx.gbl... No ideas here?

John

"jcrouse" <me> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...

Nov 20 '05 #3
Add a module level Boolean to state that you are in the
LabelBackColorSolid function. Check this variable in the Label_Paint
event. If set exit sub.

HTH

David

"jcrouse" <me> wrote in message
news:e1**************@TK2MSFTNGP09.phx.gbl:
No ideas here?

John

"jcrouse" <me> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
I am having problems with a Label_Paint event causing a continuous
loop.
Here is an explanation of the code.

I right click on a label and a context menu pops up.

I then select a menu item named "cmLSolidColor". Here is its code:

Private Sub cmLSolidColor_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles cmLSolidColor.Click

LabelBackColorSolid()

End Sub

It calls a sub named "LabelBackColorSolid". Here is its code:

Private Sub LabelBackColorSolid()

If ColorDialog1.ShowDialog() = DialogResult.OK Then

If bCMTrigger = True Then

If strCMTrigger = "lblP1JoyUp" Then

lblP1JoyUp.BackColor = (ColorDialog1.Color)

ElseIf strCMTrigger = "lblP1JoyRight" Then

lblP1JoyRight.BackColor = (ColorDialog1.Color)

End if

End if

End if

End Sub

The problem is that the label I'm right clicking on has a Label_Paint

event.
Execution goes to the line "LabelBackColorSolid" in the

cmlSolidColor_Click
event properly. Then It enters the Private Sub, "LabelBackColorSolid".

When
it attempts to read the first line, "If ColorDialog1..." and launch
the
dialog box, It immediately triggers the Label_Paint event and enter a
continuous loop. If I pause it in the debugger and then continue the
loop
ends, the dialog box pops up, I pick my color, it applies it and all
is
well. What can I do to stop this behavior. Is there a way to force it
now

to
do the Label_Paint event at this point, say, until the end of the
"LabelBackColorSolid" sub is complete?

Thank you,

John


Nov 20 '05 #4
Here is the OnPaint code:

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

If lblP1JoyUp.Visible = True Then

Dim myFontBrush As New SolidBrush(lblP1JoyUp.ForeColor)

If mnuHLabel.Checked = True Then

If bFlipText = False Then

lblP1JoyUp.Text = ""

ElseIf bFlipText = True Then

Dim sf As New StringFormat

sf.Alignment = StringAlignment.Center

sf.LineAlignment = StringAlignment.Center

lblP1JoyUp.Text = ""
e.Graphics.TranslateTransform(lblP1JoyUp.ClientSiz e.Width,
lblP1JoyUp.ClientSize.Height)

e.Graphics.RotateTransform(180)

e.Graphics.DrawString("P1JoyUp", lblP1JoyUp.Font,
myFontBrush, RectangleF.op_Implicit(lblP1JoyUp.ClientRectangle) , sf)

End If

ElseIf mnuVLabel.Checked = True Then

If bFlipText = False Then

Dim y As Integer =
CInt(e.Graphics.MeasureString("lblP1JoyUp", lblP1JoyUp.Font).Width)

Dim x As Integer =
CInt(e.Graphics.MeasureString("lblP1JoyUp", lblP1JoyUp.Font).Height)

lblP1JoyUp.Text = ""
e.Graphics.TranslateTransform((lblP1JoyUp.ClientSi ze.Width - x) \ 2,
(lblP1JoyUp.ClientSize.Height - y) \ 2)

e.Graphics.RotateTransform(270)

e.Graphics.DrawString("P1JoyUp", lblP1JoyUp.Font,
myFontBrush, -y, 0)

ElseIf bFlipText = True Then

Dim y As Integer =
CInt(e.Graphics.MeasureString("lblP1JoyUp", lblP1JoyUp.Font).Width)

Dim x As Integer =
CInt(e.Graphics.MeasureString("lblP1JoyUp", lblP1JoyUp.Font).Height)

lblP1JoyUp.Text = ""
e.Graphics.TranslateTransform((lblP1JoyUp.ClientSi ze.Width + x) \ 2,
(lblP1JoyUp.ClientSize.Height + y) \ 2)

e.Graphics.RotateTransform(90)

e.Graphics.DrawString("P1JoyUp", lblP1JoyUp.Font,
myFontBrush, -y, 0)

End If

End If

myFontBrush.Dispose()

End If

End Sub


"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
John,

What is the code in your label paint event? I cannot see how the continuous loop is happening from what you posted.
do the Label_Paint event at this point, say, until the end of the
"LabelBackColorSolid" sub is complete?

This will temporarily turn off the paint event, but something seems amiss

to have to do this...

Private Sub LabelBackColorSolid()
RemoveHandler Label1.Paint, AddressOf Label1_Paint ' Stop handling
events.

If ColorDialog1.ShowDialog() = DialogResult.OK Then
' do stuff
End If

AddHandler Label1.Paint, AddressOf Label1_Paint
End Sub

HTH,
Greg

"jcrouse" <me> wrote in message
news:e1**************@TK2MSFTNGP09.phx.gbl...
No ideas here?

John

"jcrouse" <me> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...


Nov 20 '05 #5
But, it will keep looping back into the OnPaint sub and then out again.

John

"David Williams , VB.NET MVP" <da********************@earthlink.net> wrote
in message news:e8**************@TK2MSFTNGP11.phx.gbl...
Add a module level Boolean to state that you are in the
LabelBackColorSolid function. Check this variable in the Label_Paint
event. If set exit sub.

HTH

David

"jcrouse" <me> wrote in message
news:e1**************@TK2MSFTNGP09.phx.gbl:
No ideas here?

John

"jcrouse" <me> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
I am having problems with a Label_Paint event causing a continuous
loop.
Here is an explanation of the code.

I right click on a label and a context menu pops up.

I then select a menu item named "cmLSolidColor". Here is its code:

Private Sub cmLSolidColor_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles cmLSolidColor.Click

LabelBackColorSolid()

End Sub

It calls a sub named "LabelBackColorSolid". Here is its code:

Private Sub LabelBackColorSolid()

If ColorDialog1.ShowDialog() = DialogResult.OK Then

If bCMTrigger = True Then

If strCMTrigger = "lblP1JoyUp" Then

lblP1JoyUp.BackColor = (ColorDialog1.Color)

ElseIf strCMTrigger = "lblP1JoyRight" Then

lblP1JoyRight.BackColor = (ColorDialog1.Color)

End if

End if

End if

End Sub

The problem is that the label I'm right clicking on has a Label_Paint

event.
Execution goes to the line "LabelBackColorSolid" in the

cmlSolidColor_Click
event properly. Then It enters the Private Sub, "LabelBackColorSolid".

When
it attempts to read the first line, "If ColorDialog1..." and launch
the
dialog box, It immediately triggers the Label_Paint event and enter a
continuous loop. If I pause it in the debugger and then continue the
loop
ends, the dialog box pops up, I pick my color, it applies it and all
is
well. What can I do to stop this behavior. Is there a way to force it
now

to
do the Label_Paint event at this point, say, until the end of the
"LabelBackColorSolid" sub is complete?

Thank you,

John

Nov 20 '05 #6
Resolved!

"jcrouse" <me> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
I am having problems with a Label_Paint event causing a continuous loop.
Here is an explanation of the code.

I right click on a label and a context menu pops up.

I then select a menu item named "cmLSolidColor". Here is its code:

Private Sub cmLSolidColor_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmLSolidColor.Click

LabelBackColorSolid()

End Sub

It calls a sub named "LabelBackColorSolid". Here is its code:

Private Sub LabelBackColorSolid()

If ColorDialog1.ShowDialog() = DialogResult.OK Then

If bCMTrigger = True Then

If strCMTrigger = "lblP1JoyUp" Then

lblP1JoyUp.BackColor = (ColorDialog1.Color)

ElseIf strCMTrigger = "lblP1JoyRight" Then

lblP1JoyRight.BackColor = (ColorDialog1.Color)

End if

End if

End if

End Sub

The problem is that the label I'm right clicking on has a Label_Paint event. Execution goes to the line "LabelBackColorSolid" in the cmlSolidColor_Click event properly. Then It enters the Private Sub, "LabelBackColorSolid". When it attempts to read the first line, "If ColorDialog1..." and launch the
dialog box, It immediately triggers the Label_Paint event and enter a
continuous loop. If I pause it in the debugger and then continue the loop
ends, the dialog box pops up, I pick my color, it applies it and all is
well. What can I do to stop this behavior. Is there a way to force it now to do the Label_Paint event at this point, say, until the end of the
"LabelBackColorSolid" sub is complete?

Thank you,

John

Nov 20 '05 #7

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

Similar topics

21
by: Alo Sarv | last post by:
Hi From what I have understood from various posts in this newsgroup, writing event loops pretty much comes down to this: while (true) { handleEvents(); sleep(1); // or _sleep() or...
6
by: Tom | last post by:
Hi, In the following code I have reproduced a problem in IE that is extremely annoying for my application. <html> <head> <script type="text/javascript">
1
by: gavo | last post by:
Hello everyone! Using A2K i have a form(a) with a subform(b) and within the subform there is a continuous subform(c). in the subform (b) there is a command button used to call a public...
5
by: jcrouse | last post by:
I have a program that is an external viewer. It is launched with a hotkey from within another application. The program has 30 labels that can be displayed. Since the labels may not always be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.