Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Change color of commandbuttons
Message
From
08/10/1998 05:19:16
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
08/10/1998 03:50:25
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00144491
Message ID:
00144927
Views:
21
>That I didn't think of API calls. Can you maybe point out which are the commands to use and if possible can you give some code samples.
>The code sample with the GotFocus/SetFocus is interesting but doesn't really apply to the behaviour or effect I was looking for.

Hi Yves,
Although commandbutton has a backcolor property as defined in help it is useless and can only be set at OS level. IMO it's not a good idea to play with default commandbutton. Anyway this has been asked before and I had wrote this class to mimic the behaviour. Idea is to combine an invisible commandbutton, shape, label and image in same container. Commandbutton is included to let the "button" get focus by keyboard. Shape only serves as gotfocus dot-dot border effect + intercepting mouse events and passing to container. Label and image are visual components and could be played anyway ýn desýgn mode (image for button picture with freedom for placement despite default commandbutton picture). Hope helps.
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
Previous
Reply
Map
View

Click here to load this message in the networking platform