leocb / MaterialSkin

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

MaterialTextBox2 issue on initialization #238

Closed valimaties closed 3 years ago

valimaties commented 3 years ago

( Copied from #227 )

Hi @VolatilePulse . I downloaded your branch (aero-snapping) and tried in my project. Form size it will remains as it has been set before open it. That is very good. But another problem it is happening with MaterialTextBox2 control in this branch. It doesn't loose focus (all textboxes has that colored focus bar in the bottom of control), only on initialization of form. Also, when I close a modal form, all textboxes will change its backcolor but only on text area. Pictures below:

MTB1

MTB2

This is a video showing the behavior:

https://user-images.githubusercontent.com/49796453/136949109-886f0c90-e8f3-41f3-a6ee-83fda6b2f1a6.mp4

VolatilePulse commented 3 years ago

I took a brief look at this issue last night and couldn't reproduce it with the demo application. Is it possible for you to create a small application so we can reproduce this issue? I will try tonight to create multiple text boxes and utilize a modal window to see if I can reproduce the issue.

VolatilePulse commented 3 years ago

I added a few extra MaterialTextBox2s to the sample application and used a MaterialDialog to replicate your use of a modal and I can not reproduce this issue. I would need you to create a small application so I could identify the specific issue.

valimaties commented 3 years ago

I made a small project. I found that focus bar problem does not happens in this project, but background did. You have the solution in attached zip file. In gif file I also show a small problem with cursor when mouse over. It changes to IBeam only when the mouse is over the text area, not over the all control, which must be the default cursor of the entire object.

StrangeBehavior

Test.zip

valimaties commented 3 years ago

The problem with focused textboxes is starting from design... I think it is an isolated case, so this issue can be solved in the future, if you can find the problem, if you can reproduce it. In example bellow, all textbox controls are custom MaterialTextBox2, named MyMaterialTextBox. And as you can see, a new instance of those focused controls are created with focused effect. A new instance of this class is created ok ("myMaterialTextBox" object in the end of gif). So, I think there must be made something in object's constructor to invalidate object even in designer mode.

StrangeBehavior2

VolatilePulse commented 3 years ago

I spent some time this morning looking at the project and I couldn't reproduce any of the issues you mentioned. I noticed you had included the bin directory. I even ran the last binary that you built on my system and did not experience the same issues you outlined.

This is a system dependent bug and may be difficult to track down. Are you familiar with Windows Sandbox? If so, copy the binary directory into a fresh instance of sandbox (you may require additional dependencies) and attempt to run the program there and see if you encounter the same issue. A fresh virtual machine would also work. The goal here is to eliminate as many factors as possible that could be affecting the behavior like 3rd party software.

Edit: As a side note, I noticed that you're using .NET 5. This library is not technically supported in .NET 5, yet.

valimaties commented 3 years ago

Edit: As a side note, I noticed that you're using .NET 5. This library is not technically supported in .NET 5, yet.

Yes, I know. But, as long as on your computer everything works ok, seems on my Windows it is happening something. I will try to install a virtual machine, with a clean W10, without any program, but VS. If there is ok it means some third-party application is doing something. Or maybe video driver, who knows?! I have to make these tests...

orapps44 commented 3 years ago

I've made a PR for cursor mouse over issue.

Regarding background, I've made some trial using framework 4.6.1 & 4.7.2 but I wasn't able to reproduce background issue. May be related to .NET 5 ...

valimaties commented 3 years ago

I've made a PR for cursor mouse over issue.

Regarding background, I've made some trial using framework 4.6.1 & 4.7.2 but I wasn't able to reproduce background issue. May be related to .NET 5 ...

Hi @orapps44 . Unfortunately, it is not a .Net5 issue. I've made a .Net Framework project and test the above behavior. It's happening on framework, too. So, definitely, it is an OS depending bug, as @VolatilePulse said. Very strange.

StrangeBehaviorFramework

valimaties commented 3 years ago

I have made a test now. Practically, I've made baseTextBox property from MaterialTextBox2 as public object, to be able to see its properties. So this is happening:

BaseTextboxBackColor_Problem

I think you must review OnPaint event of MaterialTextBox2, or BlendColor method from DrawHelper. Something is happening when sets BackColor of baseTextBox!!! I suggest to think of making baseTextBox a transparent TextBox object, by activating transparent style for BaseTextBox control! You don't need a background color for this control, as long as entire parent control (MaterialTextBox2) have its BackColor and all needed colors for different states (focused, mouse hover, disabled, etc...). But if it is a hard process rewriting BaseTextBox, then the only option remaining is to look at those two methods, OnPaint and BlendColor.

VolatilePulse commented 3 years ago

I don't believe this is specifically an OS bug. I believe it may be related to other software on your system that may be causing you to see different results than we do. Have you been able to test your application in a fresh Win10 environment yet to rule out other possible issues?

Once we can reproduce this issue, a fix can be worked on. As of now, I have not experienced any issues with the OnFocus event that you have pointed out. Since there could be a wide range of things causing this issue, like accessibility software, we would need to know what is causing it and look for a work around. It could also be a GPU issue, but I feel that is unlikely.

valimaties commented 3 years ago

I run this exe on a virtual W10 machine (clean install). The same experience!

Edit: My PC, at home: W10 x64, the same problem!!! Eroare

valimaties commented 3 years ago

@VolatilePulse , when you (we, in general) make an application, you don't install it on a clean system and use only that application in that system. A lot of applications could be installed on system, so, this MaterialSkin must work with other applications installed. The thing here is to make it work on all systems, all Windows versions, and to see what is happening on some of them and why, and what is happening on others and why. "I cannot reproduce it", definitely is not the solution. I test it on 3 Windows 10 x64 and all have the same issue. Different PCs... I have commercial Windows licenses on all of them, is not cracked/hacked. Did you test it on more of one PC?

Best regards, Vali

VolatilePulse commented 3 years ago

I'm sorry, I believe I may not have expressed myself clearly and that is my fault. It's difficult to track down the specific issue if we cannot emulate the issue. I asked if it worked in a fresh Windows 10 installation not because I feel the software should only work under that scenario, but so we can begin to narrow down specifically what causes the issues that you're experiencing.

I was hoping the issue that you were experiencing wouldn't be present on a VM because that would help us rule out a GPU and system files. Since you are encountering that issue in a VM, it is likely to be way above me and it won't be able to be fixed by myself.

Also, your screenshot you sent recently isn't showing the OnFocus issue you initially mentioned, or at least what I understand this issue to be about (the text boxes having focus, or the highlighted bar, when they shouldn't). I can see the outlined shape that you're talking about, the baseTextBox effectively showing through the MaterialTextBox, but I don't know what's causing it.

The reason it is important for developers to reproduce issues is so they can identify and fix the issue instead of just throwing code at an issue, possibly breaking something else. If you do know what the exact issue is and what needs to be fixed, I'm sure Orapps would gladly accept your PR or implement the specific change. But if you aren't sure what's causing it, it is important for us to reproduce the issue to attempt to fix it.

And please don't think that "can't reproduce" is a solution or a cop out. I wouldn't be asking you to test more things if I didn't genuinely want to help fix this issue. I feel that everyone should be able to enjoy MaterialSkin equally, regardless of what software is on their computer or what operating system they're working with, or what .NET version they're using. My material-form-refactor is specifically aiming to remove custom code and passing as much of the heavy lifting for the application onto Windows as possible. This allows for generally more consistent and bug free experiences while also typically being faster.

VolatilePulse commented 3 years ago

I realized that I didn't answer you question about the number of machines that I've tested on and since I'm currently at work, I ran a VM and couldn't reproduce it. I ran Windows Sandbox and couldn't reproduce it. I ran it on my work computer and couldn't reproduce it. But out of an abundance of determination, I was finally able to reproduce one of the issues.

@orapps44 when running the sample application that @valimaties posted earlier in this thread, I was able to get the "bordered" text box to occur after I clicked on the button and closed the window twice. Due to the fact that I'm at work, I'm unable to do any additional testing, however, I believe this may be a relatively easy fix once the code is identified.

I have not been able to experience the other issue of a text box showing it has focus when it really doesn't though. If you can produce a demo application for that, it would be greatly appreciated.

VolatilePulse commented 3 years ago

I've narrowed down the issue to the MaterialSkinManager's UpdateBackgrounds() method. That's what is causing the BaseTextBox to effectively inherit the form's background color. I'm not 100% why it's doing it and I'm not sure what the right approach is, but figured I'd leave my findings thus far.

Edit: This code just hides the underlying issue:

MaterialTextBox2 OnPaint(PaintEventArgs pevent)
//...
            baseTextBox.BackColor = !_enabled ? ColorHelper.RemoveAlpha(SkinManager.BackgroundDisabledColor, BackColor) : //Disabled
                isFocused ? DrawHelper.BlendColor(BackColor, SkinManager.BackgroundFocusColor, SkinManager.BackgroundFocusColor.A) : //Focused
                MouseState == MouseState.HOVER ? DrawHelper.BlendColor(BackColor, SkinManager.BackgroundHoverColor, SkinManager.BackgroundHoverColor.A) : // Hover
                DrawHelper.BlendColor(BackColor, SkinManager.BackgroundAlternativeColor, SkinManager.BackgroundAlternativeColor.A); // Normal
valimaties commented 3 years ago

Yes, @VolatilePulse , exactly ... I said about it right here https://github.com/leocb/MaterialSkin/issues/238#issuecomment-944239239 I was wondering myself why BaseTextBox must have a background color, instead of transparent background color. This control doesn't need a background color.

orapps44 commented 3 years ago

Hi,

I've found the root cause of focused control at startup (it occurs only if readonly property is set). I will create a PR soon for that.

orapps44 commented 3 years ago

See PR #242

valimaties commented 3 years ago

Thanks @orapps44 . I've made a test on my forked master with isFocused = false on constructor, and it was ok. That was before you merged PR. But if you consider removing ReadOnlyChanged is better solution, it's ok.

Now it remains the background color for baseTextBox object.

valimaties commented 3 years ago

Any news about background color problem?!

orapps44 commented 3 years ago

I'm not able to reproduce this backcolor issue. Please share your dummy project and I will have a look.

valimaties commented 3 years ago

I'm not able to reproduce this backcolor issue. Please share your dummy project and I will have a look.

Look up in the comments. It is a Test.zip archive, which contains an entire solution. Look up in the comments, there is a comment of @VolatilePulse who said he encountered this behavior in some conditions.

Regards Vali

orapps44 commented 3 years ago

This issue disapear if textbox and button are placed inside materialTabControl (this explain why it can't be seen on material example project) and if framework is 4.x ...

valimaties commented 3 years ago

This issue disapear if textbox and button are placed inside materialTabControl (this explain why it can't be seen on material example project) and if framework is 4.x ...

If I translate well, ALWAYS I have to add controls in a materialTabControl? What happens with simple forms, without drawer, without TabControl, which want to use of MaterialSkin controls?

Edit: First picture, in first comment, all those controls are in materialTabControl, and it happens. Maybe because it is .Net 5 (?!)

orapps44 commented 3 years ago

If I translate well, ALWAYS I have to add controls in a materialTabControl? What happens with simple forms, without drawer, without TabControl, which want to use of MaterialSkin controls?

There is known visual issues if controls are not inside a container like shadow missing or black color around controls (see #198 #86 #52 #30 #29).

Edit: First picture, in first comment, all those controls are in materialTabControl, and it happens. Maybe because it is .Net 5 (?!)

Yes with .Net 5 even inside materialTabControl issue still here.

orapps44 commented 3 years ago

Hi,

I've finnaly found a fix for background issue. I still not fully understand issue root cause, however following update works for me. Could you try it and le me know ?

See : https://github.com/leocb/MaterialSkin/tree/orapps44-MaterialTextBox2-backcolor-fix

valimaties commented 3 years ago

Hi,

I've finnaly found a fix for background issue. I still not fully understand issue root cause, however following update works for me. Could you try it and le me know ?

See : https://github.com/leocb/MaterialSkin/tree/orapps44-MaterialTextBox2-backcolor-fix

Hi @orapps44 , This seems to work fine to me, too. But with one other small problem: it will create a flickering view on divider (for example, in my case). So I've modified Redraw event and added SuspendLayout and ResumeLayout events, which eliminate flickering to objects, like this:

unflickering