thielj / MetroFramework

Metro UI of Windows 8 for .NET Windows Forms applications
http://thielj.github.io/MetroFramework
Other
401 stars 225 forks source link

MouseEvents? #26

Closed LiamKenyon closed 10 years ago

LiamKenyon commented 10 years ago

Ok i'm trying to setup when a textbox is clicked into the box clears,

I can do this with standard textboxs using the following:

Private Sub TextBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    TextBox2.Text = ""
End Sub

How would i change it so can do it with a "Metro" textbox?

Tried the following:

Private Sub MetroTextBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    MetroTextBox2.Text = ""
End Sub

But nothing happens. Any help?

gofal commented 10 years ago

Hi,

you have to handle the Click-Event. The MetroTextBox is not inherited from System.Windows.Forms.TextBox, but it is inherited from MetroFramework.Controls.MetroControlBase and all the Textbox-things are implemented manually. So not every Event and method that you are used to use with System.Windows.Forms.TextBox is currently supported - maybe it will be in future Releases? Currently you can use: SizeChanged, CursorChanged, ContextMenuStripChanged, ContextMenuChanged, ClientSizeChanged, Click, ChangeUICues, CausesValidationChanged, KeyUp, KeyPress, KeyDown, TextChanged.

If you realy Need more Events, then tell me. I have downloaded the sources and have done quite some changes and some new controls to make the Project suit to my product. I an new to github so I have not jet realized how to contribute my changes, but if i know that someone else Needs it too then i would try to find out how to check in some changes.

LiamKenyon commented 10 years ago

Hi Gofal,

Thanks for explaining that to me.

I would like the ability to clear the textbox when the user clicks in as its looks a little more professional than having to highlight and clear the text.

I wonder if i can manage this with the click function. But i would like to be able to do the MouseDown or something equivalent.

If you are able to share what you have that would be great :)

gofal commented 10 years ago

Of course you can achive this Feature wth the click-event too. When the user cliks into any control, then Windows raises three Events in this order: MouseDown, Click, MouseUp ( http://msdn.microsoft.com/en-us/library/ms171542(v=vs.110).aspx ). So you can use Click instead of MouseDown. The only reason why you could Need MouseDown is, when you want to implement something, that happens while the user presses the mouse button down until the user Releases the button again, eg some Kind of Drag&Drop or some Kind of drawing or moving someting.

I am not sure if it is so good, that all the text is erased if the user clicks into the TextBox. for exapmple he fills in some Input and then continues with other TextBox and then finds that he has made a typo-error and wants to correct it. he clicks into the TextBox and instead of correcting the one or two letters he as to retype the whole Input. Or what if the user is not he Kind of mouse-user, but rather the Kind of user who uses the tab-button to go from one TextBox to an other. I dont know you exakt Intention, but maybe you shold take a look at the "ProptText"-Property of the MetroTextBox. There you can define some descriptive text (eg "enter you Name here") that will be displayed in the TextBox, if the "Text"-Property is empty. So if you enter the TextBox via clikc or via tab and type the first letter, then this propttext disapears and the typed text is shown. If then later the user clicks into the TextBox, then his Prior Input will not be deleted.

LiamKenyon commented 10 years ago

Hi Gofal,

Thanks for the reply.

I'm either being really stupid (and blind) but i can't find the "prompttext" option in metrotextbox.

Am i being really dense or is there an example you can show me?

Edit: Completley ignore this.

For some reason it had another version of MetroFramework installed which used outdated NuGet Package.

All sorted now.

Thanks.