Les Snippets

Connexion

Personnaliser le curseur (caret) d'une zone de texte

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 16/10/2007 22:55:10 et initié par PCPT [Liste]
Date de mise à jour : 17/10/2007 11:36:42
Vue : 3528
Catégorie(s) : API, Trucs & Astuces, Divers, Graphique
Langages dispo pour ce code :
- VB6, VBA
- VB 2005
- C# 1.x, C# 2.x



Langage : VB6 , VBA
Date ajout : 16/10/2007
Posté par PCPT [Liste]
DateMAJ : 17/10/2007
'nécessite une TextBox et  une PictureBox
'capture visible ici  :  http://img99.imageshack.us/img99/9449/sanstitre2yn6.jpg
'
Option Explicit
Private Declare Function CreateCaret Lib "user32" (ByVal hwnd As LongByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long) As  Long
Private Declare Function ShowCaret Lib "user32" (ByVal hwnd As LongAs Long
'
'
'**********************
'
'
Private Sub Form_Load()
'   créé  l'image
    With Picture1
        .Width = 135
        .Height = 255
        .Picture = .Image
        .Visible = False
    End With
End Sub
Sub Text1_GotFocus()
    Dim As Long, p As Long
    h& = Text1.hwnd
    p& = Picture1.Picture
    CreateCaret h&, p&, 00
    ShowCaret h&
End Sub
'
'
'**********************
'
' VOUS POUVEZ PASSER PAR UN OBJET  STDPICTURE POUR éVITER LA PICTUREBOX :
'
'
Dim As New StdPicture
Private Sub Form_Load()
    Set O = LoadPicture("C:\c.jpg")
End Sub
Sub Text1_GotFocus()
    CreateCaret Text1.hwnd, O.Handle, 00
    ShowCaret Text1.hwnd
End Sub

Remarque :
en mode design, configurer la couleur de la picturebox et de la textbox, ainsi que la typo de la textbox

ce qui est dans le Form_Load est remplaçable par une simple picture en mode design également
Langage : VB 2005
Date ajout : 17/10/2007
Posté par PCPT [Liste]
'   nécessite une textbox 
'   capture visible ici :  http://img138.imageshack.us/img138/6844/tten8.jpg 
Public Class Form1 
Private Declare Sub CreateCaret Lib "user32" (ByVal hwnd As Integer, ByVal hBitmap As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) 
Private Declare Function ShowCaret Lib "user32" (ByVal hwnd As Integer) As Integer 
Dim Img As New Bitmap("D:\c.jpg") 
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus 
Dim h As Integer = TextBox1.Handle 
Dim p As Integer = Img.GetHbitmap.ToInt32 
        CreateCaret(h, p, 0, 0) 
        ShowCaret(h) 
End Sub 
Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed 
        Img.Dispose() 
End Sub 
End Class                                             
Langage : C# 1.x , C# 2.x
Date ajout : 02/11/2007
Posté par Willi [Liste]

//Nécessite une Textbox nommé pour l'exemple TextBox1
public class Form1
{
    [DllImport("user32.dll",SetLastError=True)]
    static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight);
    [DllImport("user32.dll",SetLastError=True)]
    static extern bool ShowCaret(IntPtr hWnd);
    Bitmap _caretBitmap = new Bitmap(@"C:\VotreCaret.jpg");
    Private void TextBox1_GotFocus(object sender,eventArgs e)
    {
       IntPtr hTextBox1 = TextBox1.Handle;
       IntPtr hCaretBitmap = _caretBitmap.GetHBitmap();
       CreateCaret(hTextBox1, hCaretBitmap,0,0);
       ShowCaret(hTextBox1);
    }


Remarque :
Ne pas oublier de faire un _caretBitmap.Dispose() à la fermeture de votre windows form.

Snippets en rapport avec : Image, Textbox, Curseur, Personnaliser, Caret



Codes sources en rapport avec : Image, Textbox, Curseur, Personnaliser, Caret

{Javascript / DHTML} INSERTION À PARTIR DE LA POSITION DU CURSEUR DANS UNE TEXTBOX OU AUTRE.
D'aprés ce que j'ai vu,il marche déja sur IE et Mozilla.Et donc comme son titre l'indique,il permet ...

{C / C++ / C++.NET} GIANTTAUPEKILLER (CHASSE-TAUPES)
Il s'agit du jeu de chasse-taupes adapté sur informatique. Les options de jeu sont modifiables grâc...

{Visual Basic, VB6, VB.NET, VB 2005} LA NOUVELLE VERSION DU NEW FOLDER LOOK EN FRANÇAIS
dans cette version j'ai appliqué des nouvelles fonctions comme m'ont dit plusieurs amis... integrat...

{Javascript / DHTML} UNE IMAGE QUI SUIT LA SOURIS...
Copiez les scripts javascripts dans le répertoire te copier le code HTML dans votre page... C'est fa...

{JAVA / J2EE} REMPLACER LE CURSEUR DE LA SOURIS PAR UNE IMAGE
Code tres simple permettant de modifier a sa guise le curseur de la souris par une image de son choi...

{JAVA / J2EE} TÉLÉCHARGEMENT D'IMAGES (POCHETTES CD, DVD, LIVRES...) SUR INTERNET
Petite fonction permettant de télécharger des images de cds, bd, livres, dvd, films, affiches par r...

{JAVA / J2EE} FAIRE DEFILER UNE IMAGE
...

{Visual Basic, VB6, VB.NET, VB 2005} TEXTBOX SAVOIR A QUELLE LIGNE ON EST RENDU
Savoir a quelle ligne est le curseur SANS API ...

{PHP} CAMEMBERT 2D/3D
Cette classe php permet de générer un camembert en 2D ou en 3D. L'image est au format PNG. Ci-desso...

{Visual Basic, VB6, VB.NET, VB 2005} LOUPE PICTURE BOX
Une loupe agrandissant une image réduite aux dimensions de l’écran Ayant été confronté a afficher d...