|
-
Apr 16th, 2007, 07:08 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Textbox TextAlign and SelectAll in CompactFramework
Still adapting to .NET, it really is a different animal than VB6.
I have found that there are some slight differences in the TextBox object in the Compact Framework.
First, the TextAlign property can be used to set the textbox's alignment to HorizontalAlignment.Center, for example. In the CF 2.0, only HorizontalAlignment.Left is available on Multiline = True. MSDN details this information, "Platform Note: In Pocket PC-based applications, a single-line text box supports only left alignment. A multiline text box can be aligned on the left, right, or center. "
Is there any problem using a single line textbox with Multiline = true so that the pther alignments can be used, for example a currency field?
Second, when the Shown event fires, you can use the following code to select all text in a textbox control.
Code:
TextBox1.Focus()
TextBox1.SelectAll()
In the CF 2.0, this same code cannot be used in the Shown event because it is not supported, so must use the Activated event. Also, for the code to work properly I must set the TabIndex = 0. Otherwise the form loads and becomes Activated without selecting the text in the textbox.
What would be the proper code to select all text in a textbox control after a form has been loaded?
Last edited by easymoney; Apr 16th, 2007 at 07:19 AM.
-
Apr 16th, 2007, 07:20 AM
#2
Frenzied Member
Re: Textbox TextAlign and SelectAll in CompactFramework
Hi,
first point - suggest you test it to see.
second point - use the gotfocus event of the text box
Pete
-
Apr 16th, 2007, 07:33 AM
#3
Thread Starter
Hyperactive Member
Re: Textbox TextAlign and SelectAll in CompactFramework
I am currently using several single line textbox with multiline set to true for displaying right aligned values such as numbers and currency. It works, seems the only way since the CF 2.0 does not support center and right alignment with multiline = false.
It works so far, just wondering if there are any side effects or unseen dangers using this method?
-
Apr 16th, 2007, 07:40 AM
#4
Frenzied Member
Re: Textbox TextAlign and SelectAll in CompactFramework
Hi,
if it works ok, it SHOULDN'T pose any problems. A lot of CF programming is finding theses little ways around things that aren't directly supported.
There again, the run time is < 2mb as opposed to > 22mb 
Pete
-
Apr 22nd, 2007, 02:44 AM
#5
Thread Starter
Hyperactive Member
Re: Textbox TextAlign and SelectAll in CompactFramework
Okay, this is just one of those things. Some objects and methods are very version specific. This is an example.
The multiline feature works well to allow the right alignment of text in the CF 2.0. But when I press enter on my handheld keypad, the value in the textbox disappears, most likely because it moves to the next line.
So my next thought was to capture the Enter key in the keypress event:
Code:
SuppressKeyPress = True
But this is specific to .Net 2.0 and not the CF 2.0.
So how do I trap the Enter key so that I can execute other code and hence prevent the single line (but multiline for Right Align) Textbox for being wiped out?
Maybe I need to open a new topic, but it is related to this question... idk
-
Apr 22nd, 2007, 02:52 AM
#6
Thread Starter
Hyperactive Member
Re: Textbox TextAlign and SelectAll in CompactFramework
And the e.KeyChar is read only so I can't null it....
-
Apr 22nd, 2007, 03:03 AM
#7
Thread Starter
Hyperactive Member
Re: Textbox TextAlign and SelectAll in CompactFramework
This blocks the Enter key:
Code:
Private Sub txtCurrent_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCurrent.KeyPress
If e.KeyChar = ChrW(Keys.Return) Then
' place subroutine here if you need to process something before Enter key is destroyed
e.Handled = True
End If
End Sub
Solved!
Last edited by easymoney; Apr 22nd, 2007 at 04:00 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|