473,789 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_C lick(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmLSolidColor.C lick

LabelBackColorS olid()

End Sub

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

Private Sub LabelBackColorS olid()

If ColorDialog1.Sh owDialog() = DialogResult.OK Then

If bCMTrigger = True Then

If strCMTrigger = "lblP1JoyUp " Then

lblP1JoyUp.Back Color = (ColorDialog1.C olor)

ElseIf strCMTrigger = "lblP1JoyRi ght" Then

lblP1JoyRight.B ackColor = (ColorDialog1.C olor)

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 "LabelBackColor Solid" in the cmlSolidColor_C lick
event properly. Then It enters the Private Sub, "LabelBackColor Solid". 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
"LabelBackColor Solid" sub is complete?

Thank you,

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

John

"jcrouse" <me> wrote in message
news:uO******** ******@TK2MSFTN GP11.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_C lick(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmLSolidColor.C lick

LabelBackColorS olid()

End Sub

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

Private Sub LabelBackColorS olid()

If ColorDialog1.Sh owDialog() = DialogResult.OK Then

If bCMTrigger = True Then

If strCMTrigger = "lblP1JoyUp " Then

lblP1JoyUp.Back Color = (ColorDialog1.C olor)

ElseIf strCMTrigger = "lblP1JoyRi ght" Then

lblP1JoyRight.B ackColor = (ColorDialog1.C olor)

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 "LabelBackColor Solid" in the cmlSolidColor_C lick event properly. Then It enters the Private Sub, "LabelBackColor Solid". 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
"LabelBackColor Solid" 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
"LabelBackColor Solid" sub is complete?

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

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

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

AddHandler Label1.Paint, AddressOf Label1_Paint
End Sub

HTH,
Greg

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

John

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

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

HTH

David

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

John

"jcrouse" <me> wrote in message
news:uO******** ******@TK2MSFTN GP11.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_C lick(ByVal sender As System.Object, ByVal e
As
System.EventArg s) Handles cmLSolidColor.C lick

LabelBackColorS olid()

End Sub

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

Private Sub LabelBackColorS olid()

If ColorDialog1.Sh owDialog() = DialogResult.OK Then

If bCMTrigger = True Then

If strCMTrigger = "lblP1JoyUp " Then

lblP1JoyUp.Back Color = (ColorDialog1.C olor)

ElseIf strCMTrigger = "lblP1JoyRi ght" Then

lblP1JoyRight.B ackColor = (ColorDialog1.C olor)

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 "LabelBackColor Solid" in the

cmlSolidColor_C lick
event properly. Then It enters the Private Sub, "LabelBackColor Solid".

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
"LabelBackColor Solid" sub is complete?

Thank you,

John


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

Private Sub lblP1JoyUp_Pain t(ByVal sender As Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles lblP1JoyUp.Pain t

If lblP1JoyUp.Visi ble = True Then

Dim myFontBrush As New SolidBrush(lblP 1JoyUp.ForeColo r)

If mnuHLabel.Check ed = True Then

If bFlipText = False Then

lblP1JoyUp.Text = ""

ElseIf bFlipText = True Then

Dim sf As New StringFormat

sf.Alignment = StringAlignment .Center

sf.LineAlignmen t = StringAlignment .Center

lblP1JoyUp.Text = ""
e.Graphics.Tran slateTransform( lblP1JoyUp.Clie ntSize.Width,
lblP1JoyUp.Clie ntSize.Height)

e.Graphics.Rota teTransform(180 )

e.Graphics.Draw String("P1JoyUp ", lblP1JoyUp.Font ,
myFontBrush, RectangleF.op_I mplicit(lblP1Jo yUp.ClientRecta ngle), sf)

End If

ElseIf mnuVLabel.Check ed = 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.Tran slateTransform( (lblP1JoyUp.Cli entSize.Width - x) \ 2,
(lblP1JoyUp.Cli entSize.Height - y) \ 2)

e.Graphics.Rota teTransform(270 )

e.Graphics.Draw String("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.Tran slateTransform( (lblP1JoyUp.Cli entSize.Width + x) \ 2,
(lblP1JoyUp.Cli entSize.Height + y) \ 2)

e.Graphics.Rota teTransform(90)

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

End If

End If

myFontBrush.Dis pose()

End If

End Sub


"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.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
"LabelBackColor Solid" sub is complete?

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

to have to do this...

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

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

AddHandler Label1.Paint, AddressOf Label1_Paint
End Sub

HTH,
Greg

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

John

"jcrouse" <me> wrote in message
news:uO******** ******@TK2MSFTN GP11.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************ ********@earthl ink.net> wrote
in message news:e8******** ******@TK2MSFTN GP11.phx.gbl...
Add a module level Boolean to state that you are in the
LabelBackColorS olid function. Check this variable in the Label_Paint
event. If set exit sub.

HTH

David

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

John

"jcrouse" <me> wrote in message
news:uO******** ******@TK2MSFTN GP11.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_C lick(ByVal sender As System.Object, ByVal e
As
System.EventArg s) Handles cmLSolidColor.C lick

LabelBackColorS olid()

End Sub

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

Private Sub LabelBackColorS olid()

If ColorDialog1.Sh owDialog() = DialogResult.OK Then

If bCMTrigger = True Then

If strCMTrigger = "lblP1JoyUp " Then

lblP1JoyUp.Back Color = (ColorDialog1.C olor)

ElseIf strCMTrigger = "lblP1JoyRi ght" Then

lblP1JoyRight.B ackColor = (ColorDialog1.C olor)

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 "LabelBackColor Solid" in the

cmlSolidColor_C lick
event properly. Then It enters the Private Sub, "LabelBackColor Solid".

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
"LabelBackColor Solid" sub is complete?

Thank you,

John

Nov 20 '05 #6
Resolved!

"jcrouse" <me> wrote in message
news:uO******** ******@TK2MSFTN GP11.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_C lick(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmLSolidColor.C lick

LabelBackColorS olid()

End Sub

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

Private Sub LabelBackColorS olid()

If ColorDialog1.Sh owDialog() = DialogResult.OK Then

If bCMTrigger = True Then

If strCMTrigger = "lblP1JoyUp " Then

lblP1JoyUp.Back Color = (ColorDialog1.C olor)

ElseIf strCMTrigger = "lblP1JoyRi ght" Then

lblP1JoyRight.B ackColor = (ColorDialog1.C olor)

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 "LabelBackColor Solid" in the cmlSolidColor_C lick event properly. Then It enters the Private Sub, "LabelBackColor Solid". 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
"LabelBackColor Solid" 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
18760
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 nanosleep(), depending on platform }
6
5333
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
2938
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 function
5
1330
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 oriented the same as the Operating System I needed to use the Label_Paint event to PAINT the labels text if it not oriented the same as the operating system. I am trying to figure out a way to make this event happen faster or optimize it if possible. I...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.