Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: KryptonTextBox Validate / Validating / KeyUp events are invoked twice #666

Closed
overlinejota opened this issue Mar 10, 2022 · 13 comments
Labels
bug Something isn't working fixed This issue has been fixed.

Comments

@overlinejota
Copy link

A simple form with a KrytonTextBox and a button.
The next code wave twice when KryptoTextbox1 loses focus:

namespace AppForm{
    public partial class Form1 : Krypton.Toolkit.KryptonForm{
        public Form1() {
            InitializeComponent();
        }            
        private void kryptonTextBox1_Validated(object sender, EventArgs e) {
            MessageBox.Show("Error","Hello");
        }
    }
}

private void InitializeComponent() {
	...
	this.kryptonTextBox1.Validated += new System.EventHandler(this.kryptonTextBox1_Validated);
	...
}

Thanks;

@overlinejota overlinejota added the bug Something isn't working label Mar 10, 2022
@giduac
Copy link
Contributor

giduac commented Mar 15, 2022

KMaskedTextbox is also affected.
Also happens with the "Validating" event.

When set to false non of the events is triggered.
KryptonMaskedTextBox.CausesValidation = false;
KryptonTextBox.CausesValidation = false;

This link could be helpful
https://stackoverflow.com/questions/30759864/winforms-firing-enter-event-twice

@PWagner1
Copy link
Contributor

@Smurf-IV Is this linked to the fixes that were merged yesterday?

@Smurf-IV
Copy link
Member

@Smurf-IV Is this linked to the fixes that were merged yesterday?

Do not think so, Did not look at any impact in this area as I was in the Dock and ribbon projects

@PWagner1
Copy link
Contributor

@Smurf-IV Is this linked to the fixes that were merged yesterday?

Do not think so, Did not look at any impact in this area as I was in the Dock and ribbon projects

Is this just missing the 'Focus()' call in the validate event?

@thiagoraheem
Copy link

I have the same situation and I created a project to demonstrate

https://github.com/thiagoraheem/KryptonTest

@Smurf-IV Smurf-IV self-assigned this Jun 12, 2022
@Smurf-IV Smurf-IV added the under investigation This bug/issue is currently under investigation. label Jun 12, 2022
@Smurf-IV
Copy link
Member

This also affects other controls like KDomainUD

It is because

  • the Kyrpton VisualControlBase is based on the winforms Control
  • When "Adding" an event in the designer, it adds to the direct Validated EventHandler
  • Inside Krypton it also has added an EventHandler to the control it is wrapping.
  • The Krypton EventHandler calls the base controls On#####() version, thus triggering it twice.

This could take a while to fix, e.g. just "some" of the eents in the KDominUD:

        private void OnDomainUpDownTextChanged(object sender, EventArgs e) => OnTextChanged(e);

        private void OnDomainUpDownScroll(object sender, ScrollEventArgs e) => OnScroll(e);

        private void OnDomainUpDownSelectedItemChanged(object sender, EventArgs e) => OnSelectedItemChanged(e);

        private void OnDomainUpDownGotFocus(object sender, EventArgs e)
        {
            UpdateStateAndPalettes();
            PerformNeedPaint(true);
            InvalidateChildren();
            base.OnGotFocus(e);
        }

        private void OnDomainUpDownLostFocus(object sender, EventArgs e)
        {
            UpdateStateAndPalettes();
            PerformNeedPaint(true);
            InvalidateChildren();
            // ReSharper disable RedundantBaseQualifier
            base.OnLostFocus(e);
            // ReSharper restore RedundantBaseQualifier
        }

        private void OnDomainUpDownKeyPress(object sender, KeyPressEventArgs e) => OnKeyPress(e);

        private void OnDomainUpDownKeyUp(object sender, KeyEventArgs e) => OnKeyUp(e);

        private void OnDomainUpDownKeyDown(object sender, KeyEventArgs e) => OnKeyDown(e);

        private void OnDomainUpDownPreviewKeyDown(object sender, PreviewKeyDownEventArgs e) => OnPreviewKeyDown(e);

        private void OnDomainUpDownValidated(object sender, EventArgs e) => OnValidated(e);

        private void OnDomainUpDownValidating(object sender, CancelEventArgs e) => OnValidating(e);

Q: Should the OnDomainUpDownGotFocus be rewritten to not call the base class, because it will end up calling it twice ?
A: Maybe; who knows for each Krypton control !!

@PWagner1
Copy link
Contributor

I was going round in circles for months trying to track down this bug!

@Smurf-IV What happens if you "disable" Krypton's implementation & use the standard WinForms validation calls?

@Smurf-IV
Copy link
Member

@Smurf-IV What happens if you "disable" Krypton's implementation & use the standard WinForms validation calls?

It will work as expected..
It's just all the the other event handlers that will need consideration !
Trouble is when Krypton needs to do something with the event and then calls the base anyway..

@Smurf-IV
Copy link
Member

Update: Darn it.. Keep going round in circles when trying to apply to all Krypton controls.. This bug is entrenched too deeply in some places, and I haven't even moved into Ribbons yet !

@Smurf-IV
Copy link
Member

I'm going to focus on just this control, so that it can be validated by @overlinejota as soon as a fix is published.
Otherwise there would be too many controls updated tat would remain untested fro a long time.
@Wagnerp will need something on the landing page asking for instances of "Double events" to be raised ASAP so that they can be worked on in turn with active users ready to "Test" the result.

image

@PWagner1
Copy link
Contributor

@Smurf-IV Ok, will broadcast a message out on Discord too

@Smurf-IV
Copy link
Member

FYI: Reason for separate controls updates;
image

In the above by just "Removing things that just call through to the base" shows the the click events are no longer working in the KryptonTextBox

@Smurf-IV
Copy link
Member

Done, with a few other events as well:
TBClickValidate

PR coming soon

@Smurf-IV Smurf-IV changed the title [Bug]: KryptonTextBox Validate event is invoked twice [Bug]: KryptonTextBox Validate / Validating / KeyUp events are invoked twice Jun 25, 2022
Smurf-IV added a commit that referenced this issue Jun 25, 2022
- `KeyUp`
- `Validating`
- `Validated`

#666
@Smurf-IV Smurf-IV removed their assignment Jun 25, 2022
@Smurf-IV Smurf-IV added fixed This issue has been fixed. and removed under investigation This bug/issue is currently under investigation. labels Jun 25, 2022
@Smurf-IV Smurf-IV pinned this issue Jun 25, 2022
PWagner1 added a commit that referenced this issue Jun 26, 2022
Smurf-IV added a commit that referenced this issue Jun 26, 2022
@PWagner1 PWagner1 unpinned this issue Jul 23, 2022
@PWagner1 PWagner1 pinned this issue Jul 23, 2022
@PWagner1 PWagner1 unpinned this issue Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed This issue has been fixed.
Projects
None yet
Development

No branches or pull requests

5 participants