Results 1 to 9 of 9

Thread: Bring form to front

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2013
    Posts
    4

    Bring form to front

    I am using VB 10.0 (2010), and have written a program that is linked with a data set. I am looking to bring the form to the front when the correlated data changes. I have a timer set to update the data, but it stays in the background when it updates, even though I have it set to top most. When the application is run, it is brought to front until an action is taken, but once it is in the background, it stays there unless you physically bring it back up. If anyone has any information on how I could get the form to pop up as an alert that is brought to the front when the data changes, that would be greatly appreciated. Thanks.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Bring form to front

    It might help if you describe the scenario more exactly. Are we talking about ...

    a) a single form application that needs to become the topmost application when data changes

    b) a multiple form application in which the data form is always open but needs to be foremost when data changes

    c) a multiple form application in which the data form is not (or does not need to be) always open but must open and come to the forefront when data changes

    d) some other entangled combination of forms that my little brain can't yet encompass ?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2013
    Posts
    4

    Re: Bring form to front

    It's a single form application that needs to become topmost when the data changes, so no matter what the programmer is doing, they need to deal with the form that pops up before they can continue.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Bring form to front

    You can call the Activate method of a form to make it the active window, which you presumably want if the user is supposed to do something with that form before anything else.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2013
    Posts
    4

    Re: Bring form to front

    How would I go about doing that? I'm still fairly new to VB, and tried to figure it out but I wasn't able to. I tried using form.activate(), but it said it cannot refer to itself through its default instance; use 'Me' instead. So I used Me.Activate() but still don't get the form brought to the front with data change.

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Bring form to front

    So I used Me.Activate() but still don't get the form brought to the front with data change.
    Well you can't just stick it anywhere and hope for the best! Obviously you need to run the command in response to something actually happening! You mentioned a timer so did you place the code in the Tick event handler, for example?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2013
    Posts
    4

    Re: Bring form to front

    I have it in the timer tick event handler, and it activates when the timer finishes, but it activates in the background still. I guess a better question to ask would be, if I have the program minimized, how can I get it to activate and pop up on top?

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Bring form to front

    I guess a better question to ask
    ... would be the one that you actually require the answer to? Yup, reckon it would!

    vb.net Code:
    1. Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    2.         Me.Activate()
    3.     End Sub
    4.  
    5.     Private Sub Form1_Activated(sender As System.Object, e As System.EventArgs) Handles MyBase.Activated
    6.         If Me.WindowState = FormWindowState.Minimized Then Me.WindowState = FormWindowState.Normal
    7.     End Sub
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Bring form to front

    Quote Originally Posted by anixon29 View Post
    I have it in the timer tick event handler, and it activates when the timer finishes, but it activates in the background still. I guess a better question to ask would be, if I have the program minimized, how can I get it to activate and pop up on top?
    Hmmm... you figured that it would be a good idea to wait until post #7 before telling us that the form was minimised? I suggest that, in future, you have a good think about what information is relevant before posting because if you omit a critical point like that then you're wasting everyone's time.

    Having said all that, I would not suggest doing any of this. As you may have seen yourself, often times a window's icon on the Taskbar will flash when that window wants your attention. That's what you should be doing. To suddenly bring a window up in front of someone who is in the middle of something else is rude and dangerous. There have been times when I've been typing something into one window and then another pops up and some of my keystrokes get sent to it before I realise. It is extremely annoying and if I hit Enter or some key combination that has special meaning to that window then I might dismiss it or perform some action unintentionally. That's just plain bad.

    What you should be doing is using the FlashWindow API, which is what will make the Takbar icon for your window flash. That should be enough to get the attention of the user and they can then choose for themselves when they are ready to address it, as should be the case.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width