473,883 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

e.Graphics.Rota teTransform(90)

e.Graphics.Draw String(Label1.T ext, lblP1JoyUp.Font ,
myFontBrush, -y, 0)

End If

myFontBrush.Dis pose()

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 3172
* "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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP09.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.Invalidat e from your button click
event.

Something like the following:

Private Sub Button1_Click(. ..

lblP1JoyUp.Inva lidate()

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.Inva lidate()

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

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

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******** ********@TK2MSF TNGP10.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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP12.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.Invalidat e from your button click
event.

Something like the following:

Private Sub Button1_Click(. ..

lblP1JoyUp.Inva lidate()

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.Inva lidate()

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

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

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******** ********@TK2MSF TNGP10.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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP12.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.Invalidat e from your button click
event.

Something like the following:

Private Sub Button1_Click(. ..

lblP1JoyUp.Inva lidate()

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.Inva lidate()

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

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

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******** ********@TK2MSF TNGP10.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******** ******@TK2MSFTN GP09.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
12352
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 (centered in the label) on this label. My font on this label is Courier new - hence fixed width character cells.
7
2429
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 file. For example - FORM1 IS :
20
2582
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 "painting the control". It also has no effect to explicitly call txtTest.Invalidate or txtTest.Refresh. Am I missing something simple here? Any push in the right direction is appreciated.
31
7271
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
8699
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 or resolution. How can I do this? Also, if I use a certain font & font size, how can I avoid getting any half-lines of text, where you just see the cut-off tops or bottoms of the letters? Thanks for any help!
3
4611
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 how to make a label with text on him to vertical state and not the horizontal normal state. Thanks
0
1808
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 happening. I've built the following code from several examples on the web, if you remove the rotation then alignment works fine: Imports System.ComponentModel
8
31059
by: Alexey Smirnov | last post by:
How to make bold part of the text in a Windows.Forms.Label? Thank you.
11
11533
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 wrap from happening) and Anchor to Left, Right (to enable the with autosize). How do i prevent a tool-tip from happening if the text is to large to fit in
0
9944
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11151
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
10752
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...
1
10858
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9582
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7974
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
7134
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5996
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3238
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.