Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6025491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:18:31+00:00 2026-05-23T04:18:31+00:00

So I thought that an enum would help me with States. Basically, I have

  • 0

So I thought that an enum would help me with States. Basically, I have a little Sidebar app which has 3 states:

Minimized – Where you can see a small and colored rectangular Panel indicating the app is open on the desktop.

Preview – Which indicated the app is open, and you can see the logo.

Normal – where the whole sidebar can be seen.

Now, I have setup an enum like this:

public enum CurrentState
{
    Minimized = 0,
    Preview,
    Normal
};

And I am trying to check the CurrentState and switch to another like this when the user clicks the always-visible panel:

    // If Min=Set(Preview). If Preview=Set(Normal). If Normal=Set(Min).
    if (State.HasFlag(CurrentState.Minimized))
    {
        State = CurrentState.Preview;
        this.Location = new Point(
            Screen.PrimaryScreen.WorkingArea.Right - _minimize.Size.Width - _logo.Size.Width,
            this.Location.Y
        );
    }
    else if (State.HasFlag(CurrentState.Preview))
    {
        State = CurrentState.Normal;
        this.Location = new Point(
            Screen.PrimaryScreen.WorkingArea.Right - this.Size.Width,
            this.Location.Y
        );
    }
    else
    {
        State = CurrentState.Minimized;
        this.Location = new Point(
            Screen.PrimaryScreen.WorkingArea.Right - _minimize.Size.Width,
            this.Location.Y
        );
    }

And when the application loads, I set the initial value to:

CurrentState.Minimized;, like this:

CurrentState State = CurrentState.Preview;

So, this is the expected behavior:

If form is Minimized, Move it a bit so it is in Preview mode. If it is in Preview, move it a bit so it is in Normal mode. If it is in Normal mode, set it to Minimized again.

But, upon clicking the always-visible panel the first time, it works as expected. It sets it to Preview mode and moved the form a bit.

But, that’s as far as it goes. Once it’s in Preview mode, it does not go to Normal mode upon clicking the Panel a second time, which means that it’s currently impossible to get it to normal view.

Am I doing something wrong here?

Although this may be uncommon, it is logical, and I can’t figure out where something is going wrong.

Here’s a little visual to help better clarify what I mean:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:18:32+00:00Added an answer on May 23, 2026 at 4:18 am

    The code as you have it always enters the Minimized branch of the if/else structure.

    The code below that doesn’t use the Flags but instead compares the enums works correctly and progresses through the states as you want:

    if (State == CurrentState.Minimized)    
    {        
        State = CurrentState.Preview;                        
    }    
    else if (State == CurrentState.Preview)    
    {        
        State = CurrentState.Normal;                        
    }    
    else    
    {        
        State = CurrentState.Minimized;                        
    }
    

    One thought though, which would probably make this design a lot easier to work with is to implement the State pattern.

    As the name suggests, this design pattern deals with exactly the situation you are trying to solve.

    Essentially the logic for your three states would get split out into three seperate objects that implement something like IWindowState where IWindow state includes a method called MoveState. When MoveState is called, the state object for a Minimized window knows the next state is Preview, and the Preview object knows to go to Normal.

    For your case this might be design overkill, but as soon as you want any more complex logic like “move from minimized to preview unless the user has a setting to move directly to normal” then the pattern pays for itself in properly managing the complexity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an applet, which I was writing in Java. Recently, I thought that
We currently have a WCF service that has been setup with its own DataContracts
This is for the C preprocessor experts: How can I declare an enum with
I have a VB6 project that references COMSVCSLib and one of the methods makes
My code is starting to look out of control so I thought I would
Problem I have a protobuf message definition with a MessageType field, which is an
The whole story; I have some KeyValuePairs that I need to store in a
I have built a parser using a FSM/Pushdown Automaton approach like here (and it
Greetings StackOverflowians, As discovered here , Windows 7 features a bug in which the
In this question , I use xor operator between enum with [Flags] attribute as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.