Les Snippets

Connexion

Arrondir les angles d'un formulaire

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 20/11/2008 14:55:47 et initié par PCPT [Liste]
Date de mise à jour : 11/03/2010 15:41:07
Vue : 5376
Catégorie(s) : API, WinForm, Graphique
Langages dispo pour ce code :
- VB6
- VB 2005, VB 2008, VB.NET 1.x
- Delphi 5
- Delphi 5
- VBA



Langage : VB6
Date ajout : 20/11/2008
Posté par PCPT [Liste]
DateMAJ : 08/12/2008
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As LongByVal Y1 As LongByVal X2 As  Long, ByVal Y2 As Long,  ByVal X3 As Long, ByVal Y3 As  Long) As  Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As LongAs Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As LongByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Sub RoundCorners(ByRef oFrm As Form, Optional ByVal Angle As Byte = 15)
    Dim lRet As Long
    With oFrm
'       on travaille en  pixels
        Dim lWidth As Long, lHeight As Long
        lWidth = .ScaleX(.ScaleWidth, .ScaleMode,  vbPixels)
        lHeight = .ScaleY(.ScaleHeight, .ScaleMode,  vbPixels)
'        découpe
        lRet = CreateRoundRectRgn(00, lWidth,  lHeight, Angle, Angle)
        Call SetWindowRgn(.hwnd, lRet, True)
        Call DeleteObject(lRet)
    End With
End Sub

Langage : VB.NET 1.x , VB 2005 , VB 2008
Date ajout : 20/11/2008
Posté par PCPT [Liste]
DateMAJ : 20/11/2008
    <System.Runtime.InteropServices.DllImportAttribute("gdi32.dll", SetLastError:=True)> Private Function CreateRoundRectRgn(ByVal X1 As Int32, ByVal Y1 As Int32, ByVal X2 As Int32, ByVal Y2 As Int32, ByVal X3 As Int32, ByVal Y3 As Int32) As IntPtr
    End Function
    <System.Runtime.InteropServices.DllImportAttribute("gdi32.dll", SetLastError:=True)> Private Function DeleteObject(ByVal hObject As IntPtr) As Int32
    End Function
    <System.Runtime.InteropServices.DllImportAttribute("user32.dll", SetLastError:=True)> Private Function SetWindowRgn(ByVal hwnd As IntPtr, ByVal hRgn As IntPtr, ByVal bRedraw As BooleanAs Int32
    End Function
    Public Sub RoundCorners(ByRef oFrm As System.Windows.Forms.Form, Optional ByVal Angle As System.Byte = 15)
        With oFrm
            Dim lRet As IntPtr = CreateRoundRectRgn(00, .Width, .Height, Angle, Angle)
            SetWindowRgn(.Handle, lRet, True)
            DeleteObject(lRet)
        End With
    End Sub
Langage : Delphi 5
Date ajout : 18/07/2009
Posté par f0xi [Liste]
function CreateRoundRectRgn(
  nLeftRect,
  nTopRect,
  nRightRect,
  nBottomRect,
  nWidthEllipse,
  nHeightEllipse : integer
): HRGN; stdcall; external 'gdi32.dll';

procedure TFormX.FormPaint(Sender: TObject);
var RRR : HRGN;
begin
  RRR := CreateRoundRectRgn(0, 0, Width, Height, 45, 45);
  try
    SetWindowRgn(handle, RRR, true);
  finally
    DeleteObject(RRR);
  end;
end;
Langage : Delphi 5
Date ajout : 18/07/2009
Posté par cirec [Liste]
  
procedure TForm1.FormResize(Sender: TObject); 
var aHrgn: HRGN; 
begin 
  aHrgn := CreateRoundRectRgn(00, width, height, 5050); 
  if aHrgn > 0 then 
    try 
      SetWindowRgn(Handle, aHrgn, true); 
    finally 
      DeleteObject(aHrgn); 
    end; 
end;  
Remarque :
le fait de mettre ce code dans le OnPaint n'apporte rien à part surcharger inutilement le code !! à chaque fois que la fiche doit être dessinée, entièrement où partiellement, ce code est exécuté. Alors que dans le OnResize il est appelé qu'en cas de besoin réel.
Langage : VBA
Date ajout : 11/03/2010
Posté par lermite222 [Liste]
DateMAJ : 11/03/2010

Option Explicit
Private Const cPointToPixel = 1.333333
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Sub RoundCorners(ByRef oFrm As UserForm, lWidth As Long, lHeight As Long, Optional ByVal Angle As Byte = 15)
Dim lRet As Long
Dim LHwnd As Long
    With oFrm
        LHwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X", "D") & "Frame", .Caption)
'       on travaille en  pixels
        lWidth = lWidth * cPointToPixel
        lHeight = lHeight * cPointToPixel
'        découpe
        lRet = CreateRoundRectRgn(0, 0, lWidth, lHeight, Angle, Angle)
        Call SetWindowRgn(LHwnd, lRet, True)
        Call DeleteObject(lRet)
    End With
End Sub



Snippets en rapport avec : Form, Formulaire, Fenêtre, Arr, Angles



Codes sources en rapport avec : Form, Formulaire, Fenêtre, Arr, Angles

{PHP} GÉNÉRATION/GESTION DE FORMULAIRE VIA FICHIER XML
!! LE ZIP EST DANS LE PREMIER COMMENTAIRE !! Gestion automatique simple de formulaire via un fich...

{PHP} GÉNÉRATEUR DE FORMULAIRE [AJAX][PHP5]
Bonjour, Voici un générateur de formulaire html, le principe est assez simple : on se connecte à un...

{Visual Basic, VB6, VB.NET, VB 2005} FORMS D'ASPECTS DIVERS
Vous en avez assez de vos boites de dialogues rectangulaires? Voici un code très simple à utiliser ...

{PHP} [PHP5] - CLASSE DE VÉRIFICATION DE FORMULAIRE
Bonjour à tous ! :) Voila, je devais me faire une classe afin de vérifier les entrées d'un formulai...

{C# / C#.NET} SURCHARGE CLASS FORM POUR PALIER AU PROBLÈME DE LA VALIDATION SYSTÉMATIQUE DES CONTRÔLES LORS DU CLOSE D'UNE FORM
Je voulais pouvoir utiliser la possibilité que mes contrôles déclenchent leur validation à chaque fo...

{Visual Basic, VB6, VB.NET, VB 2005} UPLOADER FICHIER ET DES VARIABLES FORMULAIRES PAR METHODE POST
Apres avoir longtemps galéré avec diverses méthodes pour simuler l'envoi d'un fichier par formulair...

{PHP} [PHP5] CLASSE FORMULAIRE
Une petite classe formulaire, avec gestion de tous les éléments et attributs possible liés à un form...

{ASP / ASP.NET} RÉCUPÉRATION DES CHAMPS D'UN FORMULAIRE LORS D'UN UPLOAD SANS COMPOSANT
Cette source sert a résoudre le pb que j'ai rencontré lors d'un upload sans composant. En effet, l...

{Visual Basic, VB6, VB.NET, VB 2005} FENETRE QUI "CLIGNOTE"
Encore une fois... pas de quoi en faire un plat... j'avais besoin de ca il y a quelques mois et j'ai...

{Visual Basic, VB6, VB.NET, VB 2005} SPLITTIX : SPLITTER DE FENETRE
C'est un activex qui permet de diviser une fenêtre en deux et qui permet à l'utilisateur de changer ...