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 6 3007
* "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/>
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/>
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/>
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/>
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/>
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/>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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
|
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,...
|
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...
|
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...
|
by: Alexey Smirnov |
last post by:
How to make bold part of the text in a Windows.Forms.Label? Thank you.
|
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...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
| |