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
Related
I know how to close a sub form and go to main form by clicking "close" button under file menu bar, but I don't know how to cancel a subform and go to main form by clicking the cross button --"cancel" which is located on the upper right corner.
and then back to the main form
Update:
I have tried go to form property, under Event,there is an item called, FormClosing, write a click event funcation name,i.e cancel_Click, and then press enter. Then I can write code under cancel_click, but it rises another problem. Since I want use same code here as the one under "close" on the menu (both can redirect back to the main form), when I close on menu bar, it appears two main form. How can I fix this?
use Form.Closing event and then do what ever you want to do. link
Set the FormClosing event for the sub-form to go to the main form. Set the FormClosing event for the main form to exit the program.
I am showing some database records in a Dialog. When I click any particular record that record fills to Active Form. But I want to focus to a button when my dialog close. So I have written the following code on form closing evennt.
private void frmDG_RecordSelection_FormClosing(object sender, FormClosingEventArgs e)
{
RecordSelectionStatus.Text = "False";
Form TargetForm = Home.ActiveMdiChild;
Button SelectRefConsultant = (Button)TargetForm.Controls.Find("btnSelectRefConsultant_NI", true).SingleOrDefault();
SelectRefConsultant.Focus();
TargetForm.ActiveControl = SelectRefConsultant;
}
But it's not working. Focus still remain to it's previous place. What am I missing ?
I am assuming that the dialog is modal... Instead of doing this in FormClosing do it, after calling ShowDialog(). If not, try using the FormClosed event instead.
I think your code is not working because, while the Form is closing, it still has modal focus.
If frmDG_RecordSelection is also MDIChild, then Home.ActiveMDIChild is this form. That is being closed.
But if frmDG is just a Dialog, the problem is different.
This dialog is Closing. But it's still visible. You cannot set focus to control that is not visible.
So you will have to set focus after this frmDG is completely closed, and invisible... To be more specific, when your MDI form is visible.
It's far more easier to do this from your MDI Form. I don't know how you have programmmed it, but I suppose it's something like that:
//this is in your MDI form
void OnRecordSelected(...)
{
frmDG yourDialog = new frmDG();
frmDG.ShowModal();
frmDG.Dispose();
}
In this case, you will have to set focus after frmDG is disposed.
I would like to remove the original event behavior of controls within a form (similar to design mode).
So, when the user clicks on the button, i only want to capture that event. I do not want the original button event to be fired. Is this somehow possible?
I am looking for a generic solution. So it should work with any form and any control within the form.
Reason: I wrote a form validation rules designer. It uses reflection to enumerate all form-types in the entry assembly. The user can then select a form type, the designer creates that form, enumerates the controls, and embedds the form in the designer panel.
clicking on a control, opens a formular designer panel, and the user can now create a formular for that control and saves the formular to a DB.
When the form is then opened in the normal "runtime" mode, it loads its validation formulars.
Events are not in fact disabled in the Winforms designer. The designer executes the constructor of the form through Reflection, everything in the InitializeComponent() method executes, including the event subscriptions. Wherever this might cause a problem, the controls check the DesignMode property (prevents a Timer from starting for example) or by custom designers. The form is displayed underneath a transparent layered window on top of which the selection rectangle and drag handles are painted. Which prevents issues with mouse clicks and keyboard focus.
You probably ought to look at this magazine article to get this working for you.
From what I understand from your question, I guess, you can still use the "DesignMode" property for this as well. In your event handling routine, you may want to bypass execution by checking on this property:
if (this.DesignMode) return;
as the first statement in your event handling block of code.
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
Is there a winforms event that fires when the user switches from a form to another window? I.e. Not through minimizing, but just by clicking on another window. How can I detect when the form becomes inactive? Thanks!
Form.Deactivate