Can buttons not have multiline text?

  • Thread starter Thread starter JamesL
  • Start date Start date
J

JamesL

In eVB if my text was longer then the space on the button it wrapped to a
second line. In VB.Net it truncates. Is there a way to make a multiline
text button?

James Lysaght
 
You'll need to p/invoke. The code below should point you in the right
direction.

Imports System.Runtime.InteropServices

<DllImport("Coredll.dll")> _
Private Shared Function GetCapture() As IntPtr
End Function

<DllImport("Coredll.dll")> _
Private Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As
Integer) As Integer
End Function

<DllImport("Coredll.dll")> _
Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As
Integer, ByVal dwNewLong As Integer) As Integer
End Function

Private Const GWL_STYLE As Integer = -16
Private Const BS_MULTILINE As Integer = &H2000

....

' The code below modifies the style of a Button control
' named "Button1" to allow the text to wrap.
Dim hWnd As IntPtr
Dim style As Integer
Me.Button1.Capture = True
hWnd = GetCapture()
Me.Button1.Capture = False
style = GetWindowLong(hWnd, GWL_STYLE)
SetWindowLong(hWnd, GWL_STYLE, style Or BS_MULTILINE)
 
I tried this, putting the code for the button control in the form load
event. No errors, and also not action. Did I put the code in the
wrong place?

James Lysaght
 
I added the invalidate, stillno error, and wrapped text. Text is still
all on one line.

James Lysaght
 
The load event is a correct place and Tim's code works well for PPC as
well as for WindowsCE. Try to implement a small application to test it.
Also try to insert Chr(13) between two part of your long text:

Button1.Text = "Long Long" + Chr(13) + "Long Text"
 
One thing to do is to always ensure that the latest service pack is on the
device/emulator. I'm not sure if it would make a difference in this
situation but it's a good idea to be running the latest SP when possible.
http://www.microsoft.com/downloads/...11-194b-4c00-b445-f92bec03032f&DisplayLang=en

The code that I posted, reposted below, I had in the "Sub New" method (aka
constructor) of the Form containing the Button.

Dim hWnd As IntPtr
Dim style As Integer
Me.Button1.Capture = True
hWnd = GetCapture()
Me.Button1.Capture = False
style = GetWindowLong(hWnd, GWL_STYLE)
SetWindowLong(hWnd, GWL_STYLE, style Or BS_MULTILINE)
 
OK,

I got it to work only to find out I can't use it!

It works well as described. Unfortunately, I perform other tasks that
are dependant on the content of the button text. The line break is
creating problems with the follow-up code. If I stick with the
multiline button text then I have to set up variables to track what I
really wanted to say on the buttons. If I need to track that
elsewhere, then there is really no point within the requirements
specifcations of my program to bother with putting it all on the
button. Also I just do not want to grow the program that much.

I think it is a better trade off for my specific design to limit the
button content to the length of text that fits on the button.

This was deffineitely a worth while exercise for me though. I learned
a lot!

Thanks for the help.

James Lysaght
 
Although I don't know the exact requirements for your application, it's a
good idea to try to limit the text displayed on the Button to two words or
less since the screen space is limited. This recommendation actually comes
straight from the PPC UI guidelines, and I'm assuming that this
recommendation would apply to vanilla CE devices as well.
http://msdn.microsoft.com/library/d...i_guide_ppc/html/ppc_command_buttons_vhux.asp

You may consider hoisting the extra text from the Button and either placing
it in a Label above the Button or, if the extra information is something
that a user could learn from the help file, you may consider outlining this
information within a help file.
 
You really don't want, in general, to use the text of a button to drive how
your code performs. Think about localizing the application into another
language. You don't want to involve the program logic in that operation,
but your current architecture would require that. Much better to use the
button events or, in the case of standard Windows applications, ID code
values, to control the program logic, allowing you to fix problems with the
text and/or localize it without having strange behavior result.

Paul T.
 
I agree... but in this case the program is not dependant on the content
of the text for logical execution. It passes the text to other
controls for further use. The user configures the text to be whatever
he wants it to be, in any language, that way the program is always in
the users native language.

James Lysaght
 
I'm doing this on Windows CE 5.0 with the Compact Framework 2.0 and
would like the squeeze the lines together more. How is that done?
 
Back
Top