Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Changing back color of a command button
Message
De
28/03/2001 01:55:32
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
27/03/2001 18:42:40
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00489076
Message ID:
00489328
Vues:
16
>Hi Gerry,
>your approach of simulating a command button by using a container works well, however I did come across one problem. When I tried it on one of my forms the button would react to mouse down/mouse up events but the (specialeffect) appearance wasn't changing on the form so the button did not appear depressed when the mouse was down.
>When I stepped through the code with the debugger it was possible to see that the specialeffect value was changing but nothing seemed to refresh the button appearance on the form (including the obvious refresh() method).
>Just as I was about to give up a colleague testing it with me put a this.backcolor=rgb() statement in the mousedown and the mouseup to see if at least the colors would change and lo and behold not only the colors changed but the specialeffect setting was activated!
>
>Further testing shows that the RGB() statements have to be in both MouseUp and MouseDown (any color is OK).
>
>Another weird VFP thing.......

Having specialeffect work just needs :
this.visible=this.visible

and if there is a commandbutton (might be invisible) in container it gets focus too. Below code works as a primitive version of container approach (not using OnMouseOut and enhanced version don't need too long code - in enhanced version a transparent container covers other elements and sucessfully mimics coolbuttons like in explorer toolbar) :
Define CLASS mybutton AS container
  Width = 108
  Height = 34
  SpecialEffect = 0
  BackColor = RGB(255,255,0)
  Name = "mybutton"

  Add OBJECT command1 AS commandbutton WITH ;
    Top = 0, ;
    Left = 1, ;
    Height = 27, ;
    Width = 84, ;
    Caption = "Command1", ;
    Style = 1, ;
    Name = "Command1"

  Add OBJECT label1 AS label WITH ;
    WordWrap = .T., ;
    BackStyle = 0, ;
    Caption = "Label1", ;
    Height = 53, ;
    Left = 27, ;
    Top = 3, ;
    Width = 74, ;
    Name = "Label1"

  Add OBJECT image1 AS image WITH ;
    Height = 21, ;
    Left = 4, ;
    Top = 5, ;
    Width = 21, ;
    Name = "Image1"

  Add OBJECT shape1 AS shape WITH ;
    Top = 4, ;
    Left = 5, ;
    Height = 26, ;
    Width = 98, ;
    BackStyle = 0, ;
    BorderStyle = 0, ;
    Name = "Shape1"

  Procedure MouseMove
    Lparameters nButton, nShift, nXCoord, nYCoord
    #Define threshhold 8
    If nButton = 0
      If between(nXCoord, this.left + threshhold, ;
          this.left + this.width - threshhold ) ;
          and between(nYCoord, this.top + threshhold, ;
          this.top + this.height - threshhold)
        This.backcolor = rgb(255,0,0)
      Else
        This.resettodefault("backcolor")
      Endif
    Endif

  Endproc

  Procedure MouseUp
    Lparameters nButton, nShift, nXCoord, nYCoord
    If nButton = 1
      This.visible = .f.
      This.specialeffect = 0
      This.visible = .t.
    Endif
  Endproc

  Procedure MouseDown
    Lparameters nButton, nShift, nXCoord, nYCoord
    If nButton = 1
      This.visible = .f.
      This.specialeffect = 1
      This.visible = .t.
    Endif
  Endproc

  Procedure command1.Click
    This.parent.click
  Endproc

  Procedure command1.Init
    With this
      .top = 1
      .left = 1
      .width = .parent.width - 2
      .height = .parent.height - 2
    Endwith
  Endproc

  Procedure command1.GotFocus
    This.parent.backcolor = rgb(255,0,0)
    This.parent.shape1.borderstyle = 3
  Endproc

  Procedure command1.LostFocus
    This.parent.resettodefault("backcolor")
    This.parent.shape1.borderstyle = 0
  Endproc

  Procedure shape1.Init
    With this
      .top = 4
      .left = 5
      .width = .parent.width - 10
      .height = .parent.height - 8
    Endwith
  Endproc

  Procedure shape1.MouseMove
    Lparameters nButton, nShift, nXCoord, nYCoord
    This.parent.mousemove(nButton, nShift, nXCoord, nYCoord)
  Endproc

  Procedure shape1.MouseUp
    Lparameters nButton, nShift, nXCoord, nYCoord
    This.parent.mouseup(nButton, nShift, nXCoord, nYCoord)
  Endproc

  Procedure shape1.MouseDown
    Lparameters nButton, nShift, nXCoord, nYCoord
    This.parent.mousedown(nButton, nShift, nXCoord, nYCoord)
  Endproc

  Procedure shape1.Click
    This.parent.click
  Endproc
Enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform