console-application

Changing Console Window's size throws ArgumentOutOfRangeException

邮差的信 提交于 2019-12-19 05:04:18
问题 I am trying to set the size of the Console Window in a c# console application. I get an ArgumentOutOfRangeException with this message: The value must be less than the console's current maximum window size of 41 in that dimension. Note that this value depends on screen resolution and the console font. I am using this to set it: Console.WindowHeight = 480; How do you set the Console window's size properly? 回答1: From MSDN of Console.WindowHeight property: The height of the console window

Playing sounds on Console - C#

别等时光非礼了梦想. 提交于 2019-12-19 04:09:47
问题 I'm writing a Console application on C# and I want to play a sound when I display texts continuously. This is what I've done : static SoundPlayer typewriter = new SoundPlayer("typewriter"); static public void print(string str, int delay) { Thread skipThread = new Thread(skipText); typewriter.PlayLooping(); textgap = delay; foreach (char c in str) { Console.Write(c); if (textgap != 0) Thread.Sleep(textgap); } typewriter.Stop(); } typewriter.wav is imported to my project next to the .cs files

Reducing console size

南楼画角 提交于 2019-12-19 04:08:12
问题 I got a problem with changing console size. This is my code: BOOL setConsole(int x, int y) { hStdin = GetStdHandle(STD_INPUT_HANDLE); hStdout = GetStdHandle(STD_OUTPUT_HANDLE); if (hStdin == INVALID_HANDLE_VALUE || hStdout == INVALID_HANDLE_VALUE) { MessageBox(NULL, TEXT("GetStdHandle"), TEXT("Console Error"), MB_OK); return false; } SMALL_RECT windowSize = {0, 0, x-1, y-1}; // Change the console window size: SetConsoleWindowInfo(hStdout, TRUE, &windowSize); COORD c = { x, y}; //Change the

Error 1 Cannot apply indexing with [] to an expression of type 'int'

一曲冷凌霜 提交于 2019-12-19 03:59:19
问题 I am using Microsoft Visual Studio 2010 and C#. This is a function that is being called form elsewhere in my console program, but I can't seem to get input into the array ipoints . static void GetPoints(int ipoints, string srestaurant) { int index = 0; int iinput; for (index = 0; index < 5; index++) { Console.Write("please enter how many points " + srestaurant[index] + " got : "); iinput = Convert.ToInt32(Console.ReadLine()); while (iinput < 0 && iinput > 20) { Console.Write("please enter how

Centering text in C# console app only working with some input

旧巷老猫 提交于 2019-12-19 02:49:14
问题 I am having a problem with centering text in a C#.NET4 console app. This is my method for centering the text: private static void centerText(String text) { int winWidth = (Console.WindowWidth / 2); Console.WriteLine(String.Format("{0,"+winWidth+"}", text)); } However, I just get the output as it would have been outputted normally. If I however use this line: Console.WriteLine(String.Format("{0,"+winWidth+"}", "text")); The "text" gets centered as it should. I am calling centerText with these

WebBrowser Control - Console Application - Events Not Firing

岁酱吖の 提交于 2019-12-18 18:30:23
问题 I have been navigating the various WebBrowser control stackoverflow questions, and I can't seem to find an answer to a problem I am having. I am trying to use the WebBrowser control to print a web page. Following MSDN's example, I have created the following console application: namespace WebPrintingMadness { using System; using System.Collections.Generic; using System.Text; /// <summary> /// The entry point of the program. /// </summary> class Program { /// <summary> /// The main entry point

Get key from any process

折月煮酒 提交于 2019-12-18 17:56:11
问题 Ive seen many solutions online but none does exactly what I want. What is the best/simplest way to get any keys pressed in a given process (not my console applicaton) while my application is running in background. I dont need the modifiers or anything. 回答1: If you don't particularly care which process the keys are being pressed in the easiest method would be to call GetAsyncKeyState. It's rather limited though as it does not hook the keyboard and requires you to call it continuously. The best

Why is Console.Readline not executing as expected

白昼怎懂夜的黑 提交于 2019-12-18 17:32:25
问题 I have the following code below to work with. The problem I have here is that the code runs through the while loop without waiting for input on the line String temp = Console.ReadLine() . Need help understanding why and how to fix please. Thanks in advance! /*Banker's algorithm Implementation*/ class Program { static void Main(string[] args) { int n = 0;//number of resources we will be dealing with int proc_num = 0;//Total number of processes to share available resources IDictionary<String,

Is it possible to send Toast notification from console application?

落爺英雄遲暮 提交于 2019-12-18 12:23:27
问题 Is it possible to send Toast notifications from console application using ToastNotificationManager ? I know that it is possible to send Toast notifications from Windows Universal app: var toast = new ToastNotification(doc); ToastNotificationManager.CreateToastNotifier().Show(toast); *doc - Toast stored in XML string To use ToastNotificaionManager I need Windows.UI.Notifications library which I can't reference in console application project. The library I mentionet before is actualy used by

Impersonate with username and password?

只愿长相守 提交于 2019-12-18 10:56:08
问题 WindowsIdentity identity = new WindowsIdentity(accessToken); WindowsImpersonationContext context = identity.Impersonate(); ... context.Undo(); Where do i declare a administraotr UserName and Passowrd ? the accessToken param doesn't help me too much... Do I have to import DLL'S for it ? 回答1: You need to get the user's token. Use the p/invoke LogonUser from the advapi32.dll: [DllImport("advapi32.dll", SetLastError = true)] public static extern bool LogonUser( string lpszUsername, string