Unable to set height of frameless Form

M

mwsenecal

I'm new to C#. Fortunately my background in other languages has made
the transition rather painless.

I'm trying to create a banner that resides at the top of the screen.
To do this I have created a class that inherits from Form. Obviously,
I don't want a frame, title bar, or taskbar button, so I eliminate
these, and set it so that it is drawn at the top of the screen.

BackColor = Color.White;
this.FormBorderStyle = FormBorderStyle.None;
this.Taksbar = false;
this.TopMost = true;
this.StartPosition = FormStartPosition.Manual;
this.Dock = System.Windows.FormsDockStyle.Top;
this.Size = new Size(Screen.PrimaryScreen.Bounds.Width, 16);
this.Left = 0;
this.Top = 0;

By and large, things are working as expected. The problem I'm having
is that I can't get the minimum height of the banner to go below
what's about 20 pixels. That is, even if I explicitly set the height
to smaller (as above), it won't get any smaller. I'm starting to think
that the way I eliminated the border and title bar has something to do
with it. I've played with minimum size, maximum size, and a few other
things, but nothing has worked.

Is this possible, and how would I go about it?

Many thanks,

---Matt
 
M

mwsenecal

After much experimentation I figured it out. I found that if I did my
form sizing as part of a Load event, it worked perfectly.

In my initialization method:

this.Load += new EventHandler(load_routine);

And somewhere in the class:

private void load_routine(object sender, EventArgs e)
{
this.Size = new Size(Screen.PrimaryScreen.Bounds.Width, 16);
} //end load_routine

And that did it! Hopefully this will help someone that's in the same
situation I was in.

---Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top