Visual Basic .Net, keep windows on top of other on-top windows - vb.net

I have created a program that I want to show in the taskbar the whole time. It launches a few keyboard shortcuts when I press their buttons. The program works great, but the windows taskbar needs to be set to always on-top or programs will maximize over it too.
If I have both my programs and the windows taskbar set to be always on top, My program is on-top of the taskbar until I click anywhere in the taskbar, for example to activate another program.
My code is as follows:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.Bounds = Screen.PrimaryScreen.Bounds
Me.TopMost = True
'...
End Sub
I considered using a timer to activate my program once in a while, but the downside to that approach is, that if I am typing in another application and the focus is moved to my program, this is very annoying.
So my question is as follows: Is there a way I can interact with the taskbar so my program is always ontop of it, regardless of anything else, or is it possible to periodically restore the on-top status so my program becomes on-top of the taskbar again without the focus going to my program?
I prefer that my program is always ontop if the taskbar, and clicking the taskbar does not temporarily make my program invisible. For example, if I can set the z-order of my application to a higher level than the taskbar, that would be best. If otherwise I can somehow spawn my program as part of the taskbar, that would also work.
PS: I have enabled the search bar in the taskbar and my program is supposed to cover it entirely. I don't use the search bar and it gives me a dedicated space without worrying covering any open programs.
PS2: This is just for me, no need to worry about anyone who has different preferences. My goal is to optimize my workflow, so the least hastle I have daily, the better.
This is what it looks like when the app runs, but clicking the taskbar makes the window invisible.:
So... How can I make sure my program stays on-top of the taskbar, even if I click somewhere in the taskbar?

Apparently the solution was pretty simple.
I was afraid of side-effects, but the solution I applied works perfectly.
I added a timer, enabled it, and every tick it simply does:
me.Topmost = true
If I now click the taskbar, the program is obviously pushed to the back, but every 100ms when the timer ticks, the program is automatically put back on top without the app actually receiving focus.

Related

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.

Win Forms VB App in Win 10 - focus issues

I have an app built in VB in Visual Studio 2012 that works absolutely fine on my windows 10 desktop, but as soon as i use it on my windows 10 tablet i see a couple of issues :
1) any forms that were intended to be smaller than full screen are shown fullscreen anyway (almost as if you're not allowed any windows less than full screen) i can live with that if need be, but surely theres a way around it?
2) - the most important one - for some strange reason, i start my app, and when i click on a button let's say it opens form 6. once i finish what i'm doing the code closes the form 6, but the previous form is now hidden and all you see is the desktop. ie it's still running, it just lost its focus and must be selected again. I understand i could set the focus to the underlying form before closing form 6, but here's the problem : it can be one of several different forms calling form 6..... so how do i make the app stay aware of what form called form6 so that when done i can return focus there?
this doesnt seem to be a problem on the desktop so i've never encountered it before. i hope one of you experts has dealt with this before
I don't have enough points yet to comment. My guess for #1 is either resolution or DPI differences between the 2 screens, and I don't have experience with the latter.
As for #2 and keeping the form aware of who called it, this is how I do it, which may not be the best solution, of course. ;)
First any form that can have multiple callers has a variable defined like
Dim callingForm As New Form
I typically create an Initialize routine to handle as much as possible before loading a form and this routine is called with the parent form (Me) as a parameter.
Dim frm As New frmClient
frm.Initialize(Me)
frm.Show()
Me.Hide()
In Initialize, callingForm is set to the parent
Public Sub Initialize(parent As Form)
callingForm = parent
'whatever else you need to do to init...
End Sub
Then when you exit the form...
Private Sub exitForm()
'whatever other closing stuff you need to do...
callingForm.Show()
Me.Close()
End Sub
That should get you started.
fyi for anyone encountering this problem, i solved it myself and it didn't require any coding. It was a difference between how vb apps act when the tablet is in "TABLET" mode, and when tablet mode is switched off. So all that needed doing is switching off enhanced tablet mode in the windows 10 settings

vb.net menu strip shadow remains after viewing

I am using a MenuStrip in my application like this:
Private top_menu As New MenuStrip
Private menu_item_file As New ToolStripMenuItem("File")
and I add items to the menu like this:
With top_menu
.Items.Add(menu_item_file)
End With
With menu_item_file
.DropDownItems.Add(sub_menu_item_show_all)
.DropDownItems.Add(sub_menu_item_show_reg)
End With
The menu drops down and it has a shadow (by default). It works fine in Windows7, but when I test it in XP, the shadow remains after the user moves away from the menu (or clicks the item). I can't figure out what is causing this. The menu continues to work fine and drops down every time the user hovers over it, but the shadow never goes away. The menu does drop down over an existing panel which has a picture in it, but I don't think that is causing this behavior.
It's some kind of bug in Win XP. Only appears when you have set your picture to your bacground. Cured by turning off shadows in Win XP.
http://www.codeproject.com/Articles/19277/Let-Your-Form-Drop-a-Shadow

Why does my form appear behind everything?

I have a program where I need to do some initial work before calling the form, so I disabled the Application Framework setting and wrote my own Main function with a call to Application.Run(myForm) when it's time to run the form.
Everything was working fine, no problems, but now I have need of some other service before opening the form. Rather than add all that code to this program, it has all been moved into its own executable. This second program can edit files that the first program will use, so I need the first program to wait so that it will read up those changes (should they be made). I suppose could just as easily use the Shell function, but for various reasons I'm creating my own Process object and calling it/waiting on it through that.
Anyway, I make this call to the second program some time before the Application.Run call. The first program waits its turn, and I can interact with the second program successfully, no trouble at all. But when it's done, the window for the first program is hidden behind any other windows that are on the screen. This doesn't happen in XP, only in Vista (and maybe 7, but I haven't confirmed yet). I've already tried manually forcing the form to appear in front, minimize then maximize, get focus, etc, but nothing brings it to the front unless the user manually clicks on it with the mouse.
What am I doing wrong? Why does this behavior occur? I know it has something to do with waiting for the executable to finish, because if I don't force the first program to wait everything is fine (other than it not waiting). I can circumvent the issue by calling the second program in the Load event of the form, but then I have to read the file a second time to catch the changes instead of reading it once, and it also looks bad because the form is being drawn really slowly while the second program is sitting there.
If anyone has any input, I'd appreciate it.
This isn't really an answer to why you're experiencing this behaviour, but a simple workaround would be to temporarily set the form's TopMost property to True in the load event. Then, depending on how intrusive you want that to be, you could either reset it under a short timer or wait for say the MouseEnter event to fire.
There are another topic in this site about that, but I not got the link. This problem seems be a bug into .NET framework. The API below (VB.NET example) works for me in windows XP and 8.1. Don't tested in other versions of Windows.
<Runtime.InteropServices.DllImport("user32")> _
Public Shared Function SetForegroundWindow(hwnd As IntPtr) As Integer
End Function
Private Sub Form_Load(sender As Object, e As EventArgs) Handles Me.Load
SetForegroundWindow(Handle)
End Sub

Winforms: Closing a program to system tray

'This is the event that is fired as the application is closing, whether it
'be from a close button in the application or from the user
'clicking the X in the upper right hand corner
Private Sub Form1_FormClosing(sender as Object, e as FormClosingEventArgs) Handles Form1.FormClosing
'What we will do here is trap the closing of the application and send the application
'to the system tray (or so it will appear, we will just make it invisible, re-showing
'it will be up to you and your notify icon)
'First minimize the form
Me.WindowState = FormWindowState.Minimized
'Now make it invisible (make it look like it went into the system tray)
Me.Visible = False
End Sub
Hello again Stackoverflow!
Im trying to make an application that when you press X, the program gets put in system tray. But i have like no idea how i'm suppost to do that, so did a search on google and found this code. Only VB2010 (what i use) doesn't like the fourth line. Can anybody give me a quick tutorial on this, and make this work in VB 2010?
By the way, i will most likely use VB only tonight, just to make one application. So im not thinking of learing the whole language.
It looks like you found code over here Dream.In.Code: Minimize To System Tray
Did you "keep" reading the rest of the messages?
You need to add:
e.Cancel = True
to your FormClosing event or else the program just ends. Also, you need to add the NotifyIcon component and a ContextMenuStrip.