Highlight certain controls when hovering above a button - c#

I have the following case:
There are several list boxes where the user can select something, some text boxes to enter text and several buttons to execute commands.
If a button is not enabled (due to a wrong/missing selection in a list box and/or a wrong entry in a text field), I'd like to show the red error adorner around the elements that needs to be fixed.
I know how I can show the red border when a entry is not correct using Validation rules - but they are not applicable since the fact "is correct" depends on the command the user wants to execute. E.g. to add an element, there is no need for a selected element in a listbox, but if you want to delete one, there needs to be a selected one.

You should use an attached behavior on the button itself. Then, hook the MouseEnter and MouseLeave events for the button.
Then all you have to do (when the mouse enters and exits the button) is fill out the validation rules for each control you want to "turn on or off" for the validation box.

Related

JQuery ContextMenu not firing for disabled item

I have an excel-like table. The following picture represents a part of it (for clarification, I setted the text of the inputs to be their respective IDs):
There is a ContextMenu that is fired on right click (code here) in each one of the inputs.
Here is how I find all these input controls at once (I need to use this way because there are some more columns that I do not want to call the ContextMenu):
$('[id^="txtF_"],
[id^="txtP_"],
[id^="txtT_"],
[id^="txtE_"],
[id^="txtM_"]').contextMenu({ ....
This works nice, however, if one of the items is disabled, the browser menu shows up instead. What can I do to fire the custom ContextMenu even if the input control is disabled?

What is the property that says a button was selected in c#?

i've been searching on internet for the property that says that a normal button was selected or not, i think there must be one because when you click a button, it turns light blue, regardless the mouse is over it or not, and when you click another button, the previous button changes back to normal and the new clicked button is set light blue.
I need it to know which button was just selected and draw a "resizing" square on it, and it gotta last as long as the button remains as the "selected one".
thanks in advance.
What you are looking for is the Focused property. For actually any Control it returns, whether it has input focus or not (so e.g. hitting Enter will cause the button to be clicked as well). Since it sounds like you want to be notified whenever that property changes, you should use the GotFocus and LostFocus events.
You can give a Control focus programmatically by calling Focus.
you can do two things,
you can do it with the events: mouseEnter and MouseLeave,
this events launches when the mouse enters or leaves the visible control area,
also the focused(boolean) property gets and sets the "selected" element
one solution could be to:
private void onElementMousenter(blablabla,sender e);
{
e.Focused=true;
}
and assign the mouseEnter events in all controls to this one so the last element will be the "selected one" until you select another

is there a way to identify the last control that was active in a .net windows forms code-behind?

I have a form where there is group of radio controls and some with textbox.
If the cursor is on textbox and i try switching the cursor to a different radio button, i should be able to identify the last active control( in this case.. the textbox) and do some validation.
The LostFocus() event of textbox pops up message indicating that "this item should be filled in..".
But if i want to go with a different radiobutton option in the same group, i dont want this message popping unnecessarily.
How do i avoid that?
The TextBox has Validating and Validated events-- you should use those instead of the LostFocus event. In the case of Validating, you can stop the user from leaving the TextBox if the criteria isn't correct. If you must use "something" like LostFocus, use the Leave event instead.
There is no "Last Active Control" type function. You would have to track that yourself by setting a variable on the Enter event of those controls.
That will lead to an ugly mess to maintain in my opinion. Validate at the form level is probably the best choice for the end user.

How to implement a ListBox that doesn't take focus away from another control, but allows manipulation?

I'm trying to make something similar to the intellisense auto-complete box that's available in Visual Studio. The box in VS leaves focus with the text editor, but when text is entered, the box's items filter down. The selected item also remains as it is, with the same styles, even though the control doesn't have focus.
Thanks.
While you don't give it the focus it won't get the focus. About the functionality (up & down keys) you might have to handle that directly in your "text editor": if the auto-complete box is present then call the appropriate methods in your auto-complete box to simulate the "Up & Down" selection and, at the same time, you have avoid your "text editor" to react to this keys.

C# win form custom control - disable selection box, and use font color for selection indicator

I have a custom control based on the label control. My question is how I disable the selection box around this custom control when a user selects it while in design mode.
I would like to just change the font color when selected, and then change it back when unselected.
The reason for this is because when you have many labels with small font very close together it makes it hard to see the other labels when you select one of them and the selection box from the one selected obscures the user from seen the other labels that are very close to the one selected.
You cannot prevent it from being selectable at design time. It is considered a component of the form and you will always be able to select it in order to be able to delete it or modify its properties by selecting it.

Categories

Resources