TextBox's property

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

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
 
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.
 
Agnes said:
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.HorizontalAlignment.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
 
Hi,

Disregard my last reply. I was thinking an ASP:Textbox, not a Windows Forms
control. Ken.
 
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.
 
Dennis said:
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
 
Thanks.

Larry Serflaten said:
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
 

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

Back
Top