Sort indicator on label

G

Guest

Is there any way to get the little sort indicator (the up/down arrow that is
visible by the column header in Explorer when you sort by a column) on a
standard label?

Note that I'm not using a datagrid - I know that they show on those by
default. I'm using a data repeater control from a third party and I'd like
to display that indicator on the header labels of that.

Thanks.
 
B

Bob Powell [MVP]

Create your own label type class. It'd take you a few minutes to rattle one
up...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
R

Rob Oldfield

Sadly not. I'm still a bit too inexperienced to figure out exactly how that
would work. Could you provide a bit more detail on how that would work?

(I do, by the way, have an existing third party 'clickable label' control
that I could inherit from that would handle the click event handling.. it's
just how to get the additional indicator that I'm stuck with.)
 
J

Jay Freedman

It's not quite the same appearance as the ones in the datagrid
headers, but there are triangles in the Marlett font -- type the
character "5" and format it in Marlett for the point-up triangle, and
"6" for the point-down one. Then you just need to write code in the
click event handler to change the caption string.

Marlett is a standard Windows font, used for things like the minimize
and restore buttons on app windows, so you don't have to worry about
packaging it with your program.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
G

Guest

Thanks for the info. I'm sure that that will be part of it but I'd still (I
think) need to figure out how to build a new class. The problem is that
within a standard label I'm not going to be able to format the actual label
text with one font, and then the sort indicator with another. Unless I'm
missing something obvious that is... it wouldn't be the first time.
 
C

Claes Bergefall

This will create an imagelist with both up and down arrows as they appear in
Outlook and Outlook Express (Explorer looks a bit different). Not sure if
the arrows look different when using themes though. I've only tested it with
classic settings. Anyway, it might be useful to you:

Private Function CreateSortingImages() As ImageList
Dim imgList As New ImageList
Dim imgUpArrow As New Bitmap(16, 16,
Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim imgDownArrow As New Bitmap(16, 16,
Drawing.Imaging.PixelFormat.Format32bppArgb)
imgList.ImageSize = New Size(16, 16)
imgList.ColorDepth = ColorDepth.Depth8Bit
imgList.TransparentColor = SystemColors.Desktop

Dim penLeft As New Pen(SystemColors.ControlDark, 1)
Dim penRight As New Pen(SystemColors.ControlLightLight, 1)
Dim brushBackground As New SolidBrush(SystemColors.Control)
Dim brushTransparent As New SolidBrush(SystemColors.Desktop)
Dim dc As Graphics
Dim point1 As Point
Dim point2 As Point
Dim point3 As Point
Dim point4 As Point
Dim point5 As Point
Dim point6 As Point

' Up arrow image - Index 0
dc = Graphics.FromImage(imgUpArrow)
dc.FillRectangle(brushTransparent, 0, 0, 16, 16)
point1 = New Point(7, 5)
point2 = New Point(8, 5)
point3 = New Point(11, 10)
point4 = New Point(11, 11)
point5 = New Point(4, 11)
point6 = New Point(4, 10)
dc.FillPolygon(brushBackground, New Point() {point1, point2, point3,
point4, point5, point6})
dc.DrawLine(penLeft, point6, point1)
dc.DrawLine(penRight, point2, point3)
dc.DrawLine(penRight, point4, point5)
imgList.Images.Add(imgUpArrow, SystemColors.Desktop)

' Down arrow image - Index 1
dc = Graphics.FromImage(imgDownArrow)
dc.FillRectangle(brushTransparent, 0, 0, 16, 16)
point1 = New Point(4, 4)
point2 = New Point(11, 4)
point3 = New Point(11, 5)
point4 = New Point(8, 10)
point5 = New Point(7, 10)
point6 = New Point(4, 5)
dc.FillPolygon(brushBackground, New Point() {point1, point2, point3,
point4, point5, point6})
dc.DrawLine(penLeft, point1, point2)
dc.DrawLine(penRight, point2, point4)
dc.DrawLine(penLeft, point5, point6)
imgList.Images.Add(imgDownArrow, SystemColors.Desktop)

Return imgList
End Function

/claes
 
J

Jay Freedman

Yeah, I overlooked that. Tell VS you want to add a new item to your project,
and select "UserControl". You get what looks like a panel. Put the regular
label (or your clickable label control) on one side of the panel, and a
label formatted in Marlett on the other side. In the code, you get a class
that derives from a framework class named UserControl. Make sure the class
is declared as public.

To make that class show up in the Designer's toolbox, insert this
"decoration" just before the class declaration:

[Designer("System.Windows.Forms.Design.ParentControlDesigner,
System.Design", typeof(IDesigner))]

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
G

Guest

OK. I'm getting there I think. I've got the 'Text' property of the user
control working so that I can specify text, and also an additional 'Updown'
property that decides whether to show a up, down, or no arrow. But...

What I would like to do would be to set it so that I can specify the text
from the form that the control appears on, and have the control display the
arrow immediately to the right of the text. Given that I'm just using label1
and label2 as the control names, I've tried this in the text changed event of
label1 in the user control:

me.label2.left=me.label1.left+me.label1.width
me.width=me.label2.left+me.label2.width

where the autosize (? not sure on that bit, I don't have it in front of me)
property on label1 is set to true.

That's not quite working. If I change the user control text from the main
form to "this is some really quite long text" then nothing happens. If I
then change it to "a" then the control makes enough space for "this is some
really quite long text" i.e. it's lagging one step behind.

Does that make sense? Any suggestions about where I should be setting the
properties?



Jay Freedman said:
Yeah, I overlooked that. Tell VS you want to add a new item to your project,
and select "UserControl". You get what looks like a panel. Put the regular
label (or your clickable label control) on one side of the panel, and a
label formatted in Marlett on the other side. In the code, you get a class
that derives from a framework class named UserControl. Make sure the class
is declared as public.

To make that class show up in the Designer's toolbox, insert this
"decoration" just before the class declaration:

[Designer("System.Windows.Forms.Design.ParentControlDesigner,
System.Design", typeof(IDesigner))]

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Rob said:
Thanks for the info. I'm sure that that will be part of it but I'd
still (I think) need to figure out how to build a new class. The
problem is that within a standard label I'm not going to be able to
format the actual label text with one font, and then the sort
indicator with another. Unless I'm missing something obvious that
is... it wouldn't be the first time.
 
G

Guest

Thanks for that. For the moment though, Jay's suggestion of using Marlett
looks to be good enough. I might try to build the graphic idea in later
though.
 
J

Jay Freedman

After playing with this for a bit, I think the proper event handler is
label1_SizeChanged(). That occurs after the AutoSize event that's
fired because the text changed.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

OK. I'm getting there I think. I've got the 'Text' property of the user
control working so that I can specify text, and also an additional 'Updown'
property that decides whether to show a up, down, or no arrow. But...

What I would like to do would be to set it so that I can specify the text
from the form that the control appears on, and have the control display the
arrow immediately to the right of the text. Given that I'm just using label1
and label2 as the control names, I've tried this in the text changed event of
label1 in the user control:

me.label2.left=me.label1.left+me.label1.width
me.width=me.label2.left+me.label2.width

where the autosize (? not sure on that bit, I don't have it in front of me)
property on label1 is set to true.

That's not quite working. If I change the user control text from the main
form to "this is some really quite long text" then nothing happens. If I
then change it to "a" then the control makes enough space for "this is some
really quite long text" i.e. it's lagging one step behind.

Does that make sense? Any suggestions about where I should be setting the
properties?



Jay Freedman said:
Yeah, I overlooked that. Tell VS you want to add a new item to your project,
and select "UserControl". You get what looks like a panel. Put the regular
label (or your clickable label control) on one side of the panel, and a
label formatted in Marlett on the other side. In the code, you get a class
that derives from a framework class named UserControl. Make sure the class
is declared as public.

To make that class show up in the Designer's toolbox, insert this
"decoration" just before the class declaration:

[Designer("System.Windows.Forms.Design.ParentControlDesigner,
System.Design", typeof(IDesigner))]

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Rob said:
Thanks for the info. I'm sure that that will be part of it but I'd
still (I think) need to figure out how to build a new class. The
problem is that within a standard label I'm not going to be able to
format the actual label text with one font, and then the sort
indicator with another. Unless I'm missing something obvious that
is... it wouldn't be the first time.

:

It's not quite the same appearance as the ones in the datagrid
headers, but there are triangles in the Marlett font -- type the
character "5" and format it in Marlett for the point-up triangle, and
"6" for the point-down one. Then you just need to write code in the
click event handler to change the caption string.

Marlett is a standard Windows font, used for things like the minimize
and restore buttons on app windows, so you don't have to worry about
packaging it with your program.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

Sadly not. I'm still a bit too inexperienced to figure out exactly
how that would work. Could you provide a bit more detail on how
that would work?

(I do, by the way, have an existing third party 'clickable label'
control that I could inherit from that would handle the click event
handling.. it's just how to get the additional indicator that I'm
stuck with.)



Create your own label type class. It'd take you a few minutes to
rattle one up...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



message Is there any way to get the little sort indicator (the up/down
arrow that is
visible by the column header in Explorer when you sort by a
column) on a standard label?

Note that I'm not using a datagrid - I know that they show on
those by default. I'm using a data repeater control from a third
party and I'd like
to display that indicator on the header labels of that.

Thanks.
 
G

Guest

Excellent. Think it's now fully functional. Many thanks.

Jay Freedman said:
After playing with this for a bit, I think the proper event handler is
label1_SizeChanged(). That occurs after the AutoSize event that's
fired because the text changed.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

OK. I'm getting there I think. I've got the 'Text' property of the user
control working so that I can specify text, and also an additional 'Updown'
property that decides whether to show a up, down, or no arrow. But...

What I would like to do would be to set it so that I can specify the text
from the form that the control appears on, and have the control display the
arrow immediately to the right of the text. Given that I'm just using label1
and label2 as the control names, I've tried this in the text changed event of
label1 in the user control:

me.label2.left=me.label1.left+me.label1.width
me.width=me.label2.left+me.label2.width

where the autosize (? not sure on that bit, I don't have it in front of me)
property on label1 is set to true.

That's not quite working. If I change the user control text from the main
form to "this is some really quite long text" then nothing happens. If I
then change it to "a" then the control makes enough space for "this is some
really quite long text" i.e. it's lagging one step behind.

Does that make sense? Any suggestions about where I should be setting the
properties?



Jay Freedman said:
Yeah, I overlooked that. Tell VS you want to add a new item to your project,
and select "UserControl". You get what looks like a panel. Put the regular
label (or your clickable label control) on one side of the panel, and a
label formatted in Marlett on the other side. In the code, you get a class
that derives from a framework class named UserControl. Make sure the class
is declared as public.

To make that class show up in the Designer's toolbox, insert this
"decoration" just before the class declaration:

[Designer("System.Windows.Forms.Design.ParentControlDesigner,
System.Design", typeof(IDesigner))]

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Rob Oldfield wrote:
Thanks for the info. I'm sure that that will be part of it but I'd
still (I think) need to figure out how to build a new class. The
problem is that within a standard label I'm not going to be able to
format the actual label text with one font, and then the sort
indicator with another. Unless I'm missing something obvious that
is... it wouldn't be the first time.

:

It's not quite the same appearance as the ones in the datagrid
headers, but there are triangles in the Marlett font -- type the
character "5" and format it in Marlett for the point-up triangle, and
"6" for the point-down one. Then you just need to write code in the
click event handler to change the caption string.

Marlett is a standard Windows font, used for things like the minimize
and restore buttons on app windows, so you don't have to worry about
packaging it with your program.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

Sadly not. I'm still a bit too inexperienced to figure out exactly
how that would work. Could you provide a bit more detail on how
that would work?

(I do, by the way, have an existing third party 'clickable label'
control that I could inherit from that would handle the click event
handling.. it's just how to get the additional indicator that I'm
stuck with.)



Create your own label type class. It'd take you a few minutes to
rattle one up...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



message Is there any way to get the little sort indicator (the up/down
arrow that is
visible by the column header in Explorer when you sort by a
column) on a standard label?

Note that I'm not using a datagrid - I know that they show on
those by default. I'm using a data repeater control from a third
party and I'd like
to display that indicator on the header labels of that.

Thanks.
 
J

Jay Freedman

You're welcome! (Not bad for someone who built his first usercontrol
about two months ago...)

Jay

Excellent. Think it's now fully functional. Many thanks.

Jay Freedman said:
After playing with this for a bit, I think the proper event handler is
label1_SizeChanged(). That occurs after the AutoSize event that's
fired because the text changed.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

OK. I'm getting there I think. I've got the 'Text' property of the user
control working so that I can specify text, and also an additional 'Updown'
property that decides whether to show a up, down, or no arrow. But...

What I would like to do would be to set it so that I can specify the text
from the form that the control appears on, and have the control display the
arrow immediately to the right of the text. Given that I'm just using label1
and label2 as the control names, I've tried this in the text changed event of
label1 in the user control:

me.label2.left=me.label1.left+me.label1.width
me.width=me.label2.left+me.label2.width

where the autosize (? not sure on that bit, I don't have it in front of me)
property on label1 is set to true.

That's not quite working. If I change the user control text from the main
form to "this is some really quite long text" then nothing happens. If I
then change it to "a" then the control makes enough space for "this is some
really quite long text" i.e. it's lagging one step behind.

Does that make sense? Any suggestions about where I should be setting the
properties?



:

Yeah, I overlooked that. Tell VS you want to add a new item to your project,
and select "UserControl". You get what looks like a panel. Put the regular
label (or your clickable label control) on one side of the panel, and a
label formatted in Marlett on the other side. In the code, you get a class
that derives from a framework class named UserControl. Make sure the class
is declared as public.

To make that class show up in the Designer's toolbox, insert this
"decoration" just before the class declaration:

[Designer("System.Windows.Forms.Design.ParentControlDesigner,
System.Design", typeof(IDesigner))]

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Rob Oldfield wrote:
Thanks for the info. I'm sure that that will be part of it but I'd
still (I think) need to figure out how to build a new class. The
problem is that within a standard label I'm not going to be able to
format the actual label text with one font, and then the sort
indicator with another. Unless I'm missing something obvious that
is... it wouldn't be the first time.

:

It's not quite the same appearance as the ones in the datagrid
headers, but there are triangles in the Marlett font -- type the
character "5" and format it in Marlett for the point-up triangle, and
"6" for the point-down one. Then you just need to write code in the
click event handler to change the caption string.

Marlett is a standard Windows font, used for things like the minimize
and restore buttons on app windows, so you don't have to worry about
packaging it with your program.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

Sadly not. I'm still a bit too inexperienced to figure out exactly
how that would work. Could you provide a bit more detail on how
that would work?

(I do, by the way, have an existing third party 'clickable label'
control that I could inherit from that would handle the click event
handling.. it's just how to get the additional indicator that I'm
stuck with.)



Create your own label type class. It'd take you a few minutes to
rattle one up...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



message Is there any way to get the little sort indicator (the up/down
arrow that is
visible by the column header in Explorer when you sort by a
column) on a standard label?

Note that I'm not using a datagrid - I know that they show on
those by default. I'm using a data repeater control from a third
party and I'd like
to display that indicator on the header labels of that.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top