PDA

View Full Version : how can I get a button name(id) when press it


zsjasper
05-06-2008, 04:49 AM
Hi, there~

I wrote a button control proc with a viarable name ,like :


proc newButton(string $buttonId)
{
button
-l "$buttonId"
-p mainColumnID
-c "someProc();"
($buttonId + "Btn");
}


because the button id has a viarable, how can I get it when i excute the somePorc()



Hope someone can help !

Thanks!

damat
05-06-2008, 01:04 PM
Why not pass it to the proc as an input parameter?

goleafsgo
05-06-2008, 01:04 PM
A couple of things...
1. I don't think you meant to quote $buttonId in the -label flag in your button call. You would literally get the text "$buttonId" if you do that.

2. I would create the button and get the returned unique name of it. Then just change your callback to accept a string. Then after creating the button you edit the button with the command plus the name of it. This way you really don't have to provide a name to the button at all. Your "newButton" proc can still take a string if you are going to use that as the buttons label but you don't have to also use it as the name.

Like this:


global proc someProc(string $buttonName)
{
print ("You clicked on " + $buttonName + "\n");
}

global proc newButton(string $buttonId)
{
string $buttonName = `button -l $buttonId ($buttonId + "Btn")`;
button -edit -c ("someProc " + $buttonName) $buttonName;
}


{
window;
columnLayout;

newButton "A_";
newButton "B_";
newButton "C_";
newButton "D_";
newButton "E_";

showWindow;
}

zsjasper
05-06-2008, 03:55 PM
hi~ goleafsgo, sorry for the "lable":blush:, I didnt notice about that.
And really thanks for the codes , that does works:)
thank you :wavey:

CGTalk Moderation
05-06-2008, 03:55 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.