Mobile button in Windows form
I need to move a button inside the form, where ever I over mouse pointer on the form? can you please suggest any solution
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Selva GanapathyRank #560 · 4.3K reputationPosted Sep 24, 2014, 4:15 AM EDT
Hi Jegan Priya,
You can achieve your requirement by following code
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Timer timer = new Timer();
timer.Interval = 10;
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
this.button1.Left = Cursor.Position.X - this.Left - this.button1 .Width /2;
this.button1.Top = Cursor.Position.Y - this.Top - 20 - this.button1.Height /2;
}
}
Regards,
Selva Ganapathy K
nathaJegamoorty Pillai84 reputationPosted Sep 24, 2014, 4:17 AM EDT