Including another window forms with in an "Iframe" in vb.net - vb.net

I want to include another form in my code instead of constantly contacting the other form and making the form move with each other, which takes a lot of time to code in each form. And now I need something that takes less time and is much easier to do, like putting one windows form inside another windows form
EDIT: Unclear Question
I want to display a windows form inside another windows form,
just the same functionality as an Iframe in HTML, but instead
of including a web page I want it to include a form

MDI interface would be best, but if you really want to do this then look at this : (formFrame is the form that is shown inside formHost)
formFrame.TopLevel = false;
formHost.Controls.Add(formFrame);
formFrame.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
formFrame.Dock = DockStyle.Fill; // can be different for you needs
formFrame.Show();

Related

How to change the order of open "tabbed forms" in MS Access via VBA

I am using "tabbed document" forms in MS Access (each main form that is open has a "tab" to allow users to easily move between forms).
Does anyone know of a way to reorder such opened forms via VBA? I have workaround code that closes all the forms and then re-opens them in the order I need, but it is clunky and slow (some of the forms are big so take a while to load, and often users have applied filters/sorts which I then need to individually re-apply, plus resetting the current record etc etc).
As all I need is to change the order of the forms on-screen, so my approach seems like overkill - but I can't seem to find info on how to do this anywhere!
(FYI I am NOT talking about the order of pages within a tab control, to avoid any confusion!)
Please attached screenshot with three tabbed forms open, I'd like to re-arrange them so eg left to right they become: #Home, Booking Detail, Enquiry Detail
Thanks
Ok, I have inadvertently figured this out.
In testing I found that if you hide a tabbed form, when you unhide it, it doesn't show up in the same position, but in fact now shows as the last form (ie the rightmost tab)
Eureka! Now to reorder the forms I simply hide them, and then unhide them in the order required. Combine this with DoCmd.Echo = False and there is, in my testing, virtually zero overhead.
Phew!
If the user is not seeing all the forms at once, you don't need to waste resource/time loading all forms at once. Load only what the user supposed to see. NavigationControl is very good for that.
Method 1
Move from tabbed documents to NavigationControl. Each tab is loaded OnDemand hence your main form start-up would be much more quicker. If the main and tabbed form are related to each other, use tabbed form's OnOpen event to dynamically change the record source.
I.e. Form_Open => me.RecordSource = Select * form T1 where T1.id = ParentForm.Id
Method 2
If you can't move to Navigation control, simulate the same effect as above.
When tab pages are changed/selected => underlying form gets a record source.
I.e.
Private Sub TabCtl2_Change()
If Me.TabCtl2.value = 1 Then
me.subform1.recordsource = source
me.subform1.LinkChildFields = linkingFieldName 'if related
me.subform1.LinkChildFields = LinkMasterFields 'if related
ElseIf Me.TabCtl2.value = 2 Then
'Your other form
end if
End Sub
This can help you to reduce your loading time.
[Cascading result sets]
In case if all of your forms are showing cascading results, you might want to consider remove record-source for all of your subforms and then re-apply at each selection.
The goal is to minimise loading time and show only necessary data the user is supposed to see/want to see. Hope this helps to have some idea.

Very slow design view on a complex form with a lot of controls

Let's start with a confession: I came from a VB6 background, and I'm accustomed to coding within the events of objects on a form, and as such my code for events ends up in somewhat random order in the code window. With this habit, it's never been very important to remember the names of controls (although I name them well)... I just double click on a button in the design view, which brings me straight to the code for that control's primary event. If I forget the name of a control, I click it and view properties. It's not a habit I've moved away from.
Well, now this is catching up to me. Using VS Express 2013, I have a form that contains a HUGE number of containers-within-containers, labels, buttons, and other doohickeys. I ported my code from VS.NET Express 2008 where this wasn't a problem. But now the act of selecting any control in the design view takes around 10 seconds before I can view its properties. If I drag to resize a control, and another 10 seconds passes before I can select another control. It makes designing this form nearly impractical.
In this particular project, I'm using use a tab control (which is never visible to the user) to design many "screens" which each contain panels full of controls. The panels for each "screen" are moved out of the tabs and docked into the main form as requested by the user changing screens. (I'm using the term "screen" to mean a window full of controls, usually maximized.)
Within the same project, a simple modal password-change form isn't slow to edit controls visually, even if the complex form is still visible in the IDE.
My question is in three parts:
First, what the heck is it spending all that time doing?
Second, is there a setting I can tweak to improve the speed?
Third, should I give up on trying to speed it up as-is, and move each "screen" into its own form for design purposes to avoid this slowness? (It's a lot of work to do that now... see next paragraph.)
Thus far I have avoided separating "screens" onto separate forms because I don't want a new window to come up when users change screens, and because code for the controls in one screen may affect the properties of controls on other screens... In such cases I prefer not to write out
form.doohickey.text = "blah"
..but rather keep it as ...
doohickey.text = "blah"
I'm using VB but I don't think this question is VB-specific.)
First off, I feel your pain. I have a management section of the application that I'm writing and I'm using a TabControl as well. I have 10 tabs so far and I've only added controls to about 4-5 tabs. I just added up the controls I have and there are about 360 controls so far on this one form and the designer file is ~3300 lines long. Currently anytime I change a property value of one of the controls or go to save the Designer, it takes about 3-4 seconds each time. I have a fairly decent machine; i5-3320M, 8GB RAM, intel 330 SSD, and it still takes a bit for it to do things within the tabControl. It also takes FOREVER to open and load the designer on that form...
What I've found is that it is easier to open a new instance of Visual Studio, create a test application, add a TabControl with the same properties, and design a new tab page from there. When I'm done I do a copy-paste into my actual project. This works great except for the few custom controls I've written in my main application project, I just have to sit and wait while adding them.
I'm now answering my own question. This is the approach I've ended up using, and it helps a lot...
My overall goal was to have an interface that didn't present a lot of windows, but still presented many different "screens".
I used to place all the different controls of different "screens" on separate panels, which were each contained in separate tabs of an invisible TabControl. I would then move those panels to my main form as needed by changing their Parent property of each panel as needed. The only problem with this is that the Winforms designer got ridiculously slow as the number of controls on a form increased into the hundreds.
Now, I am now designing each "screen" as a separate form, each of which contains a panel whose Dock property = Fill. Such a panel contains everything else on the form. The form itself never becomes visible.
As needed for to view various screens, I execute:
ScreenForm.Panel1.Parent = Mainform
...or, depending on how I lay it out...
ScreenForm.Panel1.Parent = Mainform.PanelXYZ
...I also either unload or hide any panels which already exist in the panel's new container.
I was GLADLY SURPRISED to find that the code for the various events of the controls contained in the panels would still run, because such code exists in the first form's file, not the displayed form's file. Luckily, it seems I was wrong. Event code follows the control itself. I can copy/paste not only controls, but also their corresponding event code to new forms for easier development and a faster Winforms designer.
All of this is similar to a MDI interface with maximized windows, but no title bar or [X] is displayed.
Essentially I'm doing everything as I did before, except using separate forms with panels instead of separate tabs with panels. The WinForms designer is much quicker because there aren't so many controls on any form.
I think I accidently found a workaround for saving a lot of time when changing the name of a control on a overpopulated container/project. Before you change the name, toggle False/True the "Generate Member" property of the control you want to rename(I believe you can also locate this under the "Name" property). This adds a few more clicks to the procedure but saves a lot of time. My not-yet-finished project has over 4000 controls and multiple forms and some of them are very "heavy" (10 - 20 seconds to normally change the name of a control). This, of course, don't help in anyway with the loading time of the project (about 35 seconds for me) but I can live with it. Let me know if this works for you too.

Reset focus to control with lowest tab index

I have a form that is re-used. That is, instead of creating a new instance of the form each time, the form is kept hidden, and is made visible when needed. (A design I inherited; I presume this was a performance optimization.)
The problem: The second time that the form is used, the focus is on the OK or Cancel button, from the first use of the form.
The user wants the focus to start the way it did the first time the form appears - on the control with lowest tab index.
If there were just one such form, I would hack it: add a line of code hardwired to the desired control.
But there are many such forms, and the visibility logic is in a common base class.
So it would make more sense to do this right, and tell the form to focus on its first (lowest tabindex) control.
Is there an easy way to do so?
(I could iterate through all the controls, but then I have to correctly handle nested controls. Since the GUI has to do this the first time it shows a form, I am hoping there is some method I can call that does it for me.)
(Coded in VB.net, but a C# answer would be fine.)
It is a one-liner, the logic to find the next control is exposed as a method, SelectNextControl(). You should start at the Form object, the one that can never get the focus, and ask it to find the next one in the tabbing order. Which is the child with the lowest TabIndex, whatever value it might have.
So something like this:
public void ShowAgain() {
this.Show();
this.SelectNextControl(this, true, true, true, true);
}
And do consider that a Form object that isn't visible is a rather major resource hog, using up lots of operating system resources for a small convenience. Surely you can also Close/Dispose it and recreate it when needed. YMMV.
You can try to set ActiveControl property before making form visible:
_frm.ActiveControl = null;
This should clear the active control for the form and remove focus from its controls.

Making multiple forms appear as one in VB.NET

I am writing a Windows Forms application in VB.NET. I have three forms: the main form, which shows a list of accounts, the account form which allows the user to view/edit the information for a specific account, and the policy form which allows the user to view/edit the information on a specific policy for that account. I want the forms to appear as if they are all the same window. Example: when the application starts, the user clicks an account name in the list box on the main form and clicks "edit". What I want to happen is that the window stays in the exact same place and stays the same exact size, only the content of the main form appears to be replaced with the content of the account form. Same thing if the user then chooses to edit a policy from the account form. When the user finishes and clicks "save", the main form comes back up. Through this entire use case, it would appear to the user as if they were viewing the same window the entire time, with the content of that window changing.
How can I do this? I have tried something like:
Dim newForm as New AcctForm
newForm.Location = Me.Location
newForm.Show()
Me.Close()
The problem is that if the user moves the original window, the new window appears where the parent form originally appeared, not where it ended up.
I see this is already in the comments, but what I have done in this case in the past is build each "form" in the application as a custom control. Then I have one actual form, and navigation works by changing which custom control is currently loaded on the parent form. To move from one screen/view to another, you remove the current custom control from the form's controls collection and add the new custom control.
I believe this is superior to manually setting the startup position and size, because you can use the form's .SuspendLayout()/.ResumeLayout() methods to hide the interim state, where there is no control loaded, from the user. This is harder to do when you want one form to be completely replaced by another.
This also makes it easy to set certain form properties in one place and have them be consistent for the application. You can even have an area on the form with controls that will now show in every view.
When using this pattern, I typically have each of my custom controls inherit from a common base. You may not have anything specific you will do with that base at the outset, but it almost always comes in handy later.
Finally, switching to use this scheme is easier than you think. Just go to the code for the each of your current forms, and you will find that each class currently inherits from System.Windows.Forms.Form. Most of the time, all you really need to do is change them to inherit from System.Windows.Forms.Panel and you're most of the way there.
As others have said, it may be better to redesign your application using custom controls or panels etc.
However, to answer your question regarding the seemingly random location of your forms, the first thing to check is that each form has it's StartPosition property set to Manual.
If your main form is resizable, then I would also add code to adjust newForm to the same size too.
I hope that helps with your immediate issues; so that you can move on to redesigning the application!
good morning there is another way . set property for second form to (top most) and use also
from2.show();
that make you switch between forms and keep form2 top other
Thanks
try using ShowDialog()
Dim newForm as New AcctForm
newForm.Location = Me.Location
newForm.ShowDialog()
Me.Close() <-- removed this

Closing an XAML form

I am creating a windows 8 store application using vs2012.
I am tying to switch to another xaml form by click of a button but cannot do it.
I want the code to close or hide the current form and to switch over to new form .
Regards
If you are looking to wholesale replace the content then you can use the Frame.Navigate() method.
Frame rootFrame = Window.Current.Content as Frame;
rootFrame.Navigate(typeof(YourPageClass));
or simply
this.Frame.Navigate(typeof(YourPageClass));
remember that not every elemet has property hide or something like that. If you want to hide a grid with form or do a simillar thing you need to know the property that is responsible for visibility (in most cases it is Visibility and it is a bool).
The second thing is that you can be a newbie but if you want help make some effort and give us what you want
The third thing. If you want to change a page after click use Marc`s solution