.NET : Double-click event in TabControl - c#

I would like to intercept the event in a .NET Windows Forms TabControl when the user has changed tab by double-clicking the tab (instead of just single-clicking it).
Do you have any idea of how I can do that?

The MouseDoubleClick event of the TabControl seems to respond just fine to double-clicking. The only additional step I would do is set a short timer after the TabIndexChanged event to track that a new tab has been selected and ignore any double-clicks that happen outside the timer. This will prevent double-clicking on the selected tab.

For some reason, MouseDoubleClick, as suggested by Jason Z is only firing when clicking on the tabs and clicking on the tab panel does not do anything, so that's exactly what I was looking for.

How about subclassing the TabControl class and adding your own DoubleClick event?

Related

AcceptButton for Different Tabs

I'm new to Visual Studio and am converting a C# console app to VS so that I can give it a GUI. The GUI piece is definitely a learning curve.
I have a main Form1 with Tab1 and Tab2. I can call this.AcceptButton, but it only appears to be at the form level. Is there a way for each tab to have an AcceptButton? I can't call this.Tab1.AcceptButton, however when I am in Tab2, the function of AcceptButton doesn't seem to trigger. Is it because the button doesn't exist on the tab that is in focus?
I could certainly forgo using AcceptButton if there's not a clean way to do this, but it would increase the usability of the application.
Thanks in advance!
You can listen to SelectedIndexChanged event on your TabControl. So whenever tab is change this event will fire and you can use assign another button to AcceptButton.
Have a look at this: Change accept button with tabs

Want to do some stuff when ultracomboeditor got focused

I am using UltraComboEditior of Infragistics Conrtrols in C# winform application, I want to show a messageBox when UltroComboEditior got focues by MouseClick or KeyBoard Tab button, how can I do it? Any suggestions ? I tried BeforeDropDown but it is called only when we click on arrow button to show drop down list but I am using only drop down with auto complete option set to be true.
UltraComboEditor control has "Enter" event which fires when the control becomes the active control of the form, and this event will fire in both situations - when the control got focus by using your Tab key, and when you are using your mouse.
I hope that this will help you to achieve your goal.
Doesn't it inherit the OnGotFocus event which you can subscribe to?

How to tell when the user has clicked outside of the bounds your control?

I have a custom UserControl. I want to use it in a few different products, so I want something that can be implemented inside of the UserControl itself. I want to know when the user has clicked outside of the bounds of the UserControl so that I can hide it, similar to a ComboBox. How can I do that?
I tried handling the click event, but it only seems to fire if the click occured within the bounds of the control.
That's what the Capture property is designed to do. Set it to true and all mouse messages are routed to your control, even if it moves out of the window bounds. Check the e.Location property in the MouseDown event.
Hm, you may be able to accomplish what you want by listening to the GotFocus/LostFocus events. ComboBoxes give the drop downs focus when they open and close them when they lose focus.
do this
Select all controls on your form including form
In Property Window select MouseClick event
Now enter below Code in Common_MouseClick
Code:
if (!sender.Equals(yourControl))
{
yourControl.Visible=false;
}

C# WinForm MenuStrip Event doesn't seem to fire

I don't do much WinFom development so I am not too familiar with the MenuStrip control. I have added a menu strip to my form and added (1) item to it. All of this was done using the designer.
So I have Utilities -> Download Utility. When I double click on 'Download' in the designer an event handler is created for me.
private void downloadUtilityToolStripMenuItem_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Ding!");
}
UPDATE:
I noticed that the IntializeComponent() in the constructor of my form never seems to be run. I have placed a breakpoint in the constructor and it never hits. I refactored this form to change the name from the default (form1) to 'main'. I assume this is the problem but I don't see why. All of the form1 references seemed to have been updated. I did this with the IDE.
When I debug this application I can never seem to get this event to fire. What am I missing here?
-Nick
Check on the property page of the menu item (under events - click the lightning icon) if the Click event has a handler.
Check:
Properties Window for the menu, click on the menu item in question for the 'Download'
Click on the 'Lightening Bolt', a small icon below the top of the Properties Window, if you were to mouse over it, it would display 'Events' in the tooltip.
Scroll down and look for the 'Click Event' under Actions, double click it, to let VS automatically fill in the event handler for you
OR
Double click on the menu item within the Forms Designer, that will default to the menu item's click event and fill in the code for the 'Download' Menu item, i.e. MessageBox.Show("Ding");
Hope this helps,
Best regards,
Tom.
I got it working. Apparently when debugging the project it wasn't rebuilding. After refactoring the name of my form it was necessary to 'Rebuild' the solution. Now all over my events work as they should. Thanks for the help.

Use right-click with Windows Forms Button

I am writing an app where the user should be able to alter the action of a button.
The user should right-click a button, and choose an option from a pop-up context menu. Once the choice has been made the button will perform a different action when the user uses a normal click.
I've already gotten the "Click" event working for a normal button click, however the "MouseClick" event handler isn't working correctly.
The "MouseClick" event gets activated on regular left-clicks, but never get's called for right-click.
Is there some default event handling being performed that is ignoring that right-click?
I'm sorry to say that this would be a serious UI blooper. Perhaps it would make more sense to add a small combobox next to the button.
Perhaps something like this?
http://www.codeproject.com/KB/buttons/SplitButton.aspx
If you want to display a context menu with actions to choose from it should be enough to assign a ContextMenuStrip to the ContextMenuStrip property. There is usually no need to manually handle the mouse events for that.
surely it would be better to implement it on the MouseDown event rather than the MouseUp event. i dont understand how this is much different from MouseClick event
edit: Just tried this and it works a treat :)
In Button (and certain other controls), the MouseClick event is only fired for the left button. Refer to MSDN.
If you want to know about the right button, respond to the MouseUp event--though as other posters have pointed out, this isn't a great UI idiom.
Use the Mouse UP event... test that Button.X and Button.Y are within the size of the button otherwise you have moved the mouse away from the button.
Terry G

Categories

Resources