• 0

[VB.NET] Send form to always be in the back?


Question

17 answers to this question

Recommended Posts

  • 0
  gameguy said:
Why? What's the point of even having a form to show anything if it's never going to be seen?

585546886[/snapback]

Well, I want it to be in front while the form is visible, but when it is not visible it still takes the focus away from other windows that are open (which is a huge problem).

  • 0

I don't get it. When a form isn't visible (hidden or closed), it's not taking focus away from other windows :huh:

Also, wait at least 24 hours to bump a thread (Y) Not everyone is in the same time zone, not everyone is online every day, and not everyone checks every thread in every forum ;)

  • 0
  gameguy said:
I don't get it. When a form isn't visible (hidden or closed), it's not taking focus away from other windows :huh:

Also, wait at least 24 hours to bump a thread (Y) Not everyone is in the same time zone, not everyone is online every day, and not everyone checks every thread in every forum ;)

585550836[/snapback]

Sorry about the bump. :blush:

  weenur said:
I'm a little confused, too. How is it that a child window on a hidden form is taking focus?

585552122[/snapback]

The webbrowser control (the IE component) on the form automatically brings the form to the fore front. So when the form is visible, the form is on top of every other form - however, when the form is not visible the form just steals focus from the current window with focus.

I was thinking of a way to solve it- would it be possible to detect the process that has focus automatically. For example, if I have Firefox as my active window and then I switch to notepad as my active window, could I detect that change in focus using an existing library or class? That way I could automatically send focus back to the window that my form stole focus from.

I'm not asking you to write code for me, I just want to know if such a class exists.

Thanks

  • 0
  gameguy said:
I still don't see how a control on a hidden form is taking focus... can you post some code and a screenshot?

585552765[/snapback]

It's the webbrowser control. It's like using Internet Explorer and getting a pop-up. The webbrowser control somehow hooks into my program's form and sets it as the active form. A screenshot wouldn't really show you much - but I'll try to explain it a little better.

I create a program that sits in the system tray (just a little icon) while the form is invisble. While it's hidden I programmatically visit site and extract the important information from the HTML file. The problem is that some sites act as a "pop-up" and try to mimic the behavior of a popup. When the form is visible the form really does pop-up. It also pops-up when the form is invisible, but it remains invisible, so all that you see happening is the form taking the focus away from the window you were working in.

Maybe there is a way to suppress the browser control from altering any of the properties of my program. I'm not really sure. It's really bugging the heck out of me though.

  • 0
  weenur said:
Perhaps you should use the WebClient object to get your page data instead of the browser control, and only use the browser control when you want to display something.

585553577[/snapback]

I do ocassionally look at the rendered page - so the browser control is necessary.

  • 0

Try This:

Add a checkbox to the form.

- In my code I used "khchk" as the name of the checkbox.

Change "Form1" to whatever your form name is in the code below.

This makes sure it doesn't pop up without permission from the user(by checkbox).

 ? ?Private Sub Form1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus

? ? ? ?If Me.khchk.Checked = True Then

? ? ? ? ? ?Me.Visible = False

? ? ? ?End If

? [b]This minimizes the form to tray.[/b] form to tray.

[code] ? ?Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize

? ? ? ?If Me.WindowState = FormWindowState.Minimized Then

? ? ? ? ? ?Me.Visible = False

? ?[b]Restores the window. This code is needed for the next code clip[/b]s needed for the next code clip

[code] ? ?Private Sub RestoreWindow()

? ? ? ?Me.Visible = True

? ? ? ?If Me.Visible = True Then

? ? ? ? ? ?Me.WindowState = FormWindowState.Normal

? ? ? ? ? ?Me.TopMost = True

? ? ? ?End If

? ? ? ?If Me.TopMost = True Then

? ?[b]This makes the form visible or hidden depending on whether it is visible or not and whether the checkbox is checked or not.[/b]ther it is visible or not and whether the checkbox is checked or not.

[code] ? ?Private Sub unhide()

? ? ? ?If Me.Visible = False Then

? ? ? ? ? ?If Me.khchk.Checked = False Then

? ? ? ? ? ? ? ?Me.RestoreWindow()

? ? ? ? ? ?End If

? ? ? ?El[b]This is an option for a button to check to checkbox and keep the form from showing itself.[/b]/code]

This is an option for a button to check to checkbox and keep the form from showing itself.

[code] ? ?Private Sub KeepHidden()

? ? ? ?If Me.khchk.Checked = True Then

? ? ? ? ? ?Me.k[b]Add a context menu to the tray icon with a button that runs: Me.unhide() and a button that runs Me.KeepHidden()

Like maby just the tray icon's click sub[/b]h a button that runs: Me.unhide() a[b][color=lightblue]DigitalSnow[/color][/b]e tray icon's click sub

Hope this helps,

[color=lightblue]DigitalSnow[/color]

Edited by DigitalSnow
  • 0
  VB Guy said:
I do ocassionally look at the rendered page - so the browser control is necessary.

585553724[/snapback]

Then I suggest you use a WebClient object and when you wish to view the page, create a WebBrowser on the fly (Y)

  • 0

I'd be interested in this to....basically, if the z-order of the form gets changed, it sends itself right back to the bottom of the order. I'm just not sure what event is triggered, if any, when the z-order gets changed. If I know that, then I can simply use a sendtoback command.

  • 0
  Cool4 said:
well, i see everyone is creating a browser for SJ :p

i think you should look in the webbrowser control methods because it's WB that is taking the focus even if the form is hidden

585560391[/snapback]

SJ? I'm not sure what that stands for.

Anyway - I do recall seeing some code written for VB 6 that showed how to do it - but I can't find it. It was at PSCode.com. If anyone has any progress don't hesitate to post. I'll keep looking too - there has to some API that can accomplish this.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • You do realize that if you are using Full Self Driving that you aren't actually driving, right?
    • I see several on eBay. Am I blind, or is this something else? Link (I know this link isn't in UK, but an example)
    • When my Tab S9 FE tablets were upgraded to Android 15 and Samsung UI 7.0 there were some default systems changes. One of them was. when I wanted to Power Down the tablet and tapped the Power button, Gemini popped up and I had to say Power Off which then brought up the Power Off menu resulting in an extra step in powering down the tablet. After some sleuthing I found that I could turn off Gemini and go back to the old menu, so I did. Maybe one day I will be comfortable talking to a machine but that day is not today.
    • Rufus 4.8.2253 by Razvan Serea Rufus is a small utility that helps format and create bootable USB flash drives, such as USB keys/pendrives, memory sticks, etc. Despite its small size, Rufus provides everything you need! Oh, and Rufus is fast. For instance it's about twice as fast as UNetbootin, Universal USB Installer or Windows 7 USB download tool, on the creation of a Windows 7 USB installation drive from an ISO (with honorable mention to WiNToBootic for managing to keep up). It is also marginally faster on the creation of Linux bootable USBs from ISOs. A non-exhaustive list of Rufus supported ISOs is available here. It can be especially useful for cases where: you need to create USB installation media from bootable ISOs (Windows, Linux, UEFI, etc.) you need to work on a system that doesn't have an OS installed you need to flash a BIOS or other firmware from DOS you want to run a low-level utility Rufus 4.8.2253 changelog: Switch to wimlib for all WIM image processing: Greatly speeds up image analysis when opening Windows ISOs Can speed up Windows To Go drive creation (But won't do miracles if you have a crap drive) Might help with Parallels limitations on Mac (But Rufus on Parallels is still unsupported) Enables the splitting of >4GB files with Alt-E (But still WAY SLOWER than using UEFI:NTFS) Others Switch to using Visual Studio binaries everywhere, due to MinGW DLL delay-loading limitations Add more exceptions for Linux ISOs that restrict themselves to DD mode (Nobara, openSUSE, ...) Improve reporting of UEFI bootloaders in the log, with info on the Secure Boot status Fix an issue with size limitations when writing an uncompressed VHD back to the same drive Fix a crash when opening the log with the 32-bit MinGW compiled version Fix commandline parameters not being forwarded to original Windows setup.exe Download: Rufus 4.8 | Portable | ~2.0 MB (Open Source) Download: Rufus 32-bit | ARM64 Links: Rufus Home Page | Project Page @GitHub | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Posting Machine
      David Uzondu earned a badge
      Posting Machine
    • One Month Later
      Stokenking earned a badge
      One Month Later
    • One Month Later
      Kevin Jones earned a badge
      One Month Later
    • Week One Done
      Kevin Jones earned a badge
      Week One Done
    • One Month Later
      henryj earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      531
    2. 2
      ATLien_0
      267
    3. 3
      +Edouard
      199
    4. 4
      +FloatingFatMan
      189
    5. 5
      snowy owl
      138
  • Tell a friend

    Love Neowin? Tell a friend!