• 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

    • I think they mean a phone like the s6 edge where it breaks on first drop guarantee
    • This high-end GEEKOM Mini IT12 (2025 Edition) PC has been slashed by $200 by Steven Parker GEEKOM reached out to let us know of a discount it is running on its site in the U.S., where you can save $200 off the i7 model of Mini IT12 2025 Edition. That brings the already discounted price of $699 down to just $499; buying link below. Below are the full specifications of the variant on offer GEEKOM Mini IT12 (2025 Edition) Dimensions Size 117 x 112 x 45.6mm Weight 652g CPU Intel Core i7-1280P (14 Cores, 20 Threads, 24MB Cache, up to 4.80 GHz) Graphics Intel® Iris® Xe Graphics Memory 32 GB Dual-channel DDR4-3200 SODIMM; expandable up to 64GB Storage 1 TB x M.2 2280 PCIe Gen 4 x4 SSD, expandable up to 2TB 1 x M.2 2242 SATA SSD slot, expandable up to 1TB Operating System Windows 11 Pro Bluetooth Bluetooth® v5.2 Ethernet Intel® 10/100/1000/2500 Mbps RJ45 Ethernet Wireless LAN Intel® Wi-Fi 6E AX211 Kensington Lock Yes Adapter 19V power adapter, 90W, with geo-specific AC cord (IEC C5) I/O Ports 3 x USB 3.2 Gen 2 ports 1 x USB 2.0 port 2 x USB4 ports 1 x SD card reader 1 x 3.5 mm headphone jack 1 x 2.5GbE LAN port 2 x HDMI 2.0 ports 1 x DC jack 1 x Power button MSRP $699 (see below for discount price) You may remember that we reviewed the i7-1260P variant in 2023. Here are our initial impressions of the Mini IT12 at the time. Once you have the PC out of the cushioning inside the box and the foam removed, you are greeted with a Thank You envelope. Below that, after removing the cardboard "shelf," you can find the other components, such as the power lead, HDMI cable, VESA mount plate with a bag of screws, and the instruction manual. What’s In The Box 1 x Mini IT12 Mini PC 1 x VESA Mount 1 x Power Adapter 1 x HDMI Cable 1 x User Guide 1 x Thank You Card As you can see, one HDMI cable is included in the box. Since the port is not HDMI 2.1, you will need to consider purchasing a mini DisplayPort cable or a USB4 (Type-C) to DisplayPort cable to maximize the potential of the Iris Xe Graphics display options. In addition, GEEKOM offers a one-year full warranty on its products, and if needed, you can RMA or return them locally relative to your region (the U.S. has a U.S. warehouse, and the E.U. has a Germany warehouse). Buy the i7-1280P Mini IT12 (2025 Edition) for $499 (was $699) at GEEKOM U.S. Buy the i7-1280P Mini IT12 (2025 Edition) for $499 (was $699) at Amazon U.S. When checking out, use the $30 in-page coupon or NEOIT122025 coupon code. Best of all, the shipping is quick and free.
    • That's ######ing hilarious! And it sure works when you look at both of their faces.
    • When it comes to games specifically, sure, but until now the main focus has been on doing work. All you have to do is look at how hard they're pushing AI in the productivity space to see that they've got their enterprise users in mind 1st with gamers lower on the list. Now that should all change, at least for custom gaming devices like handhelds and even, I expect, custom mini-PCs that are like consoles you can put under your TV. The whole "Xbox PC" branding they had around the show says a lot IMO.
    • I'm excited to check this out. I never played the first version, but I did just finish playing through Smalland, and while I liked it, I found myself wishing for more engaging content.
  • Recent Achievements

    • Enthusiast
      the420kid went up a rank
      Enthusiast
    • Conversation Starter
      NeoToad777 earned a badge
      Conversation Starter
    • Week One Done
      VicByrd earned a badge
      Week One Done
    • Reacting Well
      NeoToad777 earned a badge
      Reacting Well
    • Reacting Well
      eric79XXL earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      470
    2. 2
      +FloatingFatMan
      282
    3. 3
      ATLien_0
      249
    4. 4
      snowy owl
      202
    5. 5
      Edouard
      196
  • Tell a friend

    Love Neowin? Tell a friend!