• 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

    • Ea and Ubisoft's already have a 3rd party client mode where it removes the store features from the client and only uses 60mb of ram rather than 700.... I use playnite for gog and epic games because the the third party legendary client etc Combined in playnite epic and gog only use 200mb/ram while also showing my entire library from every other platform...
    • Also, this domain thing only works with Pro version of Windows, not the home version
    • More useless bloat to kill your pc by accident
    • Windows 11 gets more customization, a Recall home page, and more in new builds by Taras Buria Microsoft kicks off this Monday with a duo of nearly identical builds for Windows Insiders in the Dev and Beta Channels. Build 26200.5661 (Dev) and 26120.4452 (Beta) are now available for download with two big changes: a new home page for Recall and the recently spotted ability to customize where system indicators appear on the screen. The new Recall home page features more personalized content to help you get back to recent activities. It displays your latest snapshots and a curated view of the top three applications and websites you have spent the most time on in the past 24 hours. Here is what it looks like: In addition, Recall received a new nav bar on the left side of the screen with quick links to Home, Timeline, Feedback, and Settings. The next big addition is the ability to change where system indicators (brightness, volume, and more) appear on the screen. Now, you can set these at the top-left corner or top-center. To adjust this, go to Settings > System > Notifications > Position of the onscreen pop-up. Here are other changes included in today's builds: [Start menu] We are adding a Boolean to the Configure Start Pins policy to allow admins to apply Start menu pins once. This means that a user will receive admin pins on day 0 but can then make any changes to their Start pinned layout and have those safeguarded. These changes can be optionally applied through the existing configuration service provider (CSP). [File Explorer] We are restarting the roll out of AI actions in File Explorer that began rolling out with Build 26120.4151. Some Insiders may have seen the feature disappear. [Settings] In the most recently flights, we have added the country or region selected during device setup under Settings > Time & language > Language & region. Here is what was fixed: [General] Fixed the issue causing the Windows Vista boot sound to play instead of the Windows 11 boot sound. Fixed an issue where the option to reset your PC under Settings > System > Recovery wasn’t working on the previous build. Fixed an underlying issue leading to certain KVM virtual machines unexpectedly failing to boot, showing “UNSUPPORTED_PROCESSOR”. The Dev build has an extra fix: Fixed the issue causing a small number of Insiders to experience repeated bugchecks with KERNEL_SECURITY_CHECK_FAILURE after upgrading to most current Dev Channel builds. Known issues include the following: [General] [IMPORTANT NOTE] When joining the Beta Channel on Windows 11, version 24H2 – you will be offered Build 26120.4250 After installing Build 26120.4250, you will be offered the most recent update available. This 2-hop experience to get onto the latest flight in the Beta Channel is just temporary. After you do a PC reset under Settings > System > Recovery, your build version may incorrectly show as Build 26100 instead of Build 26120. This will not prevent you from getting future Beta Channel updates, which will resolve this issue. Some Windows Insiders may experience a rollback trying to install this update with a 0x80070005 in Windows Update. We’re working on a fix for Windows Insiders impacted. [Start menu] The following are known issues for Windows Insiders with the new Start menu: Using touch to navigate the new Start menu may not work reliably. For example, it currently does not support the swipe-up gesture. Drag and drop capabilities are limited from “All” to “Pinned.” In some cases, duplicate entries may appear in folders on the Start menu. [Xbox Controllers] Some Insiders are experiencing an issue where using their Xbox Controller via Bluetooth is causing their PC to bugcheck. Here is how to resolve the issue. Open Device Manager by searching for it via the search box on your taskbar. Once Device Manager is open, click on “View” and then “Devices by Driver”. Find the driver named “oemXXX.inf (XboxGameControllerDriver.inf)” where the “XXX” will be a specific number on your PC. Right-click on that driver and click “Uninstall”. [Click to Do (Preview)] The following known issues will be fixed in future updates to Windows Insiders: Windows Insiders on AMD or Intel™-powered Copilot+ PCs may experience long wait times on the first attempt to perform intelligent text actions in Click to Do after a new build or model update. [File Explorer] The following are known issues for AI actions in File Explorer: Narrator scan mode may not work properly in the action result canvas window for the Summarize AI action for Microsoft 365 files when reading bulleted lists. As a workaround, you can use Caps + Right key to navigate. [Widgets] Until we complete support for pinning in the new widgets board experience, pinning reverts you back to the previous experience You can find the announcement for the Dev build here and for the Beta build here.
  • Recent Achievements

    • One Month Later
      adnan.hebibovic earned a badge
      One Month Later
    • Week One Done
      adnan.hebibovic earned a badge
      Week One Done
    • Dedicated
      tesla maxwell earned a badge
      Dedicated
    • Dedicated
      Camlann earned a badge
      Dedicated
    • Week One Done
      fredss earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      629
    2. 2
      Michael Scrip
      224
    3. 3
      ATLien_0
      220
    4. 4
      +FloatingFatMan
      145
    5. 5
      Xenon
      134
  • Tell a friend

    Love Neowin? Tell a friend!