Daily Tip: How to Activate Minimized Window (Form)

24 בדצמבר 2009

This solution can be used in WPF and in WinForms (with some improvements).

Many times UI programmer needs to activate window, the activation can be done by using “Activate()” function in window. The problem is that this function will not show window if it is minimized. In that case you can use this workaround:

using System;
using System.Windows; 

namespace Test
{
       public partial class MyWindow
       {
              /// <summary>
              /// Gets Previouse Window State
              /// </summary>
              public WindowState PreviouseWindowState { get; private set; }  

              /// <summary>
              /// Constructor
              /// </summary>
              public MyWindow()
              {
                     InitializeComponent();

 

                     // store 1st value
                     PreviouseWindowState = WindowState;

 

                     // attach to event (used to store prev. win. state)
                     LayoutUpdated += Window_LayoutUpdated;
              }  

              /// <summary>
              /// Occures on layout change
              /// </summary>
              /// <param name="sender"></param>
              /// <param name="e"></param>
              private void Window_LayoutUpdated(object sender, EventArgs e)
              {
                     PreviouseWindowState = WindowState;
              }  

              /// <summary>
              /// Activates Window
              /// </summary>
              /// <param name="restoreIfMinimized">if [true] restore prev. win. state</param>
              /// <returns></returns>
              public bool Activate(bool restoreIfMinimized)
              {
                     if (restoreIfMinimized && WindowState == WindowState.Minimized)
                     {
                           WindowState = PreviouseWindowState == WindowState.Normal
                                                                     ? WindowState.Normal : WindowState.Maximized;
                     }
                     return Activate();
              }
       }
} 

As you can see I added new overloaded function “Activate(bool)” that allows activation of minimized window, thanks to new property “PreviouseWindowState” that stores previous value of “WindowState” when “Window_LayoutUpdated” in called.

Source Code: Window.cs

Remarks: Any comments/improvements will be accepted with pleasure. Of course, you must understand that this code is a contribution and I’m not responsible for any damage that may be caused by using it. All rights reserved ®.

Add comment
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים

תגי HTML מותרים: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

25 comments

  1. sam25 בדצמבר 2009 ב 2:22

    thanks :)
    your trick helped me!

    להגיב
  2. Odina17 בפברואר 2010 ב 22:44

    Hi all. Greetings to all. Help me! I can not find sites on the: Non electric waffle iron. I found only this – electric branding iron for cattle. Although appropriate barbequing hours could heat apparatus lights which add wrestler knowledge from camera without winding simple sectors of versatile wastes, the higher application of the wall of these products may retrofit the grafting of affordable note, electric iron. Electric iron, it held at time 1 on the evaluation ingredients and found power contact. With best wishes :-) , Odina from Arabia.

    להגיב
  3. Steph4 במרץ 2010 ב 21:28

    Hello,

    First thanks a lot!

    I got some troubles with the Windows State restoration and finally did:
    private void Main_Resize(object sender, EventArgs e)
    {
    if(WindowState != FormWindowState.Minimized) PreviouseWindowState = WindowState;
    }

    public void Activate(bool RestoreIfMinimized)
    {
    if (RestoreIfMinimized && (WindowState == FormWindowState.Minimized))
    {
    WindowState = PreviouseWindowState;
    }
    Activate();
    }

    Which made it.

    Steph.

    להגיב
  4. seo24 באוקטובר 2012 ב 1:19

    Plz don't erase this particular publish. I want seek attribute in Exotic Concept. Plz help me.

    להגיב
  5. Shaffer4 באפריל 2013 ב 16:49

    George Forman used to have a monopoly in the genre of former athletes marketing indoor counter top grills.
    Now unplug and open the Belgian waffle maker to confirm if it is properly baked.
    Another to let you know the baking is in progress and the final light that
    tells the cook the product is done.

    להגיב
  6. Gavin4 באפריל 2013 ב 17:00

    The Valor Fitness BG-11 10 Pair Dumbbell Rack comes with protective rubber base caps and four
    angled iron beams. Take a chest press for example; the main muscle worked is the chest,
    secondary maybe the triceps. To add variety to your routine one
    must mix up your reps, sets, weight used, rest periods, exercises, duration, and intensity.

    להגיב
  7. Vanwinkle4 באפריל 2013 ב 17:05

    5. Who's gonna keep 'em down. Along the various groups of survivors
    the doctor manages to outlive, he finds that the infection
    may have been started by a food processing plant and an additive
    that is found in nearly every food and beverage.

    להגיב
  8. Henderson4 באפריל 2013 ב 17:08

    Stand upright, knees slightly bent, shoulder
    width apart, holding dumbbells in front of thighs. Start a jogging
    or walking club with some neighbors. Nowadays, the Bowflex produces the
    optimum durability creating exercise and has special designs in comparison to
    other machines.

    להגיב
  9. Mcbee4 באפריל 2013 ב 17:15

    It will also tell you when it is time to change your brushing direction and all the other things that those LCD's used to do. For people who brush their teeth more often, the bristles may begin to wear out sooner than expected. Another reason that electric toothbrushes have become more popular in recent years is because the price of it has gone down tremendously.

    להגיב
  10. Jewell4 באפריל 2013 ב 17:21

    Surrounding the crystal was a bright sphere of Divine golden light.
    So you won't have to stumble around in the middle of the night to turn up or down the heater. With its Herculean power, the wind is capable of slipping into the home through tiny cracks in the windows and underneath the doors.

    להגיב
  11. Ruiz4 באפריל 2013 ב 17:50

    Here are the four most important ways slow cookers save you money:
    1. College kids gain on average about ten pounds the first year.
    Consumer Product Safety Commission (CPSC) is still interested in receiving
    incident or injury reports that are either directly related to this product recall or involve a different hazard with the same product.

    להגיב
  12. Cathey4 באפריל 2013 ב 17:52

    Here are my thoughts on the Durabrand Waffle Maker. When it comes to any kind of cookware or kitchen
    appliance, Wolfgang Puck remains to be at the top of the game.
    Modern makers of the waffle iron give us the challenge of
    choices on a large scale.

    להגיב
  13. Ashe4 באפריל 2013 ב 19:04

    But having bought such an expensive product there
    are some care instructions hat needs to be followed to derive the maximum benefits.
    The allergens in these compounds could be bad for people with sensitive skin, and some believe that long term exposure may be linked to certain cancers, like those of the breast.

    The summer time is the best time to have skin exfoliation.

    להגיב
  14. Pruett4 באפריל 2013 ב 21:08

    Believe it or not, just by sitting down during this bicep curl workout will actually
    add a degree of intensity. Depending on the manufacturer,
    the cost of a set will vary. This set is performed using a set of dumbbells that can be lifted alternately or
    simultaneously.

    להגיב
  15. Wild5 באפריל 2013 ב 1:27

    Examples are : A Heartful of Love, Be Mine,
    Be My Valentine etc. Therefore your needs will change in a
    supplier to purchase your goods from. Let the kids make whatever they want out of the Activ-Clay.

    להגיב
  16. Morrissey5 באפריל 2013 ב 15:47

    It was small enough to get into all the small hard-to-clean places.
    As for the UV sanitizer, you can use it every day or just once a week.
    Users usually would not need to worry regarding the battery life
    of digital toothbrush indeed.

    להגיב
  17. Mann8 באפריל 2013 ב 0:03

    Here are a few tips to help prevent and quickly clear up acne breakouts using natural, organic skin care products:
    1) Wash your face gently two times per day with warm water and a mild soap such as a goats milk soap.
    The term natural means only pure ingredients are used directly from nature
    as opposed to synthetic ingredients and organic products simply means that the molecule
    comprises of carbon and natural skin care products have no boundaries with
    regards to organic or natural products. One of the products I bought
    is the Rooting Bear Rub.

    להגיב
  18. Clancy8 באפריל 2013 ב 0:06

    Michaels offers a large variety of yarn, thread, floss, kits and cutting tools.
    You only want to shell out for genuine delivers so be mindful if you are needed for any fee or
    membership to get access to these coupons. Every time I go into A.

    להגיב
  19. Skipper8 באפריל 2013 ב 0:40

    Here are the four most important ways slow cookers save you money:1.
    Don't forget Crockpot's (slow cookers) are a great way to save money; My Crockpot (slow cooker) black beans are the easiest to make, taste great and
    are super inexpensive and healthy. Move any flammable objects away from the slow cooker.

    להגיב
  20. Flores8 באפריל 2013 ב 1:35

    But, being laughed at while preparing for a possible zombie 2012 apocalypse,
    or other consequences of the end of the Mayan calendar is going to be worth it – when the
    unimaginable and previously comically impossible actually come to life.
    The two shows this year have been advertised as:.
    It concerns the mysterious horrors of a "flesh consuming" existence, symbolically speaking more or less, that depict the grotesque lawlessness and selfishness of humankind.

    להגיב
  21. Epperson8 באפריל 2013 ב 1:48

    They have had them on since, and haven't once tried to remove them. It only takes a second for a child or pet to receive a serious burn. On a $200 a month gas bill, this would lower the bill by $50.

    להגיב
  22. Blackburn16 באוגוסט 2013 ב 15:18

    "special deals", " deep discounts", "clearance items", "cheap merchandise", and "special coupon offers".
    A good place to explore and share all the gastronomic
    delights of India is the Khana Khazana website. Keeping this craze in mind companies are opening
    outlets in different parts of the world.

    להגיב
  23. Kuntz26 באוגוסט 2013 ב 3:28

    Probably the most important thing after blade size is the size of the table top.
    There are a number of important areas to consider when making
    a purchase of an power tool, and table saws are no exception.
    The table saw additionally boasts 8" treaded pneumatic wheels so, like a fierce, all terrain table saw, the tool confidently maneuvers through difficult jobsite environments.

    להגיב
  24. Cushing29 באוגוסט 2013 ב 15:47

    When all else fails, you can always call your favorite shop and ask what pizza deals they are offering.
    Pizza delivery used to be strictly a phone transaction, but now the internet has brought ordering
    pizza to a new level. There is the Neapolitan pizza
    usually called the pizza Napolitano.

    להגיב