开发者

Effect To Show Panel in C#.net

I Want Use a Panel in a Windows Form in C#.net. I Set Visible Property of this C开发者_开发百科ontrol 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


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;
    }
  }


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

  • WPF Animation overview
  • Walkthroughs: Create a Custom Animated Button
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜