Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Controls
  New Posts New Posts RSS Feed - Multiline FlatEdit & Default Controls
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Multiline FlatEdit & Default Controls

 Post Reply Post Reply
Author
Message
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Topic: Multiline FlatEdit & Default Controls
    Posted: 27 May 2008 at 12:20am
Hi,

I thought I'd pass on a helpful little code snippet that I am using. First some background:

When the FlatEdit control has its MultiLine property set to True and your form contains another control with the Default property set to True, hitting Enter/Return in the FlatEdit control will trigger the Default control. The user needs to press Ctrl+Enter in order to add newlines to the FlatEdit control in this scenario (which may be undesirable).

Here's some code that will temporarily hold the default control while the multiline FlatEdit has focus, and restore the default control when the FlatEdit control loses focus:


Private Sub HoldDefaultControl(ByVal pHold As Boolean)
   '---------------------------------------------------------------------------------------
   ' Procedure  : HoldDefaultControl
   ' Purpose    : To set/unset the default property of another control on the parent of
   '              this usercontrol
   ' Parameters : pHold - TRUE (hold a reference to the current default control and
   '                            set its Default property to FALSE)
   '                      FALSE (set the Default property of the held reference to the
   '                             former default control to TRUE)
   '---------------------------------------------------------------------------------------
  
   Static sobjDefaultControl As Control
   Dim objCtrl As Control
   Dim blnFoundDefault As Boolean
  
   ' Remove default control from parent if it exists so
   ' user can hit enter in multiline textbox
   If pHold Then
      If sobjDefaultControl Is Nothing Then
     
         ' Loop through the controls on the parent form until we find the default control
         For Each objCtrl In Me.Controls
     
            ' Trap errors in case this control doesn't support default property
            On Error Resume Next
            blnFoundDefault = objCtrl.Default
            On Error GoTo 0
           
            If blnFoundDefault Then
               ' We have found the default control
               Set sobjDefaultControl = objCtrl ' Store a reference to this control
               Exit For ' Short circuit the loop since we found what we were looking for
            End If
         Next objCtrl
      End If
   End If
  
   If Not sobjDefaultControl Is Nothing Then
      ' If there is/was a default control
      sobjDefaultControl.Default = Not pHold ' Set or Unset the default property as required
   End If
End Sub


And to use it:


Private Sub FlatEdit1_GotFocus()
   If Me.MultiLine Then
      HoldDefaultControl True
   End If
End Sub

Private Sub FlatEdit1_LostFocus()
   HoldDefaultControl False
End Sub  


Hope this is helpful for someone!
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
Aaron View Drop Down
Senior Member
Senior Member
Avatar

Joined: 29 January 2008
Status: Offline
Points: 2192
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aaron Quote  Post ReplyReply Direct Link To This Post Posted: 27 May 2008 at 12:51am
Jason,
 
Just curious, when I add a Flatedit and a button (set to default) to a form, the Enter key will set the focus to the button or what? In my case the flatedit does nothing at all with the Enter key (staying in focus thats what it does)
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 27 May 2008 at 9:43am
Hi Aaron,

Did you put any code in your Button_Click event? Pressing the enter key at any time on a form with a Default button *should* be the same as clicking that button with the mouse (at least it has been that way in my experience). This is usually a desired result, but it is annoying when you need a multiline textbox on a form.
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
Aaron View Drop Down
Senior Member
Senior Member
Avatar

Joined: 29 January 2008
Status: Offline
Points: 2192
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aaron Quote  Post ReplyReply Direct Link To This Post Posted: 28 May 2008 at 12:46am
Hi,
 
Yes, now I know what you mean. It looks more like a bug to me. I don't see this when I use a MS textbox (when focused ENTER is next line) and this is how it should be !!!
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....
Back to Top
ijwelch View Drop Down
Senior Member
Senior Member


Joined: 20 June 2006
Status: Offline
Points: 262
Post Options Post Options   Thanks (0) Thanks(0)   Quote ijwelch Quote  Post ReplyReply Direct Link To This Post Posted: 26 October 2008 at 11:14pm
Can anyone from CJ say if this is going to be changed for 12.1?
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 27 October 2008 at 2:57pm
I was hoping SetWindowLong with ES_WANTRETURN would fix this problem, but I just tried it and it didn't help...This is the code I used (in case anyone notices a bug that would prevent it from working):


Option Explicit

Private Const ES_WANTRETURN = &H1000
Private Const GWL_STYLE = (-16)
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Sub Form_Load()
   Dim l_Style As Long
  
   ' Get current FlatEdit style
   l_Style = GetWindowLong(Me.FlatEdit1.hwnd, GWL_STYLE)
   ' Ensure ES_WANTRETURN style flag is set
   SetWindowLong Me.FlatEdit1.hwnd, GWL_STYLE, l_Style Or ES_WANTRETURN
  
   ' Test to see if ES_WANTRETURN style was set properly
   l_Style = GetWindowLong(Me.FlatEdit1.hwnd, GWL_STYLE)
   Debug.Print l_Style And ES_WANTRETURN    ' Should print 4096 if set properly
End Sub

Private Sub PushButton1_Click()
   ' Shouldn't fire when user hits Enter while FlatEdit1 has focus
   ' Even when Default property = True
   MsgBox "A"
End Sub

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.186 seconds.