Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Colors
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Title:
Re: Colors
Miscellaneous
Thread ID:
00520267
Message ID:
00520428
Views:
12
Bob,

It doesn't add the button to the label.. it adds the button to the parent container of the label at runtime.

The cmdLabel.Init() method is:
dodefault()

set classlib to ccontrol.vcx additive

this.mcButtonName = this.Name + sys(2015)
this.parent.AddObject( (this.mcButtonName), "cmdLabelButton", this )

local loObject

loObject = evaluate( "this.parent." + this.mcButtonName )
with loObject
   .Visible = .t.
   .TabIndex = this.TabIndex + 1
endwith
The cmdLabelButton class has these methods:
* cmdLabelButton.Init()
lparameter roLabel

dodefault()

with this
   .Top = roLabel.Top - 2
   .Left = roLabel.Left - 2
   .mcLabelName = roLabel.Name
   .Zorder( 1 )
endwith

* cmdLabelButton.GotFocus()
if ( dodefault() )

   * have to set this because AutoSize labels size isn't set till it's way too late
   local loObject

   loObject = evaluate( "this.parent." + this.mcLabelName )

   with this
      .Width = loObject.Width + 4
      .Height = loObject.Height + 4
   endwith

endif

* cmdLabelButton.Click()
local loObject

loObject = evaluate( "this.parent." + this.mcLabelName )
loObject.Click()
So the button establishes a name based reference the the label it's attached to. I do this instead of an object reference to keep from having destruct sequence dangling oject reference problems. In the GotFocus() the button sizes itself to be slightly larger than the label. You can not do this at Init time because a Label's .Height and .Width are not set until they are painted the first time. The Click() method hands the click event back to the label.Click().

To use it I just drop a cmdLabel object on the form, Set it's Caption and put whatever code I what in it's Click() method.

>Very interesting idea you have listed below. however the OOP idea of adding a command button to a label or adding a label to a commmand button, I cant seem to do with the class designer. I would think that I could do it with add method, or something like that... can you let me know a hint of how you added a label and command button together. It seems simple enough.. but I think my brain hurts <grin>
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Reply
Map
View

Click here to load this message in the networking platform