0

I have a project where I need to do a layers of Containers.

Container must have something like:

Form.Opacity = 0;

User can see elements under top layer, but can't use them.

I saw many examples with transparent backgrounds, but in my way I'll need to move elements on this Container. Better what I found:

class xPanel : Panel
{
  public xPanel()
  {
    SetStyle(ControlStyles.Opaque, true);
  }

  protected override CreateParams CreateParams
  {
    get
    {
      CreateParams createParams = base.CreateParams;
      createParams.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT
      return createParams;
    }
  }

  protected override void OnPaint(PaintEventArgs e)
  {
    //PaintParentBackground(e);
    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0, Color.White)),
        0, 0, Width, Height);
  }

  public void InvalidateEx()
  {
    if (Parent == null)
      return;
    Rectangle rc = new Rectangle(this.Location, this.Size);
    Parent.Invalidate(rc, true);
  }
}

But there are trails while drag elements, or blinking on redrawing.

I don't know how to solve this problem. Have ideas?

I use InvalidateEx(), in:

protected override void OnLocationChanged(EventArgs e)
{
  if (Parent != null)
    ((xPanel)Parent).InvalidateEx();
}
LarsTech
  • 80,625
  • 14
  • 153
  • 225
justAuser
  • 60
  • 1
  • 11

2 Answers2

0

Try to add

protected override OnPaintBackground(...)
{
    //base.OnPaintBackground(...);
}

So do not repaint a background, should, at least, remove blinking.

Hope this helps.

Tigran
  • 61,654
  • 8
  • 86
  • 123
  • Sorry, it is blinking, but works faster. I use InvalidateEx(), in: private void element_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { ((DrawElement)sender).Left += e.X - SL.X + SP.X; ((DrawElement)sender).Top += e.Y - SL.Y + SP.Y; ((xPanel)Parent).InvalidateEx(); } } Sorry, I don't know how to write code here =) – justAuser Jan 17 '12 at 08:33
  • @justAuser: did you enable double buffering ? – Tigran Jan 17 '12 at 09:05
  • Yes, it works good, but still blinking. And I have with this redrawing one more problem: all elements draws under background layer... Screenshots: (http://clip2net.com/s/1uDZY) funny bug: (http://clip2net.com/s/1uE5n) I need some more update after mouse up? What is a better update for this? – justAuser Jan 17 '12 at 09:26
0

If you make the BackColor and TransparancyKey properties of the panel same , the panel will be transparent. But try to select a color that is not commonly used.

Ozgur Dogus
  • 911
  • 3
  • 14
  • 38
  • With TransparancyKey I will see background of my computer... I need to see back elements... And user can choose one of day this color (and it will be like a bug) – justAuser Jan 17 '12 at 08:22