Controls w/option to have a default search message


Author
Message
Derek Price
Derek Price
StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)
Group: Forum Members
Posts: 51, Visits: 376
I really like web sites that have search boxes with the grayed out text message that clears when clicked in. See attached images. It seems that this would be a great feature for the StrataFrame-wrapped controls like the textbox, combobox, etc., especially in BrowseDialogs. This would another little UI feature that would really help the product shine.



Thanks,

Derek
Attachments
Search_Before_Click.png (161 views, 2.00 KB)
Search_After_Click.png (180 views, 2.00 KB)
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Hi Derek,



The feature could be easily implemented by extending the SF TextBox control. Simply add a property for the text that you want to display, then add some code to the get/lose focus events to manage the handling of the text for that property. Look at some other posts about subclassed controls. It is really not hard to do and you may find that other things you'd like implemented will be quite easy for you to handle.



Have a great day!

Bill
Russell Scott Brown
Russell Scott Brown
StrataFrame User (246 reputation)StrataFrame User (246 reputation)StrataFrame User (246 reputation)StrataFrame User (246 reputation)StrataFrame User (246 reputation)StrataFrame User (246 reputation)StrataFrame User (246 reputation)StrataFrame User (246 reputation)StrataFrame User (246 reputation)
Group: Forum Members
Posts: 124, Visits: 597
Les Pinter has an article about subclassing SF controls (textbox) that might help further:

http://lespinter.com/FoxToNet/ShowArticle.aspx?ArtNum=414

Russ Brown (Using C#2010/SQL Server 2008)

Les Pinter
Les Pinter
StrataFrame Team Member (65 reputation)StrataFrame Team Member (65 reputation)StrataFrame Team Member (65 reputation)StrataFrame Team Member (65 reputation)StrataFrame Team Member (65 reputation)StrataFrame Team Member (65 reputation)StrataFrame Team Member (65 reputation)StrataFrame Team Member (65 reputation)StrataFrame Team Member (65 reputation)
Group: Forum Members
Posts: 43, Visits: 213
Hi Derek,

   The file MyControls.vb listed below is approximately how you could do it. I couldn't resist. Just add it to your project, then drop instances on your form, setting the +Pinter/InititalText property for each textbox to the prompt you want to see in each empty textbox. (I subclassed TextBox because I just got my laptop back from HP and haven't yet reinstalled SF, but this should give you a leg up.) Some of it, like the BackColor handling, is tentative and not really necessary.

 ----------------------------------------------------------------------------------------

Imports System.Windows.Forms
Imports System.ComponentModel

Public Class MyTextBox : Inherits TextBox

Private OriginalColor As Color

Private _InitialText As String = ""
<Browsable(True), _
 Bindable(True), _
 Category("+Pinter"), _
 DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property InitialText() As String
 Get
  Return _InitialText
 End Get
 Set(ByVal value As String)
  _InitialText = value
  Text = _InitialText
 End Set
End Property

 Sub New()

  Font = New System.Drawing.Font("Courier New", _
   9.0!, _
   System.Drawing.FontStyle.Regular, _
   System.Drawing.GraphicsUnit.Point, _
   CType(0, Byte))
   BackColor = Color.Ivory

 End Sub

 Private Sub MyTextBox_Enter( _
  ByVal sender As Object, ByVal e As System.EventArgs) _
  Handles Me.Enter

  BackColor = Color.White
  OriginalColor = ForeColor
  ForeColor = Color.Black

  If InitialText IsNot Nothing Then
    If Text.TrimEnd() = InitialText Then
     Text = ""
    End If
  End If

 End Sub

 Private Sub MyTextBox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) _
  Handles Me.Leave

  If InitialText IsNot Nothing Then
    If Text.TrimEnd() = "" Then
     Text = InitialText
    End If
  End If
  BackColor = Color.Ivory
  ForeColor = OriginalColor

 End Sub

End Class

----------------------------------------------------------------------------------------

Les

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)StrataFrame VIP (1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
If the textbox is to be bound, make sure to strip that InitialText value from the Text property before saving. There may be a way to overlay that initial text, too, rather than replace the Text property. Just thinking out loud. Les have given you a great start, though. Have fun!!
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.7K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I haven't tried this, so it might not work, but I'd actually look into overriding the OnPaint method. If there is Text set, just do default (base.OnPaint), otherwise render the InitialText. That way you wouldn't have to worry about handling accidentally saving the InitialText and you'd only have one method to override (rather than a set of events). I.e. this would more clearly separate the text that is initially shown vs. the Text that is bound.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.7K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I couldn't help myself. I had to try the OnPaint method. It wasn't easy. I just posted my test project in the user samples area:



http://forum.strataframe.net/FindPost25587.aspx



It is kind of cool, but doesn't perform as well as I'd like. It is a good example of how to do this sort of thing (and maybe why not to do it), so you might want to check it out. This drawing stuff isn't easy.... Blink
Derek Price
Derek Price
StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)StrataFrame Novice (89 reputation)
Group: Forum Members
Posts: 51, Visits: 376
Wow you guys are fast! I was just pondering this idea yesterday and you've already implemented it. Well done! We've sub-classed many of the controls to add our own stuff as well. It just seemed like a "wouldn't it be nice" feature for all StrataFrame users. Now I have to find the time to see what you've done.



Thanks again!

Derek
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search