Form maximize on another form - vb.net

I have an MDI application which contains many child forms
My problem is, on clicking a particular menu, I am opening a form with maximize window in the MDI form. This works fine.
Now if I open another form above the first one, and if i want the second form to be of normal size, i am unable to do it.
Second form also opens with maximized window similar to first one. I want the second form to be of normal small size.
I want to show second form normally and first form maximized.
How can i do that?
Private Sub TESTToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles TESTToolStripMenuItem.Click
Dim f As New newCalendar2("UGHARANI")
f.Show()
f.MdiParent = Me
f.WindowState = FormWindowState.Maximized
End Sub

Okay, I think I understand what you're trying to accomplish: you want the first (data) form to be a kind of background to your MDI application and have the other forms display on top of it, right?
Well one way to do it might be to remove borders from the background form –FormBorderStyle = None– and fill-dock it in the MDI parent form. Although it would end up coming to the fore and hiding all your other forms if a user clicked anywhere on it. But if it doesn't require any user interaction you could always use its Activate event to send it back to the background, using Me.SendToBack().

Related

Is there anyway to not let user lost focus from winforms in vb.net?

Issue:
My Question may be weird but I need help with this.
I have this weird problem with my client PC and it all happens sometimes.
The application loses control when I close one form and opens another form.
Then he has to use the mouse and click on the form every time.
Similar but another issue.
In an MDI child form, what I do is make the user fill data in a bunch of textboxes and make the user click (or hit Enter Key) that adds that data in a datagridview row and clears all textbox and make focus on the first textbox.
At that time too the form loses focus and the user is not able to write anything. Though the textbox is still coloured (custom coloured textbox on got focus) but form loses control.
The Temporary solution:
-I make his PC restart and everything starts working fine.
-Even Closing the whole application won't help it. I have to restart the PC only.
MY Code between two forms:
Private Sub btnOk_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOk.Click
....
Hide()
frmUser.Show()
End Sub
I use Hide to close 1st form else I use close() to switch between forms.
I even face this issue of losing focus in MDI child forms too.
I even made a custom textbox that changes its background colour when it gets focus (in gotfocus event) and reverse to white when loses focus (lost focus event), so when the issue starts the textbox remains coloured and even the cursor blinking inside but I cannot type in it. Again I have to click on the application form (anywhere) and I am able to type again. Until that form closed or changed in the application.
Please help with this weird issue. Thanks...

Prevent ListView from bringing old form to front

I have a form (we'll call it Form A) that contains a ListView control. When I select an item in the ListView, the event handler creates and shows a Form B.
I want Form B to appear in front of Form A. Both forms are maximized when shown. The problem is, the ListView in Form A is making Form A take the focus back right after Form B is shown. The screen flickers temporarily, so Form B is initially in front. I know it's the ListView doing it because if I open Form B from another control, it works as intended.
I'm displaying Form B with Show(). Changing it to ShowDialog() fixes the problem, but I don't want it to be modal.
This is happening during the handler for the ListView1.ItemSelectionChanged event, and changing to ListView1.SelectedIndexChanged doesn't help.
Some code, if it makes it any clearer:
Private Sub ListView1_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
If e.IsSelected Then
Dim my_form As New MyForm
my_form.Show()
End If
End Sub
Set the ListViews Activation Property to "OneClick", then handle the ItemActivate Event and display your Form from there.

vb.net using SetParent API over IsMDIContainer?

I'm working with a set of custom controls (including a custom form), I have repainted the custom form to give it a metro style look and basically recreated the title bar of the form. Setting this form to be an MDI container causes the whole form to be repainted grey regardless of anything dictated in the OnPaint handler for the form.
I want to create a multi form application where all of the forms that are not the main form, appear inside the main form (the idea of MDI windows). I have also seen a SetParent API that achieves a similar effect without modifying its visuals, however, I have used this before to tie a cmd window to a form and it is not always reliable.
Would it be more efficient to use the MDI feature inside Winforms (if so, how do i overcome the complete recolour issue) or dump MDI and use the SetParent API to modify the child windows' parent?
EDIT: I have decided to go for using the SetParent API, it works everytime as opposed to my previous experiences with the console window. However, I need to create the window before I can set the parent and sometimes the user can see the screen flash briefly before it gets 'hooked' inside my main form. Is there a way to 'hook' it without it being visible to the user?
With MDI Parent Form if your issue is the background, then this is all you have to do, Set the IsMDIContainer property of the form to true, and then loop through each control on MDI Form to let them know this is the MDI Background, you can put this code in the form loading event,
Private Sub FormMDI_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each ctl As Control In Me.Controls
If TypeOf ctl Is MdiClient Then
ctl.BackColor = Me.BackColor
End If
Next ctl
End Sub
It might appear gray when program is not running, but it will show your desired background once the program runs

Blocking interaction between child and main parent form vb

At the moment, I have a project I'm working on with a menu that opens a new window. Annoyingly, when the new window is opened, it just does everything the main parent window does that the new window is opened up from. I want to be able to have the new window be able to do it's own thing and not just share what ever the parent is doing. Is there anything I can do at a button's click to give this form some kind of attribute that disallows this?
You can use seperate form. the working of each form will depend on what you specified in that particular form.. You can use the MDI form. and call all child forms under the mdi form. the child form will open in seperate window under MDI form.
you can simply call the child form as
Private Sub MembersToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MembersToolStripMenuItem.Click
Dim xfrm As New childForm
xfrm.MdiParent = Me
xfrm.Show()
End Sub

close form when application loses focus

My form is displayed as TopMost on my application. The problem I have is that whenever I minimize my application or it loses focus, the form remains displaying. I want to be able to minimize my application or move to another and also hide or close my form. Once the application regains the focus, then unhide or open the form again.
Here is what I worked out on the form's closing event:
Private Sub frmNavigation_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Static Minimize As Boolean
If Minimize = True Then
e.Cancel = True
Me.Hide()
End If
End Sub
I tried using the same code in the applications WindowDeactivate event but nothing happens.
You do not show how you create the instance of your frmNavigation. I am assuming that you are using the Show Method, so just use the version of Show that you pass in the top level window. That will assign the owner of the form, it will then stay on top of your Main Form and minimize and restore with it also. If this doesn't work please show how you are creating and showing your form.
frmNavigation.Show(Me)
I was able to find an answer to the question. MSDN had an article on this very issue.
it can be found here: http://support.microsoft.com/kb/186908#appliesto