I am using ButtonRenderer.DrawButton for a column with buttons with images in a DataGridView, and I am interested in when each PushButtonState value should be used.
Here is the official documentation. It says:
Default - The button has the default appearance.
Disabled - The button is disabled.
Hot - The button is hot.
Normal - The button has the normal appearance.
Pressed - The button is pressed.
The ones I do not understand well are Default and Normal. What is the difference between these two roles? In the screenshot below these 2 roles are combined with the focused bool parameter passed to the ButtonRenderer.DrawButton method.
About the default state
According to user experience guidelines for Windows-based desktop applications for button control:
The default command button is invoked when users press the Enter key.
It is assigned by the developer, but any command button becomes the
default when users tab to it.
In windows forms, to set a button as the default button of a form, you can set it as AcceptButton of the form. For more information see How to: Designate a Windows Forms Button as the Accept Button Using the Designer
About other states
If you take a look at ButtonStandardAdapter Which is responsible to draw a standard button, you will see:
private PushButtonState DetermineState(bool up) {
PushButtonState state = PushButtonState.Normal;
if (!up) {
state = PushButtonState.Pressed;
}
else if (Control.MouseIsOver) {
state = PushButtonState.Hot;
}
else if (!Control.Enabled) {
state = PushButtonState.Disabled;
}
else if (Control.Focused || Control.IsDefault) {
state = PushButtonState.Default;
}
return state;
}
And IsDefault returns true for a button which is set a AcceptButton of a Form.
I have a custom addin for Word (could also be for Excel).
The addin has a ribbon with multiple groups and multiple controls (buttons) within them.
This is an ongoing project and some of the ribbon buttons are for users, and some are for testing/development purposes.
When I send the product to the client I only show certain buttons. I want the testing buttons to be completely invisible/inaccessible. I Have tried setting the testing buttons/groups to visible = false.
This works, in the sense that the buttons do not appear on the ribbon, but if the user goes to Word's quick access toolbar > "More Commands" > "Choose Commands From" dropdown and selects my custom addin...
Then the user can see all of my buttons. Even the ones with no label.
I have tried looping the controls in the ribbon load method and setting the testing controls to enabled = false, locked = true, generatemember = false, but none of these hide the buttons from the QAT menu. I also tried control.Dispose() - no joy.
Is there anyway to set the properties of a ribbon button such that it is completely invisible and inaccessible to the user in the QAT??
Many thanks
Set the ApplicationMode.
Button CommandName='cmdExportMetadata' ApplicationModes='1'
Please see the below link too :
https://msdn.microsoft.com/en-us/library/windows/desktop/dd940486(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ee264330(v=vs.85).aspx
I would suggest you to create debug buttons dynamically. Define a constant variable like public constant string environment = "DEBUG"; and check it on start up
I'm use the following function to prompt the user to rate my app:
Launcher.LauLauncher.LaunchUriAsync(
new Uri("ms-windows-store:reviewapp?appid=" + APP_ID))
I want to check if user click on the "Cancel" button in page rating.
How can I check if the user clicks on the "Cancel" button?
Basically you're asking whether it's possible to determine whether the user actually left a rating/review when you invoke the Store URI. Unfortunately, this isn't possible at present, but it is a frequently requested capability.
I have a button in that control. How do i reach it programmatically.. I cant reach it by pressing the buttons ID in the code partial class code file.
if (HttpContext.Current.User.IsInRole("Administrator") || HttpContext.Current.User.IsInRole("Moderator"))
{
Button button = (Button)LoginView1.FindControl("DeleteThread");
from here
For the LoginView control, when being
added onto a page, at a certain time,
only one Template (anonymous or
loggedIn ) is applied on the Control
instance, so at that time, we can only
retrieve the reference of those
controls in the active template( can't
access those in the non-active
template). So you can first determine
whether the user has been
authenticated or not and then use the
LoginView.FindControl( stringId)
together with the sub control's ID to
retrieve the control reference.
I need to create a user control in C#.Net, which can be added to the application without being visible - just like the FolderBrowserDialog. It's a new window which I'll be using often so I think this is the right way. The window will be opened by envoking the showDialog-Method as known from the other dialog.
Any Idea?
Thanks and regards,
Daniel
Since all these "invisible" controls derive from Component class, you should start by reading the MSDN article on it: http://msdn.microsoft.com/en-us/library/system.componentmodel.component.aspx.
simply set Visible to false or isn't this what you're asking for ?
A UserControl is by definition not a Form; I think what you really want is a Component. That said, couldn't you really just create a new Form class that has the functionality you want? Whenever you want to display it, create a new instance and call ShowDialog. Or, if you want to preserve state, add an instance as a class member to your parent form, call its Show method whenever you want to display it, and add an event handler to its FormClosing event to check:
if (e.CloseReason == CloseReason.UserClosing)
and, if so,
e.Cancel = true;
Hide();
(This last part is to prevent errors if the user closes the form and then tries to display again after it's been disposed.)
I think more information may be needed, but if your crating a custom user control, the control should have a .Visible property. The follow is an example of how a button can be located on the form but hidden from a user.
button.Visible = true; // shows the button
button.Show(); // Shows the button
button.Visible = false; // hides the button
button.Hide(); // Hides the button
While the button may still be on the form/control, it will not be interactible by the user. You can still perform programmatic control on the button, but essentially it is not a user control while it is 'hidden'. If you want there to be a sort of hidden button that the user can click you will need to do other things to obtain this but It doesn't should like that is what you want.
This show/hide thought process sounds a lot like pains and confusion leftover from classic VB. The old form methods of show and hide, etc., were confusing and often left me as a developer in a position to not know whether an object existed or if was merely invisible. And checking was only trivial if you used On Error Goto to prevent a null reference. So right off I would advise not to think in terms of visibility unless you are doing something with a web page and need to maintain space and state.
First, create a Windows form and add it to your project, assuming that is the type of project that you are describing. Decorate the form with the proper controls, and where applicable, create properties to allow public access to the control values. Also set the DialogResult property of the buttons that either "OK" or "Cancel" the form. Give it an appropriate border style of either Fixed3D or FixedDialog. Maybe also set the property for where you want the form to appear on startup -- center parent, center screen, Windows default, etc. The event handlers for both "OK" and "Cancel" should invoke this.Close(); to close the window.
From the calling point in the code, here's some hypothetical code to get you going in the right direction. Write something like this in the place where you want to invoke your Dialog.
int intResult = 0;
string strResult = null;
MyDialogForm frm = new MyDialogForm();
frm.Title = "Select an Item";
frm.SomeProperty = 0;
frm.SomeOtherProperty = true;
if (frm.ShowDialog() == DialogResult.OK)
{
intResult = frm.Result;
strResult = frm.StringResult;
}
else if (frm.ShowDialog() == DialogResult.Cancel)
{
// User clicked the cancel button. Nothing to do except maybe display a message.
MessageBox.Show("Canceled Task");
}
...
// Somewhere further on down, but within scope, simply repeat
// what you just did, but without having to reinstantiate the
// form Window. But if you make it that far within the same
// scope, this method might be too busy and may need to be
// factored down.
So in short:
Scrap show/hide -- its not a good
practice.
Save the form data without
using an invisible form to save it;
that's the class's job.
If the UI requires a lot of flipping back and
forth between windows, check your
design for other alternatives for
solving the original problem. Maybe a design pattern such as MVC is for you, depending upon the size and complexity of your application.
Sound good?
You can put that control in a Panel. Set the panel height = 0 visible = false when you dont want to show the control.
And do the vice versa when you want to show it.
Derive from Control, not UserControl, and in the constructor set Visible = false.
Also create an event handler in the constructor.
VisibleChanged += new EventHandler(SetVisibleFalse);
Create a method named SetVisibleFalse.
private void SetVisibleFalse(object sender, EventArgs e)
{
if (Visible) Visible = false;
}