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

Percent TypeConverter

Is there a TypeConverter that converts Doubles to percent values in a PropertyGrid? The Windows.Forms.Form.Opacity property seems to use the TypeConverter that I want.

Thank you,
Lance
Nov 20 '05 #1
5 2163
View this thread from Jay Harlow and Charles Law. It might help.

-------------

Hi Jay

Thanks for confirming what I was beginning to suspect.

Using the example that I just used to Armin, I would then have

<code>
Public Structure MyValueClass

Public Function ToPercent() As Double
End Function

Public Function ToAbsolute() As Integer
End Function

End Structure

Dim d As Double
Dim i As Integer

d = mc.Value.ToPercent()
i = mc.Value.ToAbsolute()
</code>

showing that I must explicitly call ToAbsolute rather than just write

i = mc.Value

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
news:eZ**************@TK2MSFTNGP11.phx.gbl...
Charles,
Neither VB.NET 2002 nor VB.NET 2003 support what you are attempting, per
se.

You could always:

Public Structure MyValueClass

Public Function ToPercent() As String
End Function

Public Function ToInteger() As Integer
End Function

End Structure
i = mc.Value.ToInteger()
Textbox1.Text = mc.Value.ToPercent()


With VB.NET 2005 (Whidbey) we will be able to override CType, the
conversion
operator, so you will be able to do something like (based on the CTP
release
of Whidbey):

Public Structure MyValueClass

Public Function ToPercent() As String
End Function

Public Function ToInteger() As Integer
End Function

Public Shared Widening Operator CType(value As MyValueClass) As
Integer
Return value.ToInteger()
End Operator

Public Shared Narrowing Operator CType(value As Integer) As
MyValueClass
Return New MyValueClass(value)
End Operator

End Structure

i = mc.Value
mc.Value = CType(i, MyValueClass)

A Widening CType operator does not require CType, while a Narrowing CType
operator does.

Hope this helps
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:ey**************@TK2MSFTNGP11.phx.gbl...
In a VB.NET app, I can write

Dim s As String = 3.ToString

This is because 3 is of type Int32, which is a structure, which has a method ToString.

I would also like to be able to write

Dim s As String = 3.ToPercent

by supplying my own implementation of ToPercent. If I could do this,
then
I would be able to do what I ultimately wish to do, and that is write
something like the following:

Dim mc As New MyClass
Dim i As Integer

i = mc.Value
Textbox1.Text = mc.Value.ToPercent

I have tried to make Value of type MyValueClass, for example, which inherits from Int32, but Int32 is not inheritable, so that is a non-starter. In
any
case, the first assignment gives a compile time error because there is
no
default property of MyValueClass, and I can't set one unless it takes
parameters (which it doesn't).

Can anyone suggest how this might be done?

TIA

Charles


"ljlevend" <lj******@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com: Is there a TypeConverter that converts Doubles to percent values in a
PropertyGrid? The Windows.Forms.Form.Opacity property seems to use the
TypeConverter that I want.

Thank you,
Lance


Nov 20 '05 #2
Thanks for the help, but that isn't quite what I'm looking for. I need a TypeConverter class rather than a technique that converts a value. I could create my own TypeConverter class, but I want to make sure that there isn't a standard percent TypeConverter before doing so.

Lance
"scorpion53061" wrote:
View this thread from Jay Harlow and Charles Law. It might help.

-------------

Hi Jay

Thanks for confirming what I was beginning to suspect.

Using the example that I just used to Armin, I would then have

<code>
Public Structure MyValueClass

Public Function ToPercent() As Double
End Function

Public Function ToAbsolute() As Integer
End Function

End Structure

Dim d As Double
Dim i As Integer

d = mc.Value.ToPercent()
i = mc.Value.ToAbsolute()
</code>

showing that I must explicitly call ToAbsolute rather than just write

i = mc.Value

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
news:eZ**************@TK2MSFTNGP11.phx.gbl...
Charles,
Neither VB.NET 2002 nor VB.NET 2003 support what you are attempting, per


se.

You could always:

Public Structure MyValueClass

Public Function ToPercent() As String
End Function

Public Function ToInteger() As Integer
End Function

End Structure

i = mc.Value.ToInteger()
Textbox1.Text = mc.Value.ToPercent()


With VB.NET 2005 (Whidbey) we will be able to override CType, the


conversion
operator, so you will be able to do something like (based on the CTP


release
of Whidbey):

Public Structure MyValueClass

Public Function ToPercent() As String
End Function

Public Function ToInteger() As Integer
End Function

Public Shared Widening Operator CType(value As MyValueClass) As
Integer
Return value.ToInteger()
End Operator

Public Shared Narrowing Operator CType(value As Integer) As
MyValueClass
Return New MyValueClass(value)
End Operator

End Structure

i = mc.Value
mc.Value = CType(i, MyValueClass)

A Widening CType operator does not require CType, while a Narrowing CType
operator does.

Hope this helps
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:ey**************@TK2MSFTNGP11.phx.gbl...

In a VB.NET app, I can write

Dim s As String = 3.ToString

This is because 3 is of type Int32, which is a structure, which has a
method

ToString.

I would also like to be able to write

Dim s As String = 3.ToPercent

by supplying my own implementation of ToPercent. If I could do this,
then
I

would be able to do what I ultimately wish to do, and that is write
something like the following:

Dim mc As New MyClass
Dim i As Integer

i = mc.Value
Textbox1.Text = mc.Value.ToPercent

I have tried to make Value of type MyValueClass, for example, which
inherits

from Int32, but Int32 is not inheritable, so that is a non-starter. In
any
case, the first assignment gives a compile time error because there is
no
default property of MyValueClass, and I can't set one unless it takes
parameters (which it doesn't).

Can anyone suggest how this might be done?

TIA

Charles



"ljlevend" <lj******@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com:
Is there a TypeConverter that converts Doubles to percent values in a
PropertyGrid? The Windows.Forms.Form.Opacity property seems to use the
TypeConverter that I want.

Thank you,
Lance


Nov 20 '05 #3
Thanks for the help, but that isn't quite what I'm looking for. I need a TypeConverter class rather than a technique for converting the value. I could create my own TypeConverter, but I want to make sure that there isn't a standard TypeConverter for converting percents before doing so.

Lance
"scorpion53061" wrote:
View this thread from Jay Harlow and Charles Law. It might help.

-------------

Hi Jay

Thanks for confirming what I was beginning to suspect.

Using the example that I just used to Armin, I would then have

<code>
Public Structure MyValueClass

Public Function ToPercent() As Double
End Function

Public Function ToAbsolute() As Integer
End Function

End Structure

Dim d As Double
Dim i As Integer

d = mc.Value.ToPercent()
i = mc.Value.ToAbsolute()
</code>

showing that I must explicitly call ToAbsolute rather than just write

i = mc.Value

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
news:eZ**************@TK2MSFTNGP11.phx.gbl...
Charles,
Neither VB.NET 2002 nor VB.NET 2003 support what you are attempting, per


se.

You could always:

Public Structure MyValueClass

Public Function ToPercent() As String
End Function

Public Function ToInteger() As Integer
End Function

End Structure

i = mc.Value.ToInteger()
Textbox1.Text = mc.Value.ToPercent()


With VB.NET 2005 (Whidbey) we will be able to override CType, the


conversion
operator, so you will be able to do something like (based on the CTP


release
of Whidbey):

Public Structure MyValueClass

Public Function ToPercent() As String
End Function

Public Function ToInteger() As Integer
End Function

Public Shared Widening Operator CType(value As MyValueClass) As
Integer
Return value.ToInteger()
End Operator

Public Shared Narrowing Operator CType(value As Integer) As
MyValueClass
Return New MyValueClass(value)
End Operator

End Structure

i = mc.Value
mc.Value = CType(i, MyValueClass)

A Widening CType operator does not require CType, while a Narrowing CType
operator does.

Hope this helps
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:ey**************@TK2MSFTNGP11.phx.gbl...

In a VB.NET app, I can write

Dim s As String = 3.ToString

This is because 3 is of type Int32, which is a structure, which has a
method

ToString.

I would also like to be able to write

Dim s As String = 3.ToPercent

by supplying my own implementation of ToPercent. If I could do this,
then
I

would be able to do what I ultimately wish to do, and that is write
something like the following:

Dim mc As New MyClass
Dim i As Integer

i = mc.Value
Textbox1.Text = mc.Value.ToPercent

I have tried to make Value of type MyValueClass, for example, which
inherits

from Int32, but Int32 is not inheritable, so that is a non-starter. In
any
case, the first assignment gives a compile time error because there is
no
default property of MyValueClass, and I can't set one unless it takes
parameters (which it doesn't).

Can anyone suggest how this might be done?

TIA

Charles



"ljlevend" <lj******@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com:
Is there a TypeConverter that converts Doubles to percent values in a
PropertyGrid? The Windows.Forms.Form.Opacity property seems to use the
TypeConverter that I want.

Thank you,
Lance


Nov 20 '05 #4
Check out the OpacityConverter class
That's what the opacity property uses

/claes

"ljlevend" <lj******@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com...
Is there a TypeConverter that converts Doubles to percent values in a PropertyGrid? The Windows.Forms.Form.Opacity property seems to use the
TypeConverter that I want.
Thank you,
Lance

Nov 20 '05 #5
That's exactly what I was looking for. Thanks!

"Claes Bergefall" wrote:
Check out the OpacityConverter class
That's what the opacity property uses

/claes

"ljlevend" <lj******@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com...
Is there a TypeConverter that converts Doubles to percent values in a

PropertyGrid? The Windows.Forms.Form.Opacity property seems to use the
TypeConverter that I want.

Thank you,
Lance


Nov 20 '05 #6

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

Similar topics

2
by: João Santa Bárbara | last post by:
Hi all i have a class that i have made and i made an Typeconverter as well, and my problem is the code genereated in my form is Dim ClassTest1 As TestApplication.ClassTest = New...
2
by: kw | last post by:
I'm getting different behavior from what I would expect and was hoping someone could clue me in. At run time I need to examine a property of an object for a custom TypeConverter, then use that...
1
by: Sky Sigal | last post by:
(PS: Cross post from microsoft.pulic.dotnet.framework.aspnet.webcontrols) I've been looking lately for a way to keep the Properties panel for Controls 'clean'... My goal is to keep similar...
0
by: Eric Hoch | last post by:
Hello, I'm writing a TypeConverter for a class which inherits arraylist, but deserializing it always results in an arraylist, which causes an InvalidCastException. If anyone can point out what...
4
by: Kent Boogaart | last post by:
*tried this already on the buildingcontrols newsgroup but didn't get a response* Hi, As far as I can tell, it is not possible to use the TypeConverter infrastructure with generic types. Say...
4
by: swartzbill2000 | last post by:
Hello, I have a TypeConverter for converting between this Enum and Strings. Public Enum DeviceNameEnum dnNone dn2500 dnMirror End Enum 'DeviceNameEnum
11
by: Rolf Welskes | last post by:
Hello, the problem seems to be complex and is in all developments of web-controls which uses own TypeConverter. For this I have here a simple demo-program of the problem: The Control-code: A...
1
by: --== Alain ==-- | last post by:
Hi, I 'm facing an interesting issue regarding a property and its TypeConverter. When i do not attach a TypeConverter to this property, all custom properties of my custom control are displayed...
6
by: Larry Smith | last post by:
Hi there, Can anyone provide any insight on why MSFT introduced "TypeConverter.GetProperties()". There are two classes for dealing with metadata in .NET, 'Type" and "TypeDescriptor". Each has a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.