Bonsoir
en regardant la chaine d'héritage
On constate, qu'ils dérivent tous les 2 de Control
Comme tes 2 codes sont strictement identiques, on peut supposer que les propriétés et méthodes communes que tu utilises dérivent de Control, on vérifie donc.
https://docs.microsoft.com/fr-fr/dotnet/api/system.windows.forms.control?view=windowsdesktop-6.0
Donc en première approche, on peut tenter ça
public static void RoundBorder(Control frm, int CornerRadius) { Rectangle Bounds = new Rectangle(0, 0, frm.Width, frm.Height); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90); path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90); path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius-1, CornerRadius-1, 0, 90); path.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); path.CloseAllFigures(); frm.Region = new Region(path); frm.Show(); }
Dis-moi si ça marche.
Voir peut être en prenant la première classe commune de leur héritage.
(System.Windows.Forms.Control me semble pas forcément le plus adapté).
Bonjour
A tester en utilisant la classe de base Object vu qu'une Form et un Button héritent tous les deux de la classe Object .
public static void RoundBorder(Object objet, int CornerRadius) { Rectangle Bounds = new Rectangle(0, 0, objet.Width, objet.Height); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90); path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90); path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius-1, CornerRadius-1, 0, 90); path.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); path.CloseAllFigures(); objet.Region = new Region(path); objet.Show(); }
Suite à l'intervention de Whismeril remplacer Object par Control dans la procédure .
Un salut et un merci à lui
Hello,
non object ne contient pas Height, Width, Region et Show().
Il faudrait caster par la suite.
Control est la meilleure option à priori (sauf si recodage particulier dans la chaine d'héritage)
Ça fonctionne parfaitement.
Merci.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionMerci aux forces vives qui font vivre ce site.
De rien