IgnaceMaes / MaterialSkin

Theming .NET WinForms, C# or VB.Net, to Google's Material Design Principles.
MIT License
2.86k stars 831 forks source link

Clicking TextBox a second time causes some issues #10

Closed AlexxEG closed 9 years ago

AlexxEG commented 9 years ago

If the user clicks anywhere inside the TextBox a second time, the Hint will disappear. And when using Dark Theme, it will cause a white box to appear inside.

It fixes itself when the mouse leaves the TextBox, or a key is pressed.

Here's a gif (The Hint is still barely visible in the gif, but that's a issue with the gif itself. The Hint does completely disappear when viewing outside the gif)

IgnaceMaes commented 9 years ago

Oh snap, this is very annoying.

It's most likely cause by switching between UserPaint on (for the Hint) and UserPaint off (for the default system TextBox). Ill look around and hope to be able to fix it, but I don't directly see a solution for this. Customizing the TextBox is really a mess because of it not being painted in the paint method. I won't have much time though the next few days/weeks. (because of exams)

AlexxEG commented 9 years ago

I'm making progress by blocking the second mouse click if Hint should be visible. Still not perfect, there is a lot of flickering.

IgnaceMaes commented 9 years ago

Hmm I got this idea, maybe it would be better to completely hide the baseTextBox when the focus is lost & the hint should be shown. The hint could then be drawn in the baseTextBox's parent. And when it gets the focus back the base should be set visible again.

This way it would probably not flicker because it doesn't need the UserPaint flag anymore. The downside would be that when the baseTextBox got focus and the text is empty, the Hint can't be drawn.

AlexxEG commented 9 years ago

That sounds good, but there is 2 possible problems I can see:

  1. Cursor would have to be changed manually to the caret (right name?). This might be easy
  2. The right click menu, it wouldn't be able to show unless the user first selects the control. However if you're planing to create a material design context menu, it might not be a issue.

Actually the default behavior for hints in Windows seems to be to disappear when gaining focus. Which reminds me of something. Using this code:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, string lParam);

SendMessage(TextBox.Handle, 0x1500 + 1, IntPtr.Zero.ToInt32(), "Hint");

You can set the hint of any TextBox, without needing anything else. Only problem is that the hint might be difficult to read on Dark theme since you can't change the hint color with this.

You should try it by inserting it into the BaseTextBox initializer, it might be good enough.

IgnaceMaes commented 9 years ago

Oh wow I didn't knew it was built in!

It's good enough for me, its properly readable in both dark & light. It looks even better than the current implementation because that isn't drawn 100% at where the text would appear when typed. The implementation will avoid many annoying flaws so I'd say we use it instead of the current custom Hint. Can you put it in the code? I'm going to study now :stuck_out_tongue:, if not no problem, then I'll do it tonight.

AlexxEG commented 9 years ago

I remembered having used it before in some old projects and found it again. :)

Yep, I can do it.

AlexxEG commented 9 years ago

Actually, maybe you wanna do it. That way you can close this issue as well. Here is the complete MaterialSingleLineTextField.cs code: http://pastebin.com/VH1m72DE.

Should just have to copy and paste. ;)

IgnaceMaes commented 9 years ago

I'm pretty sure you can just commit and write in the title issue #10, that way it's linked to this thread. Afterwards when I merge it, I can manually close this issue.

I kinda feel like stealing your work if I would commit it :P I'm not 100% sure though, as this is my first ever repository on GitHub.

AlexxEG commented 9 years ago

Ah, didn't know how it would work across repos. I'm not too experienced with GitHub myself. :)