Can I draw on a Form, above all controls?

2019-04-28 05:29发布

问题:

Is it possible for me to draw ABOVE all controls on a form?
I have some controls (textboxes, buttons, COM objects) on my form, and I wish to draw ON them, overriding any pixels previously drawn by them.
I am using Windows Forms on C#.
NOTE: the Graphics class draws under the controls...

回答1:

Take a look at the code in this article:

Draw Over WinForms Controls

The author has created a component that (as he describes it) is like a piece of glass over your form. Your code then draws on this 'glass,' over controls, the form it overlays, etc.

One serious limitation which will affect you is that it does not draw over some controls (including the TextBox). These limitations (and the reasons for them) are described in the article but the code in the article might be what you're looking for (or might serve as a starting point for your own solution).