This is my current code, it works but it restarts the Explorer process and that's kinda weird.
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Win32;
namespace MyApp
{
class Program
{
static async Task Main(string[] args)
{
ShowSmallTaskbarIcons();
// ShowLargeTaskbarIcons();
Console.WriteLine("Press a key to exit...");
Console.ReadKey();
}
static void ShowSmallTaskbarIcons()
{
Registry.SetValue(#"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarSmallIcons", "1", RegistryValueKind.DWord);
RefreshExplorer();
}
static void ShowLargeTaskbarIcons()
{
var key = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", writable: true);
key.DeleteValue("TaskbarSmallIcons", throwOnMissingValue: false);
key.Close();
RefreshExplorer();
}
static void RefreshExplorer()
{
Process.Start("taskkill.exe", "/f /im explorer.exe");
Thread.Sleep(2000);
Process.Start("explorer.exe");
Thread.Sleep(10000);
}
}
}
I would like to do the same as with the "Use small taskbar buttons" toggle switch from Settings.
How to do the same with C#?
How to change Windows 10 taskbar icon size programmatically
This post has an example about how to send WM_SETTINGCHANGE message in c++.
However, there is no easy way to do it in c# wrapped function. You have to do it through p/invoke
Following post will help you do it in c#
convert C++ code to C#: SendMessageTimeout()
Related
I'm trying to make a bot that uses OCR and I'm having issues trying to get a hotkey library I found to work.
It uses the ModifierKeys enum as an argument in one of it's functions but apparently 'ModifierKeys doesn't exist'.
I am using System.Windows.Input which should have ModifierKeys in it and I have double checked that I have System.Windows referenced in my project (although that should be pretty obvious since I get no error to do with using System.Windows.Input, I guess)
Here's my current code (error is happening at var key):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using mrousavy;
using System.Windows.Input;
using OCRBot.Handlers;
namespace OCRBot
{
class Program
{
static OCRHandler oCRHandler = new OCRHandler();
static void Main(string[] args)
{
Console.Write("!!");
#if DEBUG
Console.WriteLine("\nPress enter to close...");
Console.ReadLine();
#endif
var key = new HotKey(
(ModifierKeys.Control | ModifierKeys.Alt),
Key.S,
this,
delegate {
MessageBox.Show("Ctrl + Alt + S was pressed!");
}
);
while (true)
{
MainLoop();
}
}
static void MainLoop()
{
oCRHandler.ReadWindow();
}
}
}
The Reference you want is WindowsBase to get ModifierKeys, not System.Windows.
Hello im trying to learn C# step by step. I installed Visual Studio to practice but 20 mins in I cant test my basic code when executing:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.Write("What is your name?");
string name = Console.ReadLine();
Console.WriteLine("My name is " + name);
}
}
}
It is as basic as this but when I execute and type a name and press enter, the cmd just closes. any help would be appreciated because i am enthusiastic to start out with C#
cmd
The Main method returns after
Console.WriteLine("My name is " + name);
And this effectively terminates the app.
You should put a
Console.Read();
to wait until the next keystroke.
Add another input to close application, so cmd wont close until you press enter again.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.Write("What is your name?");
string name = Console.ReadLine();
Console.WriteLine("My name is " + name);
Console.ReadLine();
}
}
}
Try Ctrl + F5
If you don't need to debug, then Ctrl-F5 is the best option
works automatically without any Console.Readline() or ReadKey()
Visual Studio will keep the console window open, until you press a key.
I am using Pencil.Gaming as the C# Wrapper for the OpenGL functions. I wanted to write a quite application to get the OpenGL renderer and version information but I can't seem to find the Macros for these (GL_RENDERER and GL_VERSION).
Has anyone used Pencil.Gaming or another C# wrapper before and used these or similar macros? Where are they located? Or is there another way to get this information with the wrapper?
Here's the code I have so far:
using System;
using Pencil.Gaming;
using Pencil.Gaming.Graphics;
using GLubyte = System.Byte;
namespace C_Sharp_OpenGL
{
class Program
{
static void Main(string[] args)
{
if (!Glfw.Init()){
Console.WriteLine("ERROR: Could not start GLFW3");
Console.WriteLine("Press Any Key to Continue...");
Console.ReadKey();
Environment.Exit(-1);
}
GlfwWindowPtr window = Glfw.CreateWindow(640, 480, "Hello Triangle", GlfwMonitorPtr.Null, GlfwWindowPtr.Null);
Glfw.MakeContextCurrent(window);
//Get Version Info
GLubyte renderer = GL.GetString(GL_RENDERER); //Doesn't Work
Glubyte version = GL.GetString(GL_VERSION); //Doesn't Work
}
}
}
I build wcf ,and it run's on Windows Server 2008 R2.Now i updated my program , and add Scheduler(telerik).
After this my aplication is start's to crash.
Do any one know how to fix it?
Here my code that works
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication
{
static class Program
{
// public static SchedulerForm Scheduler = new SchedulerForm(); here Scheduler disabled
private static NotifyIcon trayIcon;
static void Main()
{
using (ServiceHost host = new ServiceHost(typeof(SimpleService.SimpleService)))
{
host.Open();
SysTrayApp();
Application.Run();
}
}
public static void SysTrayApp()
{
/* tmNowActions = new ContextMenu();
tmNowActions.MenuItems.Add("....
my other function (not important)
*/
// Scheduler.ShowDialog();
}
}
}
And here after i remove comments and enable scheduler
namespace WindowsFormsApplication
{
static class Program
{
public static SchedulerForm Scheduler = new SchedulerForm();
private static NotifyIcon trayIcon;
static void Main()
{
using (ServiceHost host = new ServiceHost(typeof(SimpleService.SimpleService)))
{
host.Open();
SysTrayApp();
Application.Run();
}
}
public static void SysTrayApp()
{
/* tmNowActions = new ContextMenu();
tmNowActions.MenuItems.Add("....
my other function (not important)
*/
Scheduler.ShowDialog();
}
}
}
After this my aplication is crashed
Here the image from win server 2008 R2
Do any one know how to fix it?
UPDATE
I found that i was missing some telerik dll's,after i add them i get a new error.
If i will make empty WinForm all works fine,and i will see empty form ,but if i add telerik element(Scheduler in my case),i will get this error
Here another error that says i am missing Scheduler version,but you can see the dll and properties of this dll,and it is there it is not missing.
I resolved this problem like this:
1:Clean project and delete old files from Degub/bin.
2:Make sure all telerik dll's have the same version(end's .20 or .40) !!IMPORTANT!!.
3:In Telerik dll's click properties, and then make Copy Local = true !!IMPORTANT!!.
4:Rebuild the project.
After all this steps all start to work.
I want to run the Skeinforge slicer program written in Python inside my Windows Phone 8 C# application. I have determined that I should probably use IronPython to do this, I have already determined that I can run Skeinforge inside the ipy.exe terminal I got when I installed IronPython. My problem though is that I am struggling to figure out how to host and run a Python script with IronPython inside Windows Phone 8. I have also already managed to get a simple hello world script running inside a Desktop Windows Forms application that transfers the applications console output to the Debug console with the following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DebugWriter debugW = new DebugWriter();
Console.SetOut(debugW);
}
private void button1_Click(object sender, EventArgs e)
{
TextWriter tw = new StreamWriter("Test.py");
tw.Write(scriptBox.Text);
tw.Close();
try
{
var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile("Test.py");
}
catch (Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
}
}
}
}
And this is the DebugWriter:
class DebugWriter : TextWriter
{
private StringBuilder content = new StringBuilder();
public DebugWriter()
{
Debug.WriteLine("Writing console to debug");
}
public override void Write(char value)
{
base.Write(value);
if (value == '\n')
{
Debug.WriteLine(content.ToString());
content = new StringBuilder();
}
else
{
content.Append(value);
}
}
public override Encoding Encoding
{
get { return System.Text.Encoding.UTF8; }
}
}
I have no idea how to even add the IronPython libraries to my Windows Phone 8 application though as the standard libraries won't import. I have though tried compiling the apparently now defunct Windows Phone 7 libraries with the master source code and I can import these libraries, but I get absolutely no response on the debug terminal when I try to run my hello world script.
Do any of you have any idea how to get this woring in Windows Phone 8, if you know how to do this in Windows 8/Metro/RT then that would also probably work for WP8.
UPDATE:
I have looked at the debug output again and I seem to get this error when trying to use the WP7 libraries to run a hello world script:
A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.Scripting.DLL
Error: The method or operation is not implemented.
I managed to get Skeinforge running on a modified version of IPY. You can get the source for my application here: http://skeinforgewp8.codeplex.com/