Kéo vào Form con 1 Time Control sau đó khai báo các biến, hàm tạo và sự kiên Form Load như sau:
- private int _parentTop;
- private int _parentLeft;
- private int _parentWidth;
- private int _parentHeight;
- public FrConnection(int parentTop, int parentLeft, int parentWidth, int parrentHeight)
- {
- _parentTop = parentTop;
- _parentLeft = parentLeft;
- _parentWidth = parentWidth;
- _parentHeight = parrentHeight;
- InitializeComponent();
- }
- private void FrConnection_Load(object sender, EventArgs e)
- {
- Left = _parentLeft - 50;// vị trí khởi tạo của Form
- Top = ((_parentTop + _parentHeight / 2)) - (Height / 2);
- timer.Start();
- }
- private void timer_Tick(object sender, EventArgs e)
- {
- Left += 50;// tốc độ trượt của Form
- if (Left >= ((_parentLeft + _parentWidth / 2) - Width / 2))
- {
- Left = ((_parentLeft + _parentWidth / 2)) - (Width / 2);
- Top = ((_parentTop + _parentHeight / 2)) - (Height / 2);
- timer.Stop();
- }
- }
- private void newToolStripMenuItem_Click(object sender, EventArgs e)
- {
- FrConnection fr = new FrConnection(this.Top, this.Left, this.Width, this.Height);
- fr.ShowDialog();
- }
Sau đó Form sẽ trượt ra chính giữa:
Có thể tùy chỉnh quãng đường Form sẽ trượt tại sự kiện Form Load và tốc độ trượt của Form tại sự kiện time_Tick.
Nhận xét này đã bị quản trị viên blog xóa.
Trả lờiXóavới thể loại như bạn mình xin phép xóa comment nhé ^^!
Xóa