ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Comment ajouter un toolbar et un menu à un formulaire 'Top - Level'   



L'auteur

Mike Gagnon
Canada Canada
Membre Simple
# 0000000025
enregistré le 14/10/2004

Gagnon Mike
Pointe Cla H9R 3K8
de la société Carver Technologies Inc.
Fiche personnelle


Note des membres
18/20
1 vote


Contributions > 02 - SCX : Formulaires

Comment ajouter un toolbar et un menu à un formulaire 'Top - Level'
# 0000000146
ajouté le 11/02/2005 19:56:36 et modifié le 29/03/2006
consulté 9962 fois
Niveau débutant

Version(s) Foxpro :
VFP 9.0
VFP 8.0
VFP 7.0
VFP 6.0
VFP 5.0

Zoomer sur l'image
Description

Voici comment ajouter un toolbar et un menu à un formulaire top-level pour que le toolbar soit sur le formulaire et non flottant au dessus du formulaire.

Code source :
Public oform1
oform1=Newobject("form1")
oform1.Show
Return
Define Class form1 As Form
  ShowWindow = 2
  DoCreate = .T.
  Caption = "Form1"
  Name = "Form1"
  oToolbar1 = .Null.
  AutoCenter = .T.
  Height = 300
  Add Object commandgroup1 As CommandGroup With ;
    AutoSize = .F., ;
    ButtonCount = 5, ;
    BorderStyle = 0, ;
    Value = 1, ;
    Height = 37, ;
    Left = 12, ;
    Top = 192, ;
    Width = 348, ;
    Name = "Commandgroup1", ;
    Command1.AutoSize = .F., ;
    Command1.Top = 5, ;
    Command1.Left = 5, ;
    Command1.Height = 27, ;
    Command1.Width = 66, ;
    Command1.Caption = "Top", ;
    Command1.Name = "Command1", ;
    Command2.AutoSize = .F., ;
    Command2.Top = 5, ;
    Command2.Left = 73, ;
    Command2.Height = 27, ;
    Command2.Width = 66, ;
    Command2.Caption = "Previous", ;
    Command2.Name = "Command2", ;
    Command3.AutoSize = .F., ;
    Command3.Top = 5, ;
    Command3.Left = 141, ;
    Command3.Height = 27, ;
    Command3.Width = 66, ;
    Command3.Caption = "Next", ;
    Command3.Name = "Command3", ;
    Command4.AutoSize = .F., ;
    Command4.Top = 5, ;
    Command4.Left = 209, ;
    Command4.Height = 27, ;
    Command4.Width = 66, ;
    Command4.Caption = "Last", ;
    Command4.Name = "Command4", ;
    Command5.AutoSize = .F., ;
    Command5.Top = 5, ;
    Command5.Left = 277, ;
    Command5.Height = 27, ;
    Command5.Width = 66, ;
    Command5.Caption = "Exit", ;
    Command5.Name = "Command5"
  Add Object text1 As TextBox With ;
    Height = 25, ;
    Left = 60, ;
    Top = 48, ;
    Width = 85, ;
    Name = "Text1"
  Procedure Activate
    With This
      If Isnull(.oToolbar1)
        .oToolbar1=Createobject([tb1])
        .oToolbar1.Dock(0)
        .oToolbar1.Show()
      Endif
    Endwith
  Endproc

  Procedure oMenu
    Lparameters oFormRef, getMenuName, lUniquePopups, parm4, parm5, parm6, parm7, parm8, parm9
    Local cMenuName, nTotPops, a_menupops, cTypeParm2, cSaveFormName
    If Type("m.oFormRef") # "O" Or ;
        LOWER(m.oFormRef.BaseClass) # 'form' Or ;
        m.oFormRef.ShowWindow # 2
      Messagebox([This menu can only be called from a Top-Level form. Ensure that your form's ShowWindow property is set to 2. Read the header section of the menu's MPR file for more details.])
      Return
    Endif
    m.cTypeParm2 = Type("m.getMenuName")
    m.cMenuName = Sys(2015)
    m.cSaveFormName = m.oFormRef.Name
    If m.cTypeParm2 = "C" Or (m.cTypeParm2 = "L" And m.getMenuName)
      m.oFormRef.Name = m.cMenuName
    Endif
    If m.cTypeParm2 = "C" And !Empty(m.getMenuName)
      m.cMenuName = m.getMenuName
    Endif
    Dimension a_menupops[3]
    If Type("m.lUniquePopups")="L" And m.lUniquePopups
      For nTotPops = 1 To Alen(a_menupops)
        a_menupops[m.nTotPops]Sys(2015)
      Endfor
    Else
      a_menupops[1]="system"
      a_menupops[2]="forms"
      a_menupops[3]="help"
    Endif
    Define Menu (m.cMenuName) In (m.oFormRef.NameBar
    Define Pad _0ty0h5629 Of (m.cMenuName) Prompt "System" Color Scheme 3 ;
      KEY Alt+S, ""
    Define Pad _0ty0h562a Of (m.cMenuName) Prompt "Forms" Color Scheme 3 ;
      KEY Alt+F, ""
    Define Pad _0ty0h562b Of (m.cMenuName) Prompt "Help" Color Scheme 3 ;
      KEY Alt+H, ""
    On Pad _0ty0h5629 Of (m.cMenuName) Activate Popup (a_menupops[1])
    On Pad _0ty0h562a Of (m.cMenuName) Activate Popup (a_menupops[2])
    On Pad _0ty0h562b Of (m.cMenuName) Activate Popup (a_menupops[3])
    Define Popup (a_menupops[1]Margin Relative Shadow Color Scheme 4
    Define Bar 1 Of (a_menupops[1]Prompt "Exit"
    On Selection Bar 1 Of (a_menupops[1]Quit
    Define Popup (a_menupops[2]Margin Relative Shadow Color Scheme 4
    Define Bar 1 Of (a_menupops[2]Prompt "Form #1"
    Define Bar 2 Of (a_menupops[2]Prompt "\-"
    Define Bar 3 Of (a_menupops[2]Prompt "Form #2"
    Define Popup (a_menupops[3]Margin Relative Shadow Color Scheme 4
    Define Bar 1 Of (a_menupops[3]Prompt "About"
    Activate Menu (m.cMenuName) Nowait

    If m.cTypeParm2 = "C"
      m.getMenuName = m.cMenuName
      m.oFormRef.Name = m.cSaveFormName
    Endif
  Endproc
  Procedure Init
    _Screen.Visible = .F.
    This.oMenu(This)
  Endproc
  Procedure commandgroup1.Command5.Click
    Thisform.Release
  Endproc
Enddefine
Define Class tb1 As Toolbar
  Caption = "Toolbar1"
  Height = 28
  Left = 0
  Top = 0
  Width = 55
  ShowWindow = 1
  Name = "tb1"
  Add Object Command2 As CommandButton With ;
    Top = 3, ;
    Left = 5, ;
    Height = 22, ;
    Width = 55, ;
    Caption = "Button1", ;
    Name = "Command2"
  Add Object Command1 As CommandButton With ;
    Top = 3, ;
    Left = 27, ;
    Height = 22, ;
    Width = 55, ;
    Caption = "Button2", ;
    Name = "Command1"
Enddefine



Commentaires
Aucun commentaire enregistré ...

Publicité

Les pubs en cours :


www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2024.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3