• Web sitemizin içeriğine ve tüm hizmetlerimize erişim sağlamak için Web sitemize kayıt olmalı ya da giriş yapmalısınız. Web sitemize üye olmak tamamen ücretsizdir.

Form Kenarları Arasında Hareket Eden Buton Kontrolü

ByOnur58

Kayıtlı Üye
Forum Yaşı
11 Yıl 4 Ay
Mesajlar
2,114
Tepkime puanı
10
Kod:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DortDonenButon
{
    public partial class Form1 : Form
    {
        int xArtis = 9, yArtis = 9;
       
        Point yeniNokta;

        public Form1()
        {
            InitializeComponent();
        }

        private **** button1_Click(object sender, EventArgs e)
        {
            yeniNokta = new Point(button1.********.X,button1.********.Y);

            //butona tıklandıktan sonra buton hareket etmeye başlasın

            timer1.Start();
        }

        private **** timer1_Tick(object sender, EventArgs e)
        {
            //timer tick olayı gerçekleştiğinde buton hareket yönünde 9 birim ilerlesin
            yeniNokta.X += xArtis;

            yeniNokta.Y += yArtis;

            button1.******** = yeniNokta;

            if (button1.Left <= 0 || button1.********.X >= this.ClientSize.Width - button1.Width)
            {
                xArtis *= -1;
            }

            if (button1.Top <= 0 || button1.********.Y >= this.ClientSize.Height - button1.Height)
            {
                yArtis *= -1;
            }
        }
    }
}
 
Geri
Üst