Reputation: 646
I have been looking for resource for this issue but could not find what I want. I have a C# application in WPF which uses touch screen with mouse cursor present on the screen for users. The problem is I want to hide this mouse cursor but when I run the program in back end, the application should have mouse cursor displayed.
Does anyone have any good suggestion on where to start?
Upvotes: 3
Views: 10009
Reputation: 23675
I suggest you to use command line arguments to achieve this:
public static class Program
{
public static void Main(String[] args)
{
Boolean backend = args.Contains("-b");
// ...
MyApp app = new MyApp(backend);
app.Run();
}
}
public partial class MyApp : Application
{
public MyApp(Boolean backend)
{
InitializeComponent();
if (backend)
Cursor = Cursors.None;
}
}
To launch your app as "backend", just use the following command:
MyProgram.exe -b
and the mouse cursor will be hidden.
Upvotes: 1
Reputation: 698
It's very simple:
if(runningAsClient)
Cursor.Hide();
Of course you need a technique to determine the system you're running on, like a preprocessor directive. You can put this in your main method and set the directive in the client project configuration.
#if CLIENT
Cursor.Hide();
If you use WPF, you have to set the Cursor
property of your window to
Cursor = Cursors.None;
Upvotes: 7