views:

268

answers:

2

Hi All

I Want Use a Panel in a Windows Form in C#.net. I Set Visible Property of this Control to false And When I Click on a Button, Panel is showed. I Want Show a Panel by some Effect.

Please Help me for this

+1  A: 

The only effect I can think of is to expand the panel by using a timer and change the size of the panel step-by-step.

I would recommend you to use WPF instead of Winforms that is very good at doing this kind of stuff. You can animate all properties of the control like location, size, alpha. Please, check these articles on WPF animation

gyurisc
+2  A: 

You are leaving us guessing about what kind of effect you are looking for. I'll just arbitrarily pick a collapse and expand effect. It takes a Timer, you implement the effect in a Tick event handler. Here's an example, it requires a Panel, Timer and Button:

  public partial class Form1 : Form {
    public Form1() {
      InitializeComponent();
      timer1.Interval = 16;
      timer1.Tick += new EventHandler(timer1_Tick);
      panel1.BackColor = Color.Aqua;
      mWidth = panel1.Width;

    }
    int mDir = 0;
    int mWidth;
    void timer1_Tick(object sender, EventArgs e) {
      int width = panel1.Width + mDir;
      if (width >= mWidth) {
        width = mWidth;
        timer1.Enabled = false;
      }
      else if (width < Math.Abs(mDir)) {
        width = 0;
        timer1.Enabled = false;
        panel1.Visible = false;
      }
      panel1.Width = width;
    }

    private void button1_Click(object sender, EventArgs e) {
      mDir = panel1.Visible ? -5 : 5;
      panel1.Visible = true;
      timer1.Enabled = true;
    }
  }
Hans Passant