IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

la forme du focus


Sujet :

Windows Forms

  1. #1
    Membre à l'essai
    Inscrit en
    Février 2011
    Messages
    106
    Détails du profil
    Informations forums :
    Inscription : Février 2011
    Messages : 106
    Points : 14
    Points
    14
    Par défaut la forme du focus
    Bonjour , mon problème est tres simple pourtant je n ai pas trouver la solution.
    Bon une zone de text , textBox quant il recoit le focus il signal ceci ( | ) moi je veux qu'il signale ceci ( _ ).
    comme en msDos.
    merci de m aider.

  2. #2
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2015
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mars 2015
    Messages : 9
    Points : 16
    Points
    16
    Par défaut
    Bonjour
    Vous pouvez utiliser l'événement OnPaint, tout simplement:
    1) Dessinez un rectangle qui couvre le caret (rectangle blanc si la couleur de textbox fond est blanc aussi)
    2) Dessiner une chaîne qui va du visible à l'invisible par le temps.
    Ça marche pour moi
    (Je suggère de jeter un oeil au code SharpDevelop, chemin: src \ Libraries \ ICSharpCode.TextEditor \ Project \ Src \ Gui \ Caret.cs)

  3. #3
    Membre à l'essai
    Inscrit en
    Février 2011
    Messages
    106
    Détails du profil
    Informations forums :
    Inscription : Février 2011
    Messages : 106
    Points : 14
    Points
    14
    Par défaut
    Citation Envoyé par Alaa Ben Fatma Voir le message
    Bonjour
    Vous pouvez utiliser l'événement OnPaint, tout simplement:
    1) Dessinez un rectangle qui couvre le caret (rectangle blanc si la couleur de textbox fond est blanc aussi)
    2) Dessiner une chaîne qui va du visible à l'invisible par le temps.
    Ça marche pour moi
    (Je suggère de jeter un oeil au code SharpDevelop, chemin: src \ Libraries \ ICSharpCode.TextEditor \ Project \ Src \ Gui \ Caret.cs)

    merci , c n est pas une solution pratique

  4. #4
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour
    La seule methode viable pour le faire est un appel à l'API Windows ,car le caret est une resource shared qui impacte le systeme lui-meme...
    Lorsque le control TextBox perd le focus ,le caret doit etre restore à ses dimensions par defaut...!!!

    simplistic code .cs exemple:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
     
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
     
    namespace WinCustomCaret
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
                this.textBox1.GotFocus += new EventHandler(textBox1_GotFocus);
            }
     
     
     
            private void Form2_Load(object sender, EventArgs e)
            {
                this.textBox1.Text = "If you want the csuror to never be shown in a textbox control, then simply put the HideCaret code in the Textbox_GotFocus() event. Like below…";
                this.textBox2.Text = "If you want the csuror to never be shown in a textbox control, then simply put the HideCaret code in the Textbox_GotFocus() event. Like below…";
                this.comboBox1.Items.Add("If you want the csuror to never be shown in a textbox control, then simply put the HideCaret code in the Textbox_GotFocus() event. Like below…");
            }
            private void textBox1_GotFocus(object sender, EventArgs e)
            {
                 // show a block cursor
                ShowCustomCaret(6, 14);
            }
            private void  ShowCustomCaret(Int32  width ,Int32 height)
            {
                try 
    	        {
     
     
                   CreateCaret(this.ActiveControl.Handle.ToInt32(),0  , width, height);
                   ShowCaret(this.ActiveControl.Handle.ToInt32());
     
     
    	        }
    	        catch (Exception)
    	        {
     
    		        throw;
    	        }
     
     
            }
     
            [DllImport("user32")]
            private static extern Int32 CreateCaret(Int32 hWnd, Int32 hBitmap, Int32 nWidth, Int32 nHeight);
     
            [DllImport("user32")]
            private static extern Int32 ShowCaret(Int32 hWnd);
     
            [DllImport("user32")]
            private static extern Int32 HideCaret(Int32 hWnd);
     
        }
    }
    bon code....

  5. #5
    Membre à l'essai
    Inscrit en
    Février 2011
    Messages
    106
    Détails du profil
    Informations forums :
    Inscription : Février 2011
    Messages : 106
    Points : 14
    Points
    14
    Par défaut
    Citation Envoyé par MABROUKI Voir le message
    bonjour
    La seule methode viable pour le faire est un appel à l'API Windows ,car le caret est une resource shared qui impacte le systeme lui-meme...
    Lorsque le control TextBox perd le focus ,le caret doit etre restore à ses dimensions par defaut...!!!

    simplistic code .cs exemple:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
     
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
     
    namespace WinCustomCaret
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
                this.textBox1.GotFocus += new EventHandler(textBox1_GotFocus);
            }
     
     
     
            private void Form2_Load(object sender, EventArgs e)
            {
                this.textBox1.Text = "If you want the csuror to never be shown in a textbox control, then simply put the HideCaret code in the Textbox_GotFocus() event. Like below…";
                this.textBox2.Text = "If you want the csuror to never be shown in a textbox control, then simply put the HideCaret code in the Textbox_GotFocus() event. Like below…";
                this.comboBox1.Items.Add("If you want the csuror to never be shown in a textbox control, then simply put the HideCaret code in the Textbox_GotFocus() event. Like below…");
            }
            private void textBox1_GotFocus(object sender, EventArgs e)
            {
                 // show a block cursor
                ShowCustomCaret(6, 14);
            }
            private void  ShowCustomCaret(Int32  width ,Int32 height)
            {
                try 
    	        {
     
     
                   CreateCaret(this.ActiveControl.Handle.ToInt32(),0  , width, height);
                   ShowCaret(this.ActiveControl.Handle.ToInt32());
     
     
    	        }
    	        catch (Exception)
    	        {
     
    		        throw;
    	        }
     
     
            }
     
            [DllImport("user32")]
            private static extern Int32 CreateCaret(Int32 hWnd, Int32 hBitmap, Int32 nWidth, Int32 nHeight);
     
            [DllImport("user32")]
            private static extern Int32 ShowCaret(Int32 hWnd);
     
            [DllImport("user32")]
            private static extern Int32 HideCaret(Int32 hWnd);
     
        }
    }
    bon code....
    merci pour l aide, je vais le faire et je vous tiens au courant

  6. #6
    Membre à l'essai
    Inscrit en
    Février 2011
    Messages
    106
    Détails du profil
    Informations forums :
    Inscription : Février 2011
    Messages : 106
    Points : 14
    Points
    14
    Par défaut got_focus
    Je ne c est pas pourquoi je ne dispose pas de l événement got_focus???!!!

  7. #7
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    rebonjour
    il y a beaucoup d'events qui ne sont pas listes dans le designer mais se trouve dans le fenetre de code !!!
    Il est donc derriere les coulisses ou "underhood" (l'arbre qui cache la foret ) !!!

Discussions similaires

  1. [Téléphoner]Focus sur le tel + ouverture Form
    Par samlepiratepaddy dans le forum IHM
    Réponses: 2
    Dernier message: 05/11/2005, 22h06
  2. [VB.net] Donner le focus a un Form
    Par Manix dans le forum Windows Forms
    Réponses: 23
    Dernier message: 01/08/2005, 02h59
  3. [VB.NET] Perte de focus entre deux form
    Par toniolol dans le forum Windows Forms
    Réponses: 2
    Dernier message: 05/07/2005, 08h00
  4. Aide sur le focus d'un champ d'une forme
    Par yannickn dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 10/03/2005, 12h48
  5. Comment basculer le focus depuis une autre form ?
    Par altahir007 dans le forum Composants VCL
    Réponses: 9
    Dernier message: 03/09/2003, 15h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo