form not visible

Christ Kennedy 196 Reputation points
2021-02-18T12:42:53.383+00:00

i have a windows application.
the form is not visible but the app reports that it is.
i have a timer event

private void TmrDebug_Tick(object sender, EventArgs e)  
{  
System.Diagnostics.Debug.Print("Size(" + Width.ToString() + ", " + Height.ToString() + ")"  
                                + "Loc(" + Left.ToString() + ", " + Top.ToString() + ")"  
                                + "Visible:" + Visible.ToString()   
                                + " State:" + WindowState.ToString());  
}  
  

that reports every 500 ms and this is my screen shot

69563-screenshot-183.png

you can see the timer event reporting in the output window telling me that the form is visible
but it is NOT.

why is this happening?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,247 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,036 Reputation points
    2021-02-18T13:19:53.08+00:00

    Hello,

    The following has a Timer and a button in a standard windows form project. Click the button to toggle visible and in this example Visible is reported correctly.

    namespace WindowsFormsApp1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                Shown += OnShown;
            }
    
            private bool _loaded;
            private void OnShown(object sender, EventArgs e)
            {
                _loaded = true;
            }
    
            private void Form1_VisibleChanged(object sender, EventArgs e)
            {
                if (_loaded)
                {
                    Debug.WriteLine($"{Visible}");
                }
    
            }
    
            private async void button1_Click(object sender, EventArgs e)
            {
                Visible = !Visible;
                await Task.Delay(2000);
                Visible = !Visible;
            }
    
    
        }
    }
    

1 additional answer

Sort by: Most helpful
  1. Christ Kennedy 196 Reputation points
    2021-03-20T10:16:31.687+00:00

    ok.
    I eventually pulled the wool out from in front of my eyes and noticed that the form's vertical location was WAY off below the screen.
    what was happening was that I had a SaveFormat.txt file that sequentially resized and positioned the form but the form's SizeChanged() & LocationChanged() event handlers were playing funny with it until I added a boolean telling them to bolIgnoreChanges while the load formatting was happening.
    I am way too paranoid, next I'll think the North Koreans hacked my 4th grade class-president election.

    thank you for your attention

    0 comments No comments