• Welcome to PlanetSquires Forums.
 

Mask Edit / Textbox

Started by Petrus Vorster, January 27, 2023, 06:08:31 AM

Previous topic - Next topic

Petrus Vorster

Good Day Gents

I love the new Textbox. Especially the queue banner text.
But i am in need of a Masked input and I don't seem to get the hang of the Maskedinput control.

Would someone please just show me how to set up a CURRENCY i.e Currency Symbol, 4 digits with 2 decimals? RIGHT aligned please.
If one can do it in the TEXTBOX control, I will nicely fit with the other controls.

Some pointers will be most appreciated.

Regards, Peter
-Regards
Peter

Paul Squires

Hi Peter,

I am working on some sample code for you now. It is based on some old FireFly code that I posted here in the forum 10 or 11 years ago.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Hi Peter,

Here you go. Here is some code to get you started. You manipulate the "KeyPress" event for the TextBoxes. You can also set the TextBox's TextAlign property to align the text to the right or left. You can have multiple TextBoxes call the ProcessTextBoxKeys thereby eliminating duplicate code.

'--------------------------------------------------------------------------------
function ProcessTextBoxKeys( _
            byval hWndControl as HWND, _
            byval chCharCode  as long _
            ) as boolean
                           
  ' This function is called from the KeyPress message handler for
  ' the TextBox wanting to filter numeric data.
  dim as CWSTR wst = AfxGetWindowText( hWndControl )
  dim as long maxDecimalPlaces = 2
  dim as long periodPos = instr(wst, ".")
  dim as long minusPos = instr(wst, "-")

  select case chCharCode
      case 8  'backspace always allow
        return false
 
      case 45  ' minus sign (only allow one)
        return iif(minusPos, true, false)
        ' May want to add additional logic to only allow the minus if at the
        ' start of the text or if at the end depending on your needs.

      case 46  ' period (only allow one)
        return iif(periodPos, true, false)

      case 48 to 57  ' numbers
        ' We will allow all numbers *except* in the case where a decimal has
        ' already been entered and we have reached the maximum number of
        ' decimal places.
        if periodPos then
            return iif( len(wst) - periodPos >= maxDecimalPlaces, true, false )
        else 
            return false    ' always allow
        end if
 
  end select

  ' don't allow anything else                             
  return true                             
end function
           
           
''
''
Function frmMain_Text1_KeyPress( ByRef sender As wfxTextBox, ByRef e As EventArgs ) As LRESULT
  ' If the key pressed is not valid then the handler
  ' will return TRUE thereby stopping processing of that key.
  e.handled = ProcessTextBoxKeys( sender.hWindow, e.KeyChar )

  Function = 0
End Function

''
''
Function frmMain_Text2_KeyPress( ByRef sender As wfxTextBox, ByRef e As EventArgs ) As LRESULT
  ' If the key pressed is not valid then the handler
  ' will return TRUE thereby stopping processing of that key.
  e.handled = ProcessTextBoxKeys( sender.hWindow, e.KeyChar )

  Function = 0
End Function
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Petrus Vorster

Hi Paul

Thank you very much.
It dawned upon me that we did this is Firefly, but I have not been able to make it work yet in the new designer.

Its been going slow here a bit due to other issues, so I have not been around projects much lately.

This will be of great help. Thanks a million.

Regards,

Peter
-Regards
Peter