Windowsform : hideframe with transparency

Hi,

I've made a form with a label which is transparent.

I've also got a contextmenustrip with an item that makes it possible to hide the formframe :

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

When I execute this code, the frame hides, but the complete forms moves up the height of the frame (I can live with this), but also the background (which is transparent) moves up (without repainting).

I don't know if this explains the problem enough, so I will give an example.

Let's say you move the form to a place where the top of the transparent area is the beginnen of a color area in the background (let's say red) and the area above is green. when I rightclick to get my contextmenustrip and I select "hide frame" then the frame goes away, but the transparent area (and the rest on the form) moves up and the background that was red is still red where it should be green.

I tried this.Refresh() and this.Update(), but things don't get fixed :$

I even tried to move the form (this.Left+=100 and then this.Left-=100) but this also doesn't fix the problem.

Is there another way to get the background correct



Answer this question

Windowsform : hideframe with transparency

  • Gimosyan Azat

    Code sample (to use as a test) :

    private void Form1_Load(object sender, EventArgs e)

    {

    this.TransparencyKey = Color.Blue;

    Panel myTransparentPanel = new Panel();

    this.Controls.Add(myTransparentPanel);

    myTransparentPanel.Dock = DockStyle.Fill;

    Button myHideFrameButton = new Button();

    myTransparentPanel.BackColor = Color.Blue;

    myTransparentPanel.Top = 10;

    myTransparentPanel.Left = 10;

    myHideFrameButton.Width = 100;

    myHideFrameButton.Height = 50;

    myHideFrameButton.BackColor = Color.Red;

    myHideFrameButton.Text = "Hide frame";

    myTransparentPanel.Controls.Add(myHideFrameButton);

    myHideFrameButton.Click += new EventHandler(myHideFrameButton_Click);

    }

    void myHideFrameButton_Click(object sender, EventArgs e)

    {

    this.FormBorderStyle = FormBorderStyle.None;

    //throw new Exception("The method or operation is not implemented.");

    }

    When you execute the code and place the top of the button on the bottom of an other underlying frameborder and you press the button you will see that the underlying frameborder gets interrupted. That isn't supposed to happen.


  • Doug B

    still the same problem :$

    The background of the transparent area is still not what it should be.


  • jkc

    Makes sense but why does the "background" gets repainted when you make the panel transparent It's "my form" that does that, so why can't it do the same when I "remove" the border
  • cbroussard

    yup still not working but as you see not your form needs repainting !


  • TheBum

    void myHideFrameButton_Click(object sender, EventArgs e)

    {

    int x=this.Location.X;

    int y=this.Location.Y;

    this.FormBorderStyle = FormBorderStyle.None;

    this.Location=new Point(x,y);

    }


    this should work



  • Otter Sr

    here is what i discoverd That not your form needs to be repainted
    Hmm For example: if your form will be located over the VS 2005 toolstrip butons and u press that button and u will see the same efect as u said but if you got with the mouse over the Tool Strip of VS2005 you will see that VS will repaint himself and the "i dont know how to call it" will dissapre


  • bvanskiver

    hey not an expert but if u post some cod maybe i could help u
    i dont really understand what is your problem


  • Brett M

    yup u are right i understood what`s u`re problem  !
     and you`re right the refresh doesnt work

    when the button is pushed the form border dissaper
     but the form(withoud the any border) is moved where the the form was before we pressed the button was, and that si 20 pixils upper exact the form border height

    i think the refresh doesnt work because it`s nothing to paint


  • Akhil Jindal Verizon

    bottom line is, I can't fix it
  • Windowsform : hideframe with transparency