• 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 are missing the point, we should not have to do that. Should have a do you want an MS account option on the normal sign in.
    • Hynix 2TB Platinum P41 NVMe Gen4 2280 SSD is back at a mouth-watering price by Sayan Sen If you are in the market for an SSD, especially an M.2 2280 NVMe drive, then take a look at the Platinum P41 from SK hynix, which is currently back to its lowest price in the last six or so months (purchase link down below). This is a Gen4 SSD that promises sequential reads and writes of up to 7000MB/s and 6500MB/s, respectively. Meanwhile, the sequential read and write speeds are rated at up to 1400K IOPS and 1300K IOPS, respectively. The 2TB variant of the P41 features a 2GB DDR4 DRAM cache as well, which is meant to improve write caching and random access times with quicker metadata look-ups. Hynix says that the drive can operate at temperatures of up to 70 °C and thus you should opt for a heatsink if you intend to do data transfers for longer periods at a time. That should not be a problem, as the P41 Platinum is based on 176-layer TLC NAND and has a rated endurance of up to 1200 TBW (terabytes written) for 2TB. Make sure to update the firmware for the Platinum P41, as it fixes a throttling issue wherein the SSD would drop speeds after being used for several months (via Lower-Tone-3503 on Reddit). SSD firmware updates can often resolve critical problems, like in the case of WD/SanDisk SSDs, for example, which are still blocking Windows 11 24H2 due to inappropriate firmware. Get the SK hynix P41 at the link below: SK hynix Platinum P41 M.2 2280 NVMe SSD without heatsink: $129.99 + $10 off w/ promo code SACET23323, limited offer => $119.99 (Newegg US) You can also check out the other SSD deals we have covered in these articles here. This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • Until EVs get solid state batteries that can last 800miles+ on a single charge in Canada's -50°C weather, all while functioning 100% offline, they're still just at a guineapig testing stage IMO, and simply not worth purchasing...
    • I would question if Neowin really needs science research studies/stories than.
    • Microsoft reveals Mu, an on-device small language model built into Windows 11 by Pradeep Viswanathan Last year, Microsoft revealed Copilot+ PCs featuring a dedicated Neural Processing Unit (NPU) capable of over 40 TOPS or more. These Copilot+ PCs came with Phi-Silica, an on-device SLM to bring language intelligence capabilities to Microsoft's own first-party apps and apps from other 3rd-party developers. Today, Microsoft revealed Mu, a new on-device small language model built into Windows 11. Microsoft's goal was to create an AI-powered agent within the Settings app that can understand a user's natural language queries and integrate it into the existing search box for a smooth user experience. Hence, Microsoft is using the new Mu model to power the new agent feature in the Settings app, which was made available to Windows Insiders recently in the Dev Channel with Copilot+ PCs. Like Phi-Silica, Mu is designed to operate efficiently on NPUs, delivering over 100 tokens per second while running locally. In the official blog post, Microsoft explained how they designed and trained the Mu language model. Here's an overview of the Mu language model: Mu is a 330M encoder-decoder language model. The encoder-decoder approach achieved about 47% lower first-token latency and 4.7× higher decoding speed compared to a decoder-only model of similar size. Mu uses weight sharing in certain components to reduce the total parameter count. Microsoft trained Mu using NVIDIA A100 GPUs on Azure Machine Learning. Mu is nearly comparable in performance to a similarly fine-tuned Phi-3.5-mini, despite being one-tenth of the size. The model is better suited for multi-word queries. So for short or partial-word inputs, the Settings app will continue to surface lexical and semantic search results in the search box. Interested users can download Windows 11 Build 26120.3964 (KB5058496) or higher to check out this new AI-powered agent in the Windows Settings app.
  • Recent Achievements

    • Dedicated
      tesla maxwell earned a badge
      Dedicated
    • Dedicated
      Camlann earned a badge
      Dedicated
    • Week One Done
      fredss earned a badge
      Week One Done
    • Dedicated
      fabioc earned a badge
      Dedicated
    • Week One Done
      GoForma earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      633
    2. 2
      Michael Scrip
      224
    3. 3
      ATLien_0
      219
    4. 4
      +FloatingFatMan
      142
    5. 5
      Xenon
      135
  • Tell a friend

    Love Neowin? Tell a friend!