I am trying below code but it is not working . Please help me I am new in c#.net
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Rectangle BoundRect;
Rectangle OldRect = Rectangle.Empty;
private void EnableMouse()
{
Cursor.Clip = OldRect;
Cursor.Show();
Application.RemoveMessageFilter((IMessageFilter)this);
}
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == 0x201 || m.Msg == 0x202 || m.Msg == 0x203) return true;
if (m.Msg == 0x204 || m.Msg == 0x205 || m.Msg == 0x206) return true;
return false;
}
private void DisableMouse()
{
OldRect = Cursor.Clip;
// Arbitrary location.
BoundRect = new Rectangle(530, 530, 200, 200);
Cursor.Clip = BoundRect;
Cursor.Hide();
Application.AddMessageFilter((IMessageFilter)this);
}
}


Md SarfarajRank #194 · 12.4K reputationPosted Sep 16, 2021, 9:14 AM EDT
Rajesh KumbharRank #6,801 · 256 reputationPosted Sep 17, 2021, 6:49 AM EDT
thanks sir but it is not fullfill requirment . Even though not working code.
Requirment : user can click inside form but disable mouse action outside window form whaile running form