3

How can I hide all of the form, but only show a label?

I want my program to only display a label. No minimize, maximize buttons. No title bar. No form background. Just a label.

I tried using FormBorderStyle to none, and resize it as small as possible. But there seems to be a minimum size of the form. It goes back to about 3cm wide, and 1cm high.

Is there any way to completely get rid of everything but my label? I also want to be able to move this label around when I hold down the mouse.

I found no code for this, so unfortunately I dont have anything at the moment.

Any help is appreciated!

edit: I am not talking about this.hide(), I want the form to pretty much vanish, while only the label is shown.

One way would be to set opacity to full on the form. But that affects my label as well. Any way to not make the label transparent?

aliazik
  • 195
  • 1
  • 5
  • 13
  • Try to set the window size through WindowsAPI `SetWindowPos` I believe it's called. This could overcome the minimum size limit, if its in the framework. Also a tip - don't try to make it transparent. Your case sounds far from easy to accomplish as a transparent form in WinForms. – SimpleVar May 09 '15 at 22:16
  • Do consider a ToolTip instead. You can fix it by putting `this.Bounds = label1.DisplayRectangle;` in the Load event handler. – Hans Passant May 10 '15 at 14:06
  • Remember to pick an accepted answer – Phiter Dec 25 '15 at 03:34

3 Answers3

2

What you need to use is Region property. Assuming you

  • have a form
  • have a label on the form
  • set FormBorderStyle ==> None (this is important, otherwise you'll have to take form's non-client area into account - header, etc.) and ShowInTaskBar ==> false

    private void Form4_Load(object sender, EventArgs e)
    {
        Region = new Region(label1.Bounds);
    }
    
Mike Makarov
  • 1,287
  • 8
  • 17
0

This is what you will get if you follow my tutorial:

Result

Alright, i believe i understand what you want.

Do as it follows:

First, create a form with FormBorderStyle = none, then you go to the last property of the form and set a transparency key, i'd recommend lime, because green is a really strong color.

Once you have your transparency key, you gotta change the form background color to the same as your transparency key.

If you run your code you will notice it will be only your label, but you can't move it... yet.

The code for moving it around is taken from here:

private bool _dragging = false;
private Point _offset;
private Point _start_point = new Point(0, 0);

private void panel1_MouseDown(object sender, MouseEventArgs e)
{
    _dragging = true;  // _dragging is your variable flag
    _start_point = new Point(e.X, e.Y);
}

private void panel1_MouseUp(object sender, MouseEventArgs e)
{
    _dragging = false;
}

private void panel1_MouseMove(object sender, MouseEventArgs e)
{
    if (_dragging)
    {
        Point p = PointToScreen(e.Location);
        Location = new Point(p.X - this._start_point.X, p.Y - this._start_point.Y);
    }
}

Add this to your form code, then set the right actions to your LABEL. On your label MouseDown should be panel1_MouseDown, etc, etc. If you did everything right, you should have a floating movable text by now! :)

Community
  • 1
  • 1
Phiter
  • 14,570
  • 14
  • 50
  • 84
0

I have an easy way to do it:

  1. Check out "TransparencyKey" in the properties of Form
  2. Set the color of transparency the color of your form background color.
  3. Change "FormBorderStyle" to none.
  4. Add a Label to your project and write something.
    http://s1.freeupload.ir/i/00082/vmi50rd5w8nd.jpg
  5. Test your project it should be like this:

http://s1.freeupload.ir/i/00082/oy06dqx4wuxx.jpg

I hope this helped you!

Pouya
  • 182
  • 1
  • 6