How to Control where a form loads - vb.net

This is going to be the first of many questions I am sure.
I am starting to create an application in VB.net and I am not super familiar with the language yet. I am trying to design an application based off of a system tray icon and by that I mean, when you launch the application, there should be no initial form that loads, just the icon in the system tray.
From there I need to do two things. I would like "on mouse-over" to pop-up the form right above the system tray and "on double-click" have it open in the middle of the computer screen.
I am successful in using "static" placement {Me.Location = New Point(800, 390)}
I can get the windows/forms to open where I want them to, but the problem is when I change to a different computer they don't open in the correct location. I need a way to make sure the forms open in correct location no matter the screen resolution.
Can anyone recommend what I should Google to learn more about form placement or maybe even a link. Being so new to the language, my Google attempts have failed and I am needing more direction and a little hand holding until I get the terminology down and an idea of what I am looking for,...

If you want to dynamically place your form based off the desktop size, check out:
SystemInformation.VirtualScreen.Width
SystemInformation.VirtualScreen.Height
...and move your form based on these dynamic values. e.g.
Me.Location = New Point(SystemInformation.VirtualScreen.Width - Me.Width, SystemInformation.VirtualScreen.Height - Me.Height)
For more information about VirtualScreen, check out MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.virtualscreen.aspx
VirtualScreen will give you the combined size and width of multiple monitors, so as an alternate, you could also simply look at the primary screen, e.g.
Screen.PrimaryScreen.WorkingArea.Width
Screen.PrimaryScreen.WorkingArea.Height

you can use Me.CenterToScreenTo center it to the users screen and as far as i know that is the best you can do

In form properties there is a property StartUpPosition set it to CenterScreen

Related

vb.net: keep form always keep back and never got font by click

I want to make a desktop item manager program using vb.net.
I hope to create a form there and use the menus etc. to make the desktop icons work.
You want to set the form to always be behind the other windows. Like a widget.
How to do this?

How to keep MS Access Forms only in the MS Access Window/Canvas?

I have created my MS Access Program but I have multiple monitors and so do the other people who will be using the program.
Just so you know my forms are popup style, have no borders or record selectors and I am guessing this is where my issue comes in.
I would like to know if there is a way to ensure that when a user opens a form, the form will only open within the MS Access Window/Canvas on the active monitor?
I would also like to know if there is a way for my application to automatically adjust according to the users screen resolution?
As an example my Forms open perfectly when I am using the application on my main screen which has a resolution of 3840 x 2160 but if I open the application on my second screen which has a resolution of 1920 x 1080 the forms that open subsequently, such as the user form, then opens on the main screen so small that no one can read or see it.
Application is on Right monitor and User Form is Open on Left (Main) Monitor
The code I have used for the OnOpen Event is below:
Private Sub Form_Open(Cancel As Integer)
Dim Right As Integer, Down As Integer
Right = Screen.ActiveForm.WindowLeft
Down = Screen.ActiveForm.WindowTop
DoCmd.MoveSize Right, Down
End Sub
This was obtained from some research but I cant seem to bind everything to the Application Window/Canvas.
Thank you.
Well, if you only ever have one window open at one time, then you can do this with ease.
Remember, today most applications are SPA (what we call single page applications). We don't use (nor have) very often a main applcation window, and THEN a child window. For one, they tend to not be touch friendly, and it is VERY hard to move a window around with touch.
but, even desktop browsers even use some "kind" of tabbed interface. And so do most desktop applications. And by tabbed - I don't necessary mean across the top. This access screen shows a tab system from the left side:
So, Access now has a option to use tabbed interface.
And if you :
do NOT use pop windows.
Set access to use tabbed interface, eg this:
Then un-check the display tabs.
If you do above, then you WILL NEVER EVER see the access background window.
You see this:
However, keep this in mind:
The form you launch will re-size to the main size of the Access window - not the other way around.
All forms can't be popup
You are "SPA" like applcation.
So, most accounting and most desktop applications now work this way. And WHEN you launch a form, the window does not re-size tot he form, but remains the current applcation window size.
So, without ANY specials code, you can 100% hide the access background window.
And if you re-size the access application window, then the form will re-size to fill out the current form.
This might look quite bad in some cases - such as this:
Now for above, I on purpose made the form background green - just to PROVE and show that that Access background window NEVER will display with above options.
So, the main issue here?
You can 100% hide the access background window. And you can now do this WITHOUT specials code. Just a few settings.
On startup, you can hide the ribbon - or build a custom one - again your choice.
But, your forms MUST NOT be popup forms anymore.
So, hiding the access background window is very easy - it then becomes a question of form size - size forms re-size to application window size - not the other way around.
On the other hand, if you adopt a tabbed interface (accross the top or left side), then your main window is always in display, and you are in effect swapping out the form (a sub form) for display of that given form. You can write your own code, or use a new navigation form - which does this for you).
If you need to launch separate windows, then you could launch them as popup from this main form - but that main form will of course always hide the access background if you follow above.
If you wish to hide the ribbon, then on your main form - load event, you can add this code:
DoCmd.ShowToolbar "Ribbon", acToolbarNo
So, your main form (which hides access background) could be tabbed inteface (SPA) or it could be a launcher form, and each option clicked on could launch a form as popup - which can be dragged anywhere on your computer - including to the 2nd monitor if you wish.
So, either forms stay always in the main applcation window - but never see the background. Or you use above, and launch forms as popup.

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

VB.NET forms keep disappearing while system is in use

We have a "Core" system that we use to run the business and there are about 15-18 people using it at any one time. The program is written in VB.NET and has about 165 forms.
The way it works is when the user runs the program he/she is prompted to log in and if the login is successful a "Main" form is displayed with a number of menus (Customers, Suppliers...). From there they can click on the menus which open another form on top of the "Main" (the "Main" form needs to be visible in the background because it displays information that is relevant to the users while they are in other screens)
The issue we are having is that if the users have other programs open while using the "Core" system (Outlook, Word, Chrome, anything really) and switch to another program and then back to the system, it only displays the "Main" form and any other forms open on top disappear. The way we get around this is by switching back to the other programs they have open and clicking on the minimise button in the top right corner of the window until all the other programs are minimised, which only leaves the "Core" system visible. However this is becoming a nuisance to all the users (including myself and the other developer) and we really need to sort this issue out in order to keep out staff happy :)
I would appreciate any advice or pointers in the right direction which will help us solve this issue and please feel free to ask if you need any more information.
It seems you are creating the ChildForm from the MainForm but the ChildForm itself is showing itself with Me.ShowDialog(). What you should probably try is showing the form from the MainForm and passing the MainForm in as the parent. This should keep the form tied to it's parent and on top. For example:
childForm.showDialog(Me)
Where Me is the MainForm. This is the documentation for that method.
This is the important part:
Owner Type: System.Windows.Forms.IWin32Window
Any object that implements IWin32Window that represents the top-level window that will own the modal dialog box.
Does that make sense?
Changing code to show dialog will change behavior of your code little bit, like your main from execution will hold till you close child form
But you can you use only show as child (not dialog)
childForm.show (Me)
This will not change anything except whenever you click on main form it will display its entire children on it.

Controlling output to a TV display while control panel is on laptop screen?

I have a program written in VB.Net with Visual Studio 2008. I have one window form to display on a laptop that controls the information seen/sent on another form that is to be continually displayed on an output from the laptop to a TV, Projector or Monitor.
Or I would like to accomplish this:
Computer/laptop - Has window form 1 that controls the program
TV/Ouput - Has window form 2 that shows updated data on the screen for people to see
I do not want people to see the control form that is on the laptop.
Is their a way to assign a form to use an output to other screen only?
You can create two forms, one is the control panel with startup on the primary screen (default). For the other form, set the location to that of the secondary screen (i.e. TV or projector). To do this, iterate through i.e. Screen.AllScreens.Where(x=>!x.Primary).First(). The WorkingArea property gives the rectangle in which to place the second form.
Try this application. I had developed it for our local channel...
http://www.mediafire.com/file/dq01lf4zbasstso/Videobox%20%28dual%20screen%20video%20player%29.zip
or try this...
http://www.mediafire.com/file/mahr69wdll5l5yn/now%20showing.zip
I don't know if I completely understand your problem...
There are several ways of making 2 forms to communicate, one could have a reference to the other, or you could have some "manager" or "controller" class that knows about both of them. If both forms are from different apps you must resort to sockets, named pipes, a message queue, have some middle layer like a webservice, etc.
About sending the display... again, I don't know if I've understood you, if both the form1 and form2 are located in the same computer, you can use System.Windows.Forms.Screen to get the laptop monitor and TV information, like their resolution and coordinates, and locate the forms themselves or other content in the corresponding screen.
You have two ways to go ahead.
A. Using separate Projector or monitor as second monitor for your laptop(Dual Monitor).
To start with the configuration of dual monitor refer this and this.
For this kind of setup your both forms would be running on the same machine. To adjust the display form on second monitor refer this and this
Controlling the second form can be achieved by creating instance of that form and controlling the instance from first form.
B. Using two machines one as controller and second as presenter.
For this kind of setup. You will need two applications to run. And need socket(TCP/UDP) communication to communicate between both.
I feel you are looking for first solution.
Are you just trying to send text to the second form?
Will following work or am I not understanding your question?
frm2.label1.text = me.textbox1.text
Regards
Jake