By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,582 Members | 1,694 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,582 IT Pros & Developers. It's quick & easy.

TextBox's property

P: n/a
I create my own usercontrol (textbox), I new a property 'Type'
I will set this property during design mode, I will set 'I' OR 'C', i stands
for integer, c stands for character,
Now, In that usercontrol, I want to detect that property , if the propety
set to "I", the textalign will set to 'right'

iF ME.TYPE ='I"
Me.textAlign = HorizontalAlignment.Right
endif
if Me.type = "C"
Me.textAlign = HorizontalAlignment.left
endif

I put the above code in InitLayout(), but it seems didn't work . Where
Should I place these code ???
Thanks a lot
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi,

I think it isn't working because a textbox doesn't have a
HorizontalAlignment. Labels do though. But textboxes are always aligned on
the left side. So if you inherit from Label instead of Textbox you should
be on the right track. Do you have VS.Net? It will show the properties
available. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I create my own usercontrol (textbox), I new a property 'Type'
I will set this property during design mode, I will set 'I' OR 'C', i stands for integer, c stands for character,
Now, In that usercontrol, I want to detect that property , if the propety
set to "I", the textalign will set to 'right'

iF ME.TYPE ='I"
Me.textAlign = HorizontalAlignment.Right
endif
if Me.type = "C"
Me.textAlign = HorizontalAlignment.left
endif

I put the above code in InitLayout(), but it seems didn't work . Where
Should I place these code ???
Thanks a lot

Nov 21 '05 #2

P: n/a

"Agnes" <ag***@dynamictech.com.hk> wrote
I create my own usercontrol (textbox), I new a property 'Type'
I will set this property during design mode, I will set 'I' OR 'C', i stands
for integer, c stands for character,
First, that should be an Enumeration,

Second "Type" is a basic variable type, it would be best to choose
some other name

Now, In that usercontrol, I want to detect that property , if the propety
set to "I", the textalign will set to 'right'
I put the above code in InitLayout(), but it seems didn't work . Where
Should I place these code ???
Thanks a lot

You should put it in the public property. For example, if your control
has only one textbox, then you don't need to keep a variable at all, you
can just set and return the value directly from the textbox:
Public Property TextAlign() As Windows.Forms.HorizontalAlignment
Get
Return Me.TextBox1.TextAlign
End Get
Set(ByVal Value As Windows.Forms.HorizontalAlignment)
Me.TextBox1.TextAlign = Value
End Set
End Property
Also, if you plan to let others use it, you might want to add attributes
to set the defaults, and add a description. Attributes go ahead of the
property declaration:

<ComponentModel.Category("Appearance"), ComponentModel.Description("Indicates how the text should be aligned."), _
ComponentModel.Browsable(True), ComponentModel.DefaultValue(Windows.Forms.Horizont alAlignment.Left)> _
Public Property TextAlign() As Windows.Forms.HorizontalAlignment
(That is all on one line, note the _ continuation character)

(Also: Imports System was assumed, otherwise use:
System.ComponentModel....)

HTH
LFS
Nov 21 '05 #3

P: n/a
Hi,

Disregard my last reply. I was thinking an ASP:Textbox, not a Windows Forms
control. Ken.

"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I think it isn't working because a textbox doesn't have a
HorizontalAlignment. Labels do though. But textboxes are always aligned on the left side. So if you inherit from Label instead of Textbox you should
be on the right track. Do you have VS.Net? It will show the properties
available. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I create my own usercontrol (textbox), I new a property 'Type'
I will set this property during design mode, I will set 'I' OR 'C', i

stands
for integer, c stands for character,
Now, In that usercontrol, I want to detect that property , if the propety set to "I", the textalign will set to 'right'

iF ME.TYPE ='I"
Me.textAlign = HorizontalAlignment.Right
endif
if Me.type = "C"
Me.textAlign = HorizontalAlignment.left
endif

I put the above code in InitLayout(), but it seems didn't work . Where
Should I place these code ???
Thanks a lot


Nov 21 '05 #4

P: n/a
Larry, I was curious by your comment "that should be an enumeration". I
gathered that you thought that "type" property should not only have it's name
changed to avoid conflicts but also is should be an enumeration rather than a
property. I am new to VB.Net and was wondering exactly what you meant by
this. I looked at the help on enumerations but was unable to grasp your
intent. Thanks for any clarification.

"Larry Serflaten" wrote:

"Agnes" <ag***@dynamictech.com.hk> wrote
I create my own usercontrol (textbox), I new a property 'Type'
I will set this property during design mode, I will set 'I' OR 'C', i stands
for integer, c stands for character,


First, that should be an Enumeration,

Second "Type" is a basic variable type, it would be best to choose
some other name

Now, In that usercontrol, I want to detect that property , if the propety
set to "I", the textalign will set to 'right'


I put the above code in InitLayout(), but it seems didn't work . Where
Should I place these code ???
Thanks a lot

You should put it in the public property. For example, if your control
has only one textbox, then you don't need to keep a variable at all, you
can just set and return the value directly from the textbox:
Public Property TextAlign() As Windows.Forms.HorizontalAlignment
Get
Return Me.TextBox1.TextAlign
End Get
Set(ByVal Value As Windows.Forms.HorizontalAlignment)
Me.TextBox1.TextAlign = Value
End Set
End Property
Also, if you plan to let others use it, you might want to add attributes
to set the defaults, and add a description. Attributes go ahead of the
property declaration:

<ComponentModel.Category("Appearance"), ComponentModel.Description("Indicates how the text should be aligned."), _
ComponentModel.Browsable(True), ComponentModel.DefaultValue(Windows.Forms.Horizont alAlignment.Left)> _
Public Property TextAlign() As Windows.Forms.HorizontalAlignment
(That is all on one line, note the _ continuation character)

(Also: Imports System was assumed, otherwise use:
System.ComponentModel....)

HTH
LFS

Nov 21 '05 #5

P: n/a

"Dennis" <De****@discussions.microsoft.com> wrote
Larry, I was curious by your comment "that should be an enumeration". I
gathered that you thought that "type" property should not only have it's name
changed to avoid conflicts but also is should be an enumeration rather than a
property. I am new to VB.Net and was wondering exactly what you meant by
this. I looked at the help on enumerations but was unable to grasp your
intent. Thanks for any clarification.

The intent to was to suggest making that control look and feel more like
other controls.

Put a textbox (for example) on a form and change its TextAlign property.
You'll note to do that, you select from a drop down list. The method to
get the property grid to display that drop down list is to use an enumeration.

More over, using a character to effect behavior or appearance is also not
a very common approach. Look around, see if you can find a property that
want's you to enter a character, where the character effects behaviour or
appearance, and not a value or state. (ie, not a Text value or Name property)

As developers, we really need to think about what our users expect from
an application (or other piece of software). The advantage of Windows
is that many tasks are common across many applications which allows
the users to quickly grasp how to get things done, without a large amount
of learning new processes. The same goes for that small control, as it
does for a full blown application. If it acts and responds like many of
the other controls, the developers who need to put it to use already have
a large part of the knowlege they need to interact with it.

Finally, enumerations help to document code. Which would be easier
to read and understand:

control.TextAlign = "i"

Or

control.TextAlign = HorizontalAlignment.Right

As you see, "i" says nothing about what the property is beng set to do....

LFS
Nov 21 '05 #6

P: n/a
Thanks.

"Larry Serflaten" wrote:

"Dennis" <De****@discussions.microsoft.com> wrote
Larry, I was curious by your comment "that should be an enumeration". I
gathered that you thought that "type" property should not only have it's name
changed to avoid conflicts but also is should be an enumeration rather than a
property. I am new to VB.Net and was wondering exactly what you meant by
this. I looked at the help on enumerations but was unable to grasp your
intent. Thanks for any clarification.

The intent to was to suggest making that control look and feel more like
other controls.

Put a textbox (for example) on a form and change its TextAlign property.
You'll note to do that, you select from a drop down list. The method to
get the property grid to display that drop down list is to use an enumeration.

More over, using a character to effect behavior or appearance is also not
a very common approach. Look around, see if you can find a property that
want's you to enter a character, where the character effects behaviour or
appearance, and not a value or state. (ie, not a Text value or Name property)

As developers, we really need to think about what our users expect from
an application (or other piece of software). The advantage of Windows
is that many tasks are common across many applications which allows
the users to quickly grasp how to get things done, without a large amount
of learning new processes. The same goes for that small control, as it
does for a full blown application. If it acts and responds like many of
the other controls, the developers who need to put it to use already have
a large part of the knowlege they need to interact with it.

Finally, enumerations help to document code. Which would be easier
to read and understand:

control.TextAlign = "i"

Or

control.TextAlign = HorizontalAlignment.Right

As you see, "i" says nothing about what the property is beng set to do....

LFS

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.