I have a complex user control with 384 "wells" = circles each surrounded by a rectangle. Circle and surrounding rectangle colors are updated individually and independently from the control mouse events and also by commands from the parent form. The "Well" shapes are drawn in the Paint event, though I have also played with CreateGraphics() for individual "Well" updates (why else would the method exist?) I've no experience with Regions, but understood that Graphics might take care of some local control section or clip paints (v. fuzzy on that part). I was wondering if I should be using Regions with Clip and Hit Testing for the "Wells" in this kind of control?
Asked
Active
Viewed 254 times
0
-
1[CreateGraphics..why else would the method exist?](https://stackoverflow.com/questions/35544789/drawtobitmap-returning-blank-image/35571419?r=SearchResults&s=2|30.0765#35571419) – TaW Dec 15 '18 at 23:39
-
So you want to test for the circles not the squares? – TaW Dec 15 '18 at 23:40
-
Note that testing the rectangles is dirt cheap. But Regions and clipping can get rather expensive. Although your cicles seem to be tiny and quite symmetrical, so performance may still be ok. GraphicsPaths can also be used, btw.. For a discussion of large regions see [here](https://stackoverflow.com/questions/43139118/region-isvisiblepointf-has-very-slow-performance-for-large-floating-point-valu/43180365?r=SearchResults&s=10|29.6288#43180365) – TaW Dec 15 '18 at 23:45
-
TaW - thanks. Actually, the circle within a square is a a single conceptual region with two parts. The circles color is set by the Form, while the square background is used to indicate selected wells by mouse or arrow key within the control. – beanmf Dec 16 '18 at 01:58
-
1If hit testing the squares is ok a simple calculation will do, no need to use any of the graphics calls.. - If not the best solution depends on how dynamically the graphics change. The fastest test would imo be to have a bitmap and do a single GetPixel on it.. – TaW Dec 16 '18 at 09:23
-
I converted CreateGraphics calls to using the Paint event Graphics. CreateGraphics was used to handle mouse-event rectangle selection coloring (light cyan) and as expected, the entire control gets repainted constantly. whereas with CreateGraphics() there was no flicker, the updates were much faster. Perhaps this is another exception to the rule? I could live with it either way. As for hit testing, I agree, simple calculation seems to work. – beanmf Dec 16 '18 at 16:38
-
1Flicker will go away if the Form or the control you draw on is `DoubleBuffered`. Form has a Property, PictureBox is DB always. Other controls need either a subclass or a call like [this](https://stackoverflow.com/questions/44185298/update-datagridview-very-frequently/44188565#44188565) – TaW Dec 16 '18 at 17:45
-
control inherits from UserControl, so DB was available and worked well. One warning though: (see https://stackoverflow.com/questions/21981896/two-output-file-names-resolved-to-the-same-output-path/53798771#53798771) – beanmf Dec 18 '18 at 10:19