Anyone know if the Ribbon control (using a Ribbon Window WPF project in VS 2010) has an event handler for when the tabs are minimized?
I tried looking around the events but I couldn't find anything that worked.
I'm assuming you want the Ribbon.Collapsed event, or it's corresponding Expanded event.
Its IsMinimizedChanged in older version. I am using version 2.0 and had to disable minimize functionality on ribbon.
IsMinimizedChanged event is called when the minimize button on ribbon is clicked or someone double click on the tab.
I inherited the Ribbon and added the following code to detect if Ribbon is being minimized or maximized:
Event IsMinimizedChanged As EventHandler
Private mIsMinimized As Boolean
Protected Overrides Sub OnChildDesiredSizeChanged(child As UIElement)
MyBase.OnChildDesiredSizeChanged(child)
If TypeOf child Is Grid Then
If Not mIsMinimized = IsMinimized Then
RaiseEvent IsMinimizedChanged(Me, EventArgs.Empty)
mIsMinimized = IsMinimized
End If
End If
End Sub
Related
I have a popup menu which is displayed when the user minimizes the form. However, when a user clicks on a background program such as a document of MS Word my form is behind the document but not minimized or hidden. Therefore, I cannot control this. Is there an Event on VS which can be used?
Try the Form.Deactivate event:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.deactivate%28v=vs.110%29.aspx
Description from MSDN:
Occurs when the form loses focus and is no longer the active form.
You can use Deactivate Event of a WinForm
Private Sub Form1_Deactivate(sender As Object, e As EventArgs) Handles Me.Deactivate
'Your code Here
End Sub
Use the Form.Deactivate event, it's called when the form loses focus.
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.deactivate%28v=vs.110%29.aspx
I noticed something weird , for the textbox there are some events that just appear in the code, but in the design(when I open properties , and click on the events tab) these events are not visible !
for example :
textbox1.LostFocus += textbox1.LostFocus;
or the GotFocus event .
Anybody has an idea regard this ??
thanx in advance
it is because some events not Browsable
if you check the documentation you will see [BrowsableAttribute(false)] for the events like GotFocus
if BrowsableAttribute false then that event not displayed in a Properties window.
Note The GotFocus and LostFocus events are low-level focus events
that are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages.
Typically, the GotFocus and LostFocus events are only used when
updating UICues or when writing custom controls. Instead the Enter and
Leave events should be used for all controls except the Form class,
which uses the Activated and Deactivate events.
In which method / function do you register (+= ) that events? Only the events registered in the InitializeComponent (DesignerCode) / constructor code, are considered by the Designer.
Edit: In that case, Damith is right with Browsable(false).
My answer would be valid if you see the event in the Designer, but not the linked event handler method.
I have written a custom control in C# (inherited from Forms.Control) and it seems to working fine, but if you press the button fast enough a problem occurs: only every other click will call the click event handler. This doesn't happen if you don't press it fast (less than once a second). The mouseUp and mouseDown handlers always get called no matter how fast you click the button.
Of course doesn't happen with the canned winform button.
I cannot use the canned button because I'm writing an application for the .net compact framework, so I need a custom control in order to make the UI more presentable. Also, I tested out my code on the full version of the .net framework, and I still have the same problem.
Any help would be greatly appreciated. Thank you!
If you are clicking rapidly enough, you are getting into DoubleClick territory.
According to above MSDN Page the order of events are:
The following series of events is raised by the control when such a user action takes place:
MouseDown event.
Click event.
MouseClick event.
MouseUp event.
MouseDown event.
DoubleClick event.
MouseDoubleClick event.
MouseUp event
If you will notice there is only one Click event per DoubleClick
For a way to disable it try looking at this MSDN Page discussing ControlStyles.
From above link:
StandardClick -- If true, the control implements the standard Click behavior.
StandardDoubleClick -- If true, the control implements the standard DoubleClick behavior. This style is ignored if the StandardClick bit is not set to true.
So try this in your controls constructor or load event:
this.SetStyle(ControlStyles.StandardClick, true );
this.SetStyle(ControlStyles.StandardDoubleClick, false);
Since SetStyle does not appear to be in the Compact Framework you could add a DoublClick Event and have it trigger the Click event Programmically like this.
YourClickEvent(sender, new MouseEventArgs(System.Windows.Forms.MouseButtons.Left,1,0,0,0));
When you click your control fast enough, it calls double click rather than click.
So, you should do something like this in your click function:
{
control.Enabled = false;
......
control.Enabled = true;
}
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.
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?