views:

67

answers:

5

I have a C# visual studio 2005 form ...

On the form I need to programatically allow buttons to be available to be available.

e.g. a.) available for usage if a file is open b.) unavailable for usage if a file is not open.

Ideally I want to do something like word does -- like word, where the buttons are greyed out if you they can not be used.

-->edit In a windows C# GUI (not web based).

A: 

I'd have thought you'd use the "enabled" attribute on the button. You can use JavaScript or jQuery to set the attribute based on some condition on the form such as a hidden field having a certain value or something else on your form.

griegs
+4  A: 

If this is for Windows Forms, set the Enabled property of the button to true or false.

adrift
A: 

You can bind button enabled property to object wich has public bool typed property

Andrew Dementiev
+1  A: 

You can do something like this (I figured you needed some code):

if(//the document is open)
{
  btnYourButton.Enabled = true; //to make it available
  btnYourButton.Visible = true; //to show the button
}
else
{
  btnYourButton.Enabled = false; //to make it unavailable
  btnYourButton.Visible = false; //to hide the button
}

Enabled determines the usability of the button. Visible hides or shows the button.

Secko
great thanks... where should I put this control flow code?
It makes sense that i can change the property seetings for the buttons... so, I just do this in the dialog box code section when the user opens the file.
@user407601 The code goes in .cs file where you need to check for your document. I would recommend that you create a function in your class, and store the code there.
Secko
A: 

I suggest you use this, http://www.codeproject.com/KB/miscctrl/CradsActions.aspx

For WPF, you can use commands.

Lex Li