473,397 Members | 2,116 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,397 software developers and data experts.

label control text rotation (paint) revisited.

I am rotating some text is some label controls. In the one place I use it it
works fine. In the other place I use it I can't figure out the syntax. I
don't really understand the event. Where it works fine, it seems to fire
when the form changes visibility. Here is the 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 frm1.intPriHP1 = frm1.intPriVP1 Then

If strLay1RotAngle = "90" Then

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

Dim x As Integer =
CInt(e.Graphics.MeasureString(Label1.Text, 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(Label1.Text, lblP1JoyUp.Font,
myFontBrush, -y, 0)

End If

myFontBrush.Dispose()

End If

End Sub
However, I now also need to place the same type code under a control event
such as a button click event. I am struggling trying to figure out the
syntax, mostly the "ByVal e" part and the handler. What would the proper
syntax be to either place the above syntax under a button click event, or
better yet, maybe inside a sub of its own. I need to call the above code for
30 label controls so having it in it's own sub would probably be the way to
go, right?

Help,
John



Nov 20 '05 #1
6 3122
* "jcrouse" <me> scripsit:
I am rotating some text is some label controls. In the one place I use it it
works fine. In the other place I use it I can't figure out the syntax.
[...]
However, I now also need to place the same type code under a control event
such as a button click event. I am struggling trying to figure out the
syntax, mostly the "ByVal e" part and the handler. What would the proper
syntax be to either place the above syntax under a button click event, or
better yet, maybe inside a sub of its own. I need to call the above code for
30 label controls so having it in it's own sub would probably be the way to
go, right?


I would derive a class from 'System.Windows.Forms.Label' and override
its 'OnPaint' sub. Then I would add a property 'Angle' that determines
the angle in which the text should be drawn. In the setter for this
property you can call 'Me.Invalidate' to redraw the text in the right
angle. Then you can use this control instead of the standard label
control.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #2
That's way outside of my capabilities. I don't understand.

John

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OC**************@TK2MSFTNGP09.phx.gbl...
* "jcrouse" <me> scripsit:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax.
[...]
However, I now also need to place the same type code under a control event such as a button click event. I am struggling trying to figure out the
syntax, mostly the "ByVal e" part and the handler. What would the proper
syntax be to either place the above syntax under a button click event, or better yet, maybe inside a sub of its own. I need to call the above code for 30 label controls so having it in it's own sub would probably be the way to go, right?


I would derive a class from 'System.Windows.Forms.Label' and override
its 'OnPaint' sub. Then I would add a property 'Angle' that determines
the angle in which the text should be drawn. In the setter for this
property you can call 'Me.Invalidate' to redraw the text in the right
angle. Then you can use this control instead of the standard label
control.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 20 '05 #3
I can't give up my standard label controls. I have too much code going on
with them. I have mouse ups, mouse downs, click events, mouse moves and all
kinds of settable properties. They are part of a form designer and are
movable at runtime. also, the font, forecolor, backcolor and size are all
settable with menus. It just seems like too much to change.

John

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OC**************@TK2MSFTNGP09.phx.gbl...
* "jcrouse" <me> scripsit:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax.
[...]
However, I now also need to place the same type code under a control event such as a button click event. I am struggling trying to figure out the
syntax, mostly the "ByVal e" part and the handler. What would the proper
syntax be to either place the above syntax under a button click event, or better yet, maybe inside a sub of its own. I need to call the above code for 30 label controls so having it in it's own sub would probably be the way to go, right?


I would derive a class from 'System.Windows.Forms.Label' and override
its 'OnPaint' sub. Then I would add a property 'Angle' that determines
the angle in which the text should be drawn. In the setter for this
property you can call 'Me.Invalidate' to redraw the text in the right
angle. Then you can use this control instead of the standard label
control.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 20 '05 #4
John,
When you derive from Label the control you create is a standard label, which
means you continue to use the same mouse ups, mouse downs, click events,
mouse moves and all kinds of the same settable properties.

You continue using the same form designer to set the same properties, the
only difference is, you new Label now has 1 more property an Angle
property...

I too would recommend you derive from Label and add an Angle Property, as
once you learn how I suspect your forms will suddenly become simpler and
easier to create, understand, and maintain later.

For a good intro explanation of OO in VB.NET I would recommend Robin A.
Reynolds-Haertle's book "OOP with Microsoft Visual Basic .NET and Microsoft
Visual C# .NET - Step by Step" from MS Press.

To answer your original question you do not really want to duplicate the
paint logic, as this is highly error prone. Instead you simply want to have
windows call the existing paint event when needed. To do this from a button
Click event handler, simply call Label.Invalidate from your button click
event.

Something like the following:

Private Sub Button1_Click(...

lblP1JoyUp.Invalidate()

End Sub

This will cause your label control to be repainted.

There are three interrelated methods on having a control repaint itself.
Invalidate, Update, and Refresh.

' request that the object repaint itself
lblP1JoyUp.Invalidate()

' cause the object to repaint itself right now!
lblP1JoyUp.Update()

' request that the object repaint itself, and do it right now!
lblP1JoyUp.Refresh()

If you simply call Invalidate, the Paint event of the control will be called
when all other events (such as your button click) have finished processing.
Update causes the Paint event to be called directly, while Refresh
effectively does an Invalidate followed by Refresh. Most of the time calling
Invalidate is all you really should do, otherwise you may wind up repainting
the control multiple times...

Hope this helps
Jay
"jcrouse" <me> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I can't give up my standard label controls. I have too much code going on
with them. I have mouse ups, mouse downs, click events, mouse moves and all kinds of settable properties. They are part of a form designer and are
movable at runtime. also, the font, forecolor, backcolor and size are all
settable with menus. It just seems like too much to change.

John

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OC**************@TK2MSFTNGP09.phx.gbl...
* "jcrouse" <me> scripsit:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax.
[...]
However, I now also need to place the same type code under a control event such as a button click event. I am struggling trying to figure out the
syntax, mostly the "ByVal e" part and the handler. What would the proper syntax be to either place the above syntax under a button click event, or better yet, maybe inside a sub of its own. I need to call the above
code
for 30 label controls so having it in it's own sub would probably be the
way
to go, right?


I would derive a class from 'System.Windows.Forms.Label' and override
its 'OnPaint' sub. Then I would add a property 'Angle' that determines
the angle in which the text should be drawn. In the setter for this
property you can call 'Me.Invalidate' to redraw the text in the right
angle. Then you can use this control instead of the standard label
control.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 20 '05 #5
That helps a lot. I know my code is nowhere near as clean and efficient as
it should be. I guess that's part of the learning curve. We tend to use what
we are comfortable with. I have been looking for a few good reads. I'll pick
up the one you recommended and start there.

Thank you,

John

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ef**************@TK2MSFTNGP12.phx.gbl...
John,
When you derive from Label the control you create is a standard label, which means you continue to use the same mouse ups, mouse downs, click events,
mouse moves and all kinds of the same settable properties.

You continue using the same form designer to set the same properties, the
only difference is, you new Label now has 1 more property an Angle
property...

I too would recommend you derive from Label and add an Angle Property, as
once you learn how I suspect your forms will suddenly become simpler and
easier to create, understand, and maintain later.

For a good intro explanation of OO in VB.NET I would recommend Robin A.
Reynolds-Haertle's book "OOP with Microsoft Visual Basic .NET and Microsoft Visual C# .NET - Step by Step" from MS Press.

To answer your original question you do not really want to duplicate the
paint logic, as this is highly error prone. Instead you simply want to have windows call the existing paint event when needed. To do this from a button Click event handler, simply call Label.Invalidate from your button click
event.

Something like the following:

Private Sub Button1_Click(...

lblP1JoyUp.Invalidate()

End Sub

This will cause your label control to be repainted.

There are three interrelated methods on having a control repaint itself.
Invalidate, Update, and Refresh.

' request that the object repaint itself
lblP1JoyUp.Invalidate()

' cause the object to repaint itself right now!
lblP1JoyUp.Update()

' request that the object repaint itself, and do it right now!
lblP1JoyUp.Refresh()

If you simply call Invalidate, the Paint event of the control will be called when all other events (such as your button click) have finished processing. Update causes the Paint event to be called directly, while Refresh
effectively does an Invalidate followed by Refresh. Most of the time calling Invalidate is all you really should do, otherwise you may wind up repainting the control multiple times...

Hope this helps
Jay
"jcrouse" <me> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I can't give up my standard label controls. I have too much code going on
with them. I have mouse ups, mouse downs, click events, mouse moves and

all
kinds of settable properties. They are part of a form designer and are
movable at runtime. also, the font, forecolor, backcolor and size are all settable with menus. It just seems like too much to change.

John

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OC**************@TK2MSFTNGP09.phx.gbl...
* "jcrouse" <me> scripsit:
> I am rotating some text is some label controls. In the one place I use
it it
> works fine. In the other place I use it I can't figure out the
syntax. > [...]
> However, I now also need to place the same type code under a control

event
> such as a button click event. I am struggling trying to figure out the > syntax, mostly the "ByVal e" part and the handler. What would the

proper > syntax be to either place the above syntax under a button click event, or
> better yet, maybe inside a sub of its own. I need to call the above

code
for
> 30 label controls so having it in it's own sub would probably be the

way
to
> go, right?

I would derive a class from 'System.Windows.Forms.Label' and override
its 'OnPaint' sub. Then I would add a property 'Angle' that

determines the angle in which the text should be drawn. In the setter for this
property you can call 'Me.Invalidate' to redraw the text in the right
angle. Then you can use this control instead of the standard label
control.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>



Nov 20 '05 #6
Well, the problem is this. The control paint event seems to fire on visible
change. I don't want that. My label is draggable at runtime and when I drag
it across the form, the paint event seems to run continually until I stop
dragging the control. The makes the drag very slow and choppy. I want to
only call the paint event when needed, like inside my mouse up or mouse move
event.

Thanks,

John

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ef**************@TK2MSFTNGP12.phx.gbl...
John,
When you derive from Label the control you create is a standard label, which means you continue to use the same mouse ups, mouse downs, click events,
mouse moves and all kinds of the same settable properties.

You continue using the same form designer to set the same properties, the
only difference is, you new Label now has 1 more property an Angle
property...

I too would recommend you derive from Label and add an Angle Property, as
once you learn how I suspect your forms will suddenly become simpler and
easier to create, understand, and maintain later.

For a good intro explanation of OO in VB.NET I would recommend Robin A.
Reynolds-Haertle's book "OOP with Microsoft Visual Basic .NET and Microsoft Visual C# .NET - Step by Step" from MS Press.

To answer your original question you do not really want to duplicate the
paint logic, as this is highly error prone. Instead you simply want to have windows call the existing paint event when needed. To do this from a button Click event handler, simply call Label.Invalidate from your button click
event.

Something like the following:

Private Sub Button1_Click(...

lblP1JoyUp.Invalidate()

End Sub

This will cause your label control to be repainted.

There are three interrelated methods on having a control repaint itself.
Invalidate, Update, and Refresh.

' request that the object repaint itself
lblP1JoyUp.Invalidate()

' cause the object to repaint itself right now!
lblP1JoyUp.Update()

' request that the object repaint itself, and do it right now!
lblP1JoyUp.Refresh()

If you simply call Invalidate, the Paint event of the control will be called when all other events (such as your button click) have finished processing. Update causes the Paint event to be called directly, while Refresh
effectively does an Invalidate followed by Refresh. Most of the time calling Invalidate is all you really should do, otherwise you may wind up repainting the control multiple times...

Hope this helps
Jay
"jcrouse" <me> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I can't give up my standard label controls. I have too much code going on
with them. I have mouse ups, mouse downs, click events, mouse moves and

all
kinds of settable properties. They are part of a form designer and are
movable at runtime. also, the font, forecolor, backcolor and size are all settable with menus. It just seems like too much to change.

John

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OC**************@TK2MSFTNGP09.phx.gbl...
* "jcrouse" <me> scripsit:
> I am rotating some text is some label controls. In the one place I use
it it
> works fine. In the other place I use it I can't figure out the
syntax. > [...]
> However, I now also need to place the same type code under a control

event
> such as a button click event. I am struggling trying to figure out the > syntax, mostly the "ByVal e" part and the handler. What would the

proper > syntax be to either place the above syntax under a button click event, or
> better yet, maybe inside a sub of its own. I need to call the above

code
for
> 30 label controls so having it in it's own sub would probably be the

way
to
> go, right?

I would derive a class from 'System.Windows.Forms.Label' and override
its 'OnPaint' sub. Then I would add a property 'Angle' that

determines the angle in which the text should be drawn. In the setter for this
property you can call 'Me.Invalidate' to redraw the text in the right
angle. Then you can use this control instead of the standard label
control.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>



Nov 20 '05 #7

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

Similar topics

4
by: Stuart Norris | last post by:
Dear Readers, I am attempting to draw box around some text using unicode on multiline label. The label is forty characters wide and 12 lines deep. I have been trying to draw a box around text...
7
by: Jon S via DotNetMonster.com | last post by:
Hi all, I posted this yesterday but didnt explain it too well so thought I would do it again. I have a label on a form that I want to be able to change the text while I'm in a seperate class...
20
by: BB | last post by:
Hello all, I am trying to override OnPaint in a custom textbox control (so I can drawstring a caption, etc.). In the code below, I get the "painting the form" message as expected, but not the...
31
by: jcrouse | last post by:
Is there a quick and easy way to change the color of a label controls border from the default black to white? Thank you, John
9
by: C R | last post by:
I have a label inside of a form. The form is maximized to fill the entire screen. I would like the label to take up 40% of the width of the screen, and 70% of the height, regardless of monitor size...
3
by: Avi G | last post by:
Hi, i work with VS 2005 and i need to know how to put the windows time(Clock) on my label that it is on the form that i will see the full time include the second as they move, and i need to know...
0
by: VorTechS | last post by:
I'm having a problem with an inherited label, applying text rotation to aligned text. If text rotation is applied to the aligned text, the alignment goes 'nuts'. I can find no logic to what is...
8
by: Alexey Smirnov | last post by:
How to make bold part of the text in a Windows.Forms.Label? Thank you.
11
by: Peter Larsen [] | last post by:
Hi, I have two questions related to the Label control. How do i prevent the label from expand the canvas into 2 lines (word wrap) ?? At the moment i set AutoSize to false (to prevent the word...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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...

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.