cyotek / Cyotek.Windows.Forms.ColorPicker

Color picker control suite for Windows Forms applications.
http://cyotek.com/blog/tag/colorpicker
MIT License
149 stars 41 forks source link

Refreshing ColorGrid in code - no refresh = crasj #20

Closed stigzler closed 2 years ago

stigzler commented 4 years ago

Hi - thanks for this library - it's really good.

I'm using it to build a custom ColorPicker. One problem I'm having is that I manipulate the custom colors in code (in colorgrid), but can't find a way to refresh it in code once custom colors are added or removed. The only way I can find is by changing the color via the colorwheel or coloreditor (all linked via cloreditor manager). The change of color then (I assume) forces a redraw of the colorgrid.

Another problem is that if I don't refresh manually and change the custom colors, this can cause a crash when you mouseover the colors.

Here's a vid of my loading some custom colors - you'll see it doesn't refresh until I click the colorwheel:

https://youtu.be/-PdJKmOl6-Y?t=134

I tried various permutation of control.invalidate(true); control.refresh + control.update on the colorgird and parent controls, but nothing forces a refresh.

I'd really appreciate a answer as apart from this - your library's perfect!

Thanks Steve

cyotek commented 4 years ago

Hello,

Thanks for the bug report. Do you have a sample project you can attach or send me which reproduces the issue (especially the crash) as I wasn't immediately able to reproduce.

It sounds a little perplexing as to why calling Refresh or Invalidate isn't working, it's almost as though the calls to BeginUpdate don't have an equivalent number of EndUpdate calls. Can you try calling EndUpdate a few times and see if that fixes it? If it does, then you'll need to make sure that if you're calling BeginUpdate to freeze drawing you call EndUpdate the same number of times.

Regards; Richard Moss

stigzler commented 4 years ago

Hey - thanks for the response. It's likely my dodgy coding (hobby coder). I've packaged the project up and you can download it here (too big to attach @ 30M - it's a controls library):

http://niftymonkey.uk/hpserverpublic/temp/stigzler.utility.controls.zip

I messed around with .BeginUpdate/.EndUpdate etc to little avail. What I ended up doing was removing any ColorGrid1 begin/end updates and .invalidates, ensuring that I only had ColorGrid1.Refresh anywhere in the control. Still no joy. Weirdly - refresh works when I remove a custom color row, but not when I add them! Vids:

Remove (working): https://youtu.be/qdV0De-vi7Q Add (not working): https://youtu.be/VIDVYEPy2ac

I also discovered another issue around when I remove a row, when I mouse over the ColorGrid afterwards, it causes an unhandled exception. It was a little intermittent, so not sure what's going on there. I haven't posted as separate issues, because i suspect it may be linked? Video of this: https://youtu.be/ONJHx8YveG8

Thanks for any help you can give + apologies in advance if it's my amateurish coding!

cyotek commented 4 years ago

Hello,

Thanks for the sample project, I'll give that a go. The ColorPicker controls are a bit of a mess and just like some of my other projects I don't recall the state of it - last time I was working on it I was splitting it up, hopefully I'll be able to reproduce the issues from your project. I'm fairly sure I fixed an index out of range crashed which could be what you're experiencing.

I'll update this ticket when I've had a chance to look into it, it might be a couple of days though as (as usual) I have to got fix a bunch of web crawler bugs.

(I assume you closed this issue by accident so I've reopened it!)

Regards; Richard Moss

stigzler commented 4 years ago

Thanks Richard - appreciated + no rush! I've got a million and one other things to do on this project before it even alphas...