Page en cours de chargement

Donnez votre avis..
Que pensez-vous de gambaslinux.fr?
 
Interessant
Il manque des rubriques
excellent site
Résultats
INTERFACE GAMBAS
LOGICIELS GAMBAS 3
TUTORIELS
=Bibliothèque
Creer son logiciel - Les menus contextuels
LES MENUS CONTEXTUELS OU MENU POPUP

menu.png
Aujourd'hui dans cet exemplenous allons voir comment afficher un menu contextuel pour notre application, ce menu qui réagit au clic droit de la souris, appelé communément le menu popup.

créons une application et écrivons le code ci dessous :

' Gambas class file
remarques du programme
'-----------------------------------
 ' Projet    : Menus contextuels français
 ' Date      : 09/09
 ' Auteur    : taoteblues (Dr Henri LOQUET)
 ' Détails   : Création et utilisation d'un menu contextuel dans Textbox, ValueBox, ComboBox et TextArea
'-----------------------------------

déclaration des variables
PUBLIC letext AS TextBox 'variable pour le groupe Textbox
PUBLIC lechiffre AS ValueBox 'variable pour le groupe ValueBox
PUBLIC lecombo AS ComboBox 'variable pour le groupe ComboBox

PRIVATE montext AS Integer
PRIVATE Textcode AS String
PRIVATE Textdecode AS String

PUBLIC SUB Form_Open()
'curseur sur la première textbox
TextBox1.SetFocus

ComboBox1.Add("un", 0)
ComboBox1.Add("deux", 1)
ComboBox1.Add("trois", 2)
ComboBox1.Index = 0
ComboBox2.Add("0", 0)
ComboBox2.Add("1", 1)
ComboBox2.Add("2", 2)
ComboBox2.Add("3", 3)
ComboBox2.Add("4", 4)
ComboBox2.Index = 1
'centrer la feuille
ME.Center
END

PUBLIC SUB Button1_Click()

  ME.Close

END
PUBLIC SUB lechiffre_mousedown()
lechiffre = LAST 
  montext = 2

END

PUBLIC SUB letext_Menu()
  popup.Popup
END

PUBLIC SUB letext_mousedown()
  letext = LAST
  montext = 1
END

PUBLIC SUB lechiffre_Menu()
 popup.Popup  
END


PUBLIC SUB lecombo_Menu()
 popup.Popup  
END

PUBLIC SUB lecombo_mousedown()
  lecombo = LAST 
  montext = 3
END

PUBLIC SUB TextArea1_Menu()
mnutext.Popup
END

PUBLIC SUB mnutextredo_Click() 
  TextArea1.Redo
END

PUBLIC SUB mnutextundo_Click() 
  TextArea1.Undo
END

PUBLIC SUB mnutextcouper_Click() 
 ' TextArea1.Cut
 DIM monchiffre AS String

'autre méthode pour couper afin de gérer les caractères français avec les accents
monchiffre = TextArea1.Selection.Text
'changer les caractères spéciaux en html
    changercode(monchiffre)
monchiffre = Textcode

Clipboard.copy(monchiffre)
TextArea1.Selection.Text = ""
END

PUBLIC SUB mnutextcopier_Click() 
 ' TextArea1.Copy
  DIM monchiffre AS String

'autre méthode pour copier afin de gérer les caractères français avec les accents
monchiffre = TextArea1.Selection.Text
'changer les caractères spéciaux en html
    changercode(monchiffre)
monchiffre = Textcode

Clipboard.copy(monchiffre)

END

PUBLIC SUB mnutextcoller_Click() 
  'TextArea1.Paste
  DIM inserer AS String
inserer = Clipboard.paste()
'remmettre les caractères spéciaux avec accents
retourcode(inserer)

  TextArea1.Insert(Textdecode)
END

PUBLIC SUB mnucopier_Click()
DIM monchiffre AS String

SELECT CASE montext
CASE 1
monchiffre = letext.Selection.Text
    changercode(monchiffre)
monchiffre = Textcode

Clipboard.copy(monchiffre)
CASE 2
monchiffre = lechiffre.Selection.Text
    changercode(monchiffre)
monchiffre = Textcode

Clipboard.copy(monchiffre)
CASE 3
monchiffre = lecombo.Selection.Text
    changercode(monchiffre)
monchiffre = Textcode

Clipboard.copy(monchiffre)

END SELECT
END


PUBLIC SUB mnucoller_Click()
DIM inserer AS String
inserer = Clipboard.paste()
retourcode(inserer)
SELECT CASE montext
CASE 1
  letext.Insert(Textdecode)
CASE 2
 lechiffre.Insert(Textdecode)
CASE 3
 lecombo.Insert(Textdecode)
END SELECT



END

PUBLIC SUB mnucouper_Click()
DIM monchiffre AS String

SELECT CASE montext
CASE 1
monchiffre = letext.Selection.Text
    changercode(monchiffre)
monchiffre = Textcode

Clipboard.copy(monchiffre)
letext.Selection.Text = ""
CASE 2
Clipboard.copy(lechiffre.Selection.Text)
lechiffre.Selection.Text = ""
CASE 3
monchiffre = lecombo.Selection.Text
    changercode(monchiffre)
monchiffre = Textcode

Clipboard.copy(monchiffre)
lecombo.Selection.Text = ""
END SELECT

END
PRIVATE SUB changercode(mettre AS String)

     'Les A
    '-------
    mettre = Replace(mettre, "À", "À")
    mettre = Replace(mettre, "Á", "Á")
    mettre = Replace(mettre, "Â", "Â")
    mettre = Replace(mettre, "Ã", "Ã")
    mettre = Replace(mettre, "Ä", "Ä")
    mettre = Replace(mettre, "Å", "Å")
    mettre = Replace(mettre, "Æ", "Æ")
    mettre = Replace(mettre, "à", "à")
    mettre = Replace(mettre, "á", "á")
    mettre = Replace(mettre, "â", "â")
    mettre = Replace(mettre, "ã", "ã")
    mettre = Replace(mettre, "æ", "æ")

    'Les C
    '-------
    mettre = Replace(mettre, "¢", "¢")
    mettre = Replace(mettre, "Ç", "Ç")
    mettre = Replace(mettre, "ç", "ç")

    'Les E
    '-------
    mettre = Replace(mettre, "È", "È")
    mettre = Replace(mettre, "É", "É")
    mettre = Replace(mettre, "Ê", "Ê")
    mettre = Replace(mettre, "Ë", "Ë")
    mettre = Replace(mettre, "è", "è")
    mettre = Replace(mettre, "é", "é")
    mettre = Replace(mettre, "ê", "ê")
    mettre = Replace(mettre, "ë", "ë")

    'Les I
    '------
    mettre = Replace(mettre, "Ì", "Ì")
    mettre = Replace(mettre, "Í", "Í")
    mettre = Replace(mettre, "Î", "Î")
    mettre = Replace(mettre, "Ï", "Ï")
    mettre = Replace(mettre, "ì", "ì")
    mettre = Replace(mettre, "í", "í")
    mettre = Replace(mettre, "î", "î")
    mettre = Replace(mettre, "ï", "ï")

    'Les O
    '------
    mettre = Replace(mettre, "Ò", "Ò")
    mettre = Replace(mettre, "Ó", "Ó")
    mettre = Replace(mettre, "Ô", "Ô")
    mettre = Replace(mettre, "Õ", "Õ")
    mettre = Replace(mettre, "Ö", "Ö")
    mettre = Replace(mettre, "Ø", "Ø")
    mettre = Replace(mettre, "ò", "ò")
    mettre = Replace(mettre, "ó", "ó")
    mettre = Replace(mettre, "ô", "ô")
    mettre = Replace(mettre, "õ", "õ")
    mettre = Replace(mettre, "ö", "ö")
    mettre = Replace(mettre, "ø", "ø")

    'Les U
    '-------
    mettre = Replace(mettre, "Ù", "Ù")
    mettre = Replace(mettre, "Ú", "Ú")
    mettre = Replace(mettre, "Û", "Û")
    mettre = Replace(mettre, "Ü", "Ü")
    mettre = Replace(mettre, "ù", "ù")
    mettre = Replace(mettre, "ú", "ú")
    mettre = Replace(mettre, "û", "û")
    mettre = Replace(mettre, "ü", "ü")


    'Les fractions
    '----------------
    mettre = Replace(mettre, "¼", "¼")
    mettre = Replace(mettre, "½", "½")
    mettre = Replace(mettre, "¾", "¾")

    'TM, COPYRIGHT, REG
    '--------------------------
    mettre = Replace(mettre, "™", "™")
    mettre = Replace(mettre, "©", "©")
    mettre = Replace(mettre, "®", "®")

    'Divers
    '--------
    mettre = Replace(mettre, "ƒ", "&nfnof;")
    mettre = Replace(mettre, "… ", "…")
    mettre = Replace(mettre, "† ", "†")
    mettre = Replace(mettre, "‡", "‡")
    mettre = Replace(mettre, "ˆ", "ˆ")
    mettre = Replace(mettre, "‰", "‰")
    mettre = Replace(mettre, "Š", "Š")
    mettre = Replace(mettre, "š", "š")
    mettre = Replace(mettre, "Œ", "Œ")
    mettre = Replace(mettre, "œ", "œ")
    mettre = Replace(mettre, "•", "•")
    mettre = Replace(mettre, "–", "–")
    mettre = Replace(mettre, "˜", "˜")
    mettre = Replace(mettre, "¡", "¡")
    mettre = Replace(mettre, "£", "£")
    mettre = Replace(mettre, "¤", "¤")
    mettre = Replace(mettre, "¥", "¥")
    mettre = Replace(mettre, "¦", "¦")
    mettre = Replace(mettre, "§", "§")
    mettre = Replace(mettre, "¨", "¨")
    mettre = Replace(mettre, "ª", "ª")
    mettre = Replace(mettre, "¬", "¬")
    mettre = Replace(mettre, "¯", "¯")
    mettre = Replace(mettre, "°", "°")
    mettre = Replace(mettre, "±", "±")
    mettre = Replace(mettre, "¹", "¹")
    mettre = Replace(mettre, "²", "²")
    mettre = Replace(mettre, "³", "³")
    mettre = Replace(mettre, "´", "´")
    mettre = Replace(mettre, "µ", "µ")
    mettre = Replace(mettre, "·", "·")
    mettre = Replace(mettre, "¸", "¸")
    mettre = Replace(mettre, "º", "º")
    mettre = Replace(mettre, "»", "»")
    mettre = Replace(mettre, "¿", "¿")

  Textcode = mettre
END

PRIVATE SUB retourcode(remettre AS String)

    'Les A
    '-------
    remettre = Replace(remettre, "À", "À")
    remettre = Replace(remettre, "Á", "Á")
    remettre = Replace(remettre, "Â", "Â")
    remettre = Replace(remettre, "Ã", "Ã")
    remettre = Replace(remettre, "Ä", "Ä")
    remettre = Replace(remettre, "Å", "Å")
    remettre = Replace(remettre, "Æ", "Æ")
    remettre = Replace(remettre, "à", "à")
    remettre = Replace(remettre, "á", "á")
    remettre = Replace(remettre, "â", "â")
    remettre = Replace(remettre, "ã", "ã")
    remettre = Replace(remettre, "æ", "æ")

    'Les C
    '-------
    remettre = Replace(remettre, "¢", "¢")
    remettre = Replace(remettre, "Ç", "Ç")
    remettre = Replace(remettre, "ç", "ç")

    'Les E
    '-------
    remettre = Replace(remettre, "È", "È")
    remettre = Replace(remettre, "É", "É")
    remettre = Replace(remettre, "Ê", "Ê")
    remettre = Replace(remettre, "Ë", "Ë")
    remettre = Replace(remettre, "è", "è")
    remettre = Replace(remettre, "é", "é") 
    remettre = Replace(remettre, "ê", "ê")
    remettre = Replace(remettre, "ë", "ë")

    'Les I
    '------
    remettre = Replace(remettre, "Ì", "Ì")
    remettre = Replace(remettre, "Í", "Í")
    remettre = Replace(remettre, "Î", "Î")
    remettre = Replace(remettre, "Ï", "Ï")
    remettre = Replace(remettre, "ì", "ì")
    remettre = Replace(remettre, "í", "í")
    remettre = Replace(remettre, "î", "î")
    remettre = Replace(remettre, "ï", "ï")

    'Les O
    '------
    remettre = Replace(remettre, "Ò", "Ò")
    remettre = Replace(remettre, "Ó", "Ó")
    remettre = Replace(remettre, "Ô", "Ô")
    remettre = Replace(remettre, "Õ", "Õ")
    remettre = Replace(remettre, "Ö", "Ö")
    remettre = Replace(remettre, "Ø", "Ø")
    remettre = Replace(remettre, "ò", "ò")
    remettre = Replace(remettre, "ó", "ó")
    remettre = Replace(remettre, "ô", "ô")
    remettre = Replace(remettre, "õ", "õ")
    remettre = Replace(remettre, "ö", "ö")
    remettre = Replace(remettre, "ø", "ø")

    'Les U
    '-------
    remettre = Replace(remettre, "Ù", "Ù")
    remettre = Replace(remettre, "Ú", "Ú")
    remettre = Replace(remettre, "Û", "Û")
    remettre = Replace(remettre, "Ü", "Ü")
    remettre = Replace(remettre, "ù", "ù")
    remettre = Replace(remettre, "ú", "ú")
    remettre = Replace(remettre, "û", "û")
    remettre = Replace(remettre, "ü", "ü")


    'Les fractions
    '----------------
    remettre = Replace(remettre, "¼", "¼")
    remettre = Replace(remettre, "½", "½")
    remettre = Replace(remettre, "¾", "¾")

    'TM, COPYRIGHT, REG
    '--------------------------
    remettre = Replace(remettre, "™", "™")
    remettre = Replace(remettre, "©", "©")
    remettre = Replace(remettre, "®", "®")

    'Divers
    '--------
    remettre = Replace(remettre, "&nfnof;", "ƒ")
    remettre = Replace(remettre, "…", "…")
    remettre = Replace(remettre, "†", "†")
    remettre = Replace(remettre, "‡", "‡")
    remettre = Replace(remettre, "ˆ", "ˆ")
    remettre = Replace(remettre, "‰", "‰")
    remettre = Replace(remettre, "Š", "Š")
    remettre = Replace(remettre, "š", "š")
    remettre = Replace(remettre, "Œ", "Œ")
    remettre = Replace(remettre, "œ", "œ")
    remettre = Replace(remettre, "•", "•")
    remettre = Replace(remettre, "–", "–")
    remettre = Replace(remettre, "˜", "˜")
    remettre = Replace(remettre, "¡", "¡")
    remettre = Replace(remettre, "£", "£")
    remettre = Replace(remettre, "¤", "¤")
    remettre = Replace(remettre, "¥", "¥")
    remettre = Replace(remettre, "¦", "¦")
    remettre = Replace(remettre, "§", "§")
    remettre = Replace(remettre, "¨", "¨")
    remettre = Replace(remettre, "ª", "ª")
    remettre = Replace(remettre, "¬", "¬")
    remettre = Replace(remettre, "¯", "¯")
    remettre = Replace(remettre, "°", "°")
    remettre = Replace(remettre, "±", "±")
    remettre = Replace(remettre, "¹", "¹")
    remettre = Replace(remettre, "²", "²")
    remettre = Replace(remettre, "³", "³")
    remettre = Replace(remettre, "´", "´")
    remettre = Replace(remettre, "µ", "µ")
    remettre = Replace(remettre, "·", "·")
    remettre = Replace(remettre, "¸", "¸")
    remettre = Replace(remettre, "º", "º")
    remettre = Replace(remettre, "»", "»")
    remettre = Replace(remettre, "¿", "¿")

  Textdecode = remettre
END

PUBLIC SUB TextBox3_Menu()
 'ne pas avoir de menu
  STOP EVENT
 END

PUBLIC SUB mnutext_Show()
'voir ou ne pas voir copier, coller, couper en fonction du presse papier
IF TextArea1.Selection.Text <> "" THEN
mnutextcopier.enabled = TRUE
mnutextcouper.enabled = TRUE
ELSE
mnutextcopier.enabled = FALSE
mnutextcouper.enabled = FALSE
ENDIF

IF Clipboard.Paste() <> "" THEN
mnutextcoller.enabled = TRUE
ELSE
mnutextcoller.enabled = FALSE
ENDIF

END

PUBLIC SUB popup_Show()
DIM monchiffre AS String

monchiffre = Clipboard.Paste()

'voir ou ne pas voir copier, coller, couper en fonction du presse papier

SELECT CASE montext
CASE 1
IF letext.Selection.Text <> "" THEN
mnucopier.Enabled = TRUE
mnucouper.Enabled = TRUE
ELSE
mnucopier.Enabled = FALSE
mnucouper.Enabled = FALSE
ENDIF
IF monchiffre <> "" THEN
mnucoller.Enabled = TRUE
ELSE
mnucoller.Enabled = FALSE
ENDIF
CASE 2
IF lechiffre.Selection.Text <> "" THEN
mnucopier.Enabled = TRUE
mnucouper.Enabled = TRUE
ELSE
mnucopier.Enabled = FALSE
mnucouper.Enabled = FALSE
ENDIF
IF monchiffre
mnucoller.Enabled = TRUE
ELSE
mnucoller.Enabled = FALSE
ENDIF
CASE 3
IF lecombo.Selection.Text <> "" THEN
mnucopier.Enabled = TRUE
mnucouper.Enabled = TRUE
ELSE
mnucopier.Enabled = FALSE
mnucouper.Enabled = FALSE
ENDIF
IF monchiffre <> "" THEN
mnucoller.Enabled = TRUE
ELSE
mnucoller.Enabled = FALSE
ENDIF
END SELECT  
END
voilà pour aujourd'hui.




Date de création : 02/10/2009 @ 22:16
Dernière modification : 03/10/2009 @ 10:43
Catégorie : Creer son logiciel
Page lue 5583 fois


Imprimer l'article Imprimer l'article


react.gifRéactions à cet article

Personne n'a encore laissé de commentaire.
Soyez donc le premier !


ACCES RAPIDE
RECHERCHE




LES INSTRUCTIONS
Divers
INSTRUCTIONS
Où ça, qui ça?
VISITES

   visiteurs

   visiteurs en ligne

ARCHIVES GAMBAS 1/2
^ Haut ^