Answer» Hello I made a file that is ment to work like cmd.exe but in a form, but I don't WANT it to show the console... is there a way to hide it?
My code:
using System; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; namespace Test { public class Forma { [DllImport("msvcrt.dll")] public static extern int system(string cmd); public void CreateMyForm() { int go = 1; while (go == 1) { Form form1 = new Form(); Button button1 = new Button (); TEXTBOX textbox1 = new TextBox (); button1.Text = "Use"; textbox1.Text = ""; textbox1.SuspendLayout(); textbox1.AcceptsReturn = true; textbox1.AcceptsTab = true; textbox1.Dock = DockStyle.Fill; button1.Location = new Point (0, 20); button1.Size = new Size(170, 23); textbox1.Location = new Point (button1.Left, button1.Height + button1.Top + 10); form1.ClientSize = new Size(170, 42); form1.Text = "Command Prompt"; form1.HelpButton = false; form1.FormBorderStyle = FormBorderStyle.FixedDialog; form1.MaximizeBox = false; form1.MinimizeBox = false; form1.CancelButton = button1; form1.StartPosition = FormStartPosition.CenterScreen; form1.Controls.Add(button1); form1.Controls.Add(textbox1); form1.ShowDialog(); system(textbox1.Text); } } public static void Main() { system("Title CMD"); Test.Forma F = new Test.Forma(); F.CreateMyForm(); } } }create it as a GUI APPLICATION, not a console application.Ok i'll try this out thank you for the help. [EDIT] Sorry I'm a noob(bit better now) at c# but how would I use GUI in this file?Fixed ok I figured it out and added some extra things If you could I would like it if you would test out this code now I made hide the console, I'm happy
I aslo put my own COMMANDS in there they are... show console, hide console, preset, reset. you can only use reset when you use preset and can't reuse preset untill you use reset!
To close the program use the show console command and press the X button on the Console!
Code:
using System; using System.IO; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; namespace Test { public class Forma { [DllImport("msvcrt.dll")] public static extern int system(string cmd); [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName,string lpWindowName); [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); public static void setConsoleWindowVisibility(bool VISIBLE, string title) { IntPtr hWnd = FindWindow(null, title); if (hWnd != IntPtr.Zero) { if (!visible) { ShowWindow(hWnd, 0); } else { ShowWindow(hWnd, 1); } } } public void CreateMyForm() { int go = 1; while (go == 1) { Form form1 = new Form(); Button button1 = new Button (); TextBox textbox1 = new TextBox (); button1.Text = "Use"; textbox1.SuspendLayout(); textbox1.AcceptsReturn = true; textbox1.AcceptsTab = true; textbox1.Dock = DockStyle.Fill; button1.Location = new Point (0, 20); button1.Size = new Size(170, 23); textbox1.Location = new Point (button1.Left, button1.Height + button1.Top + 10); form1.ClientSize = new Size(170, 42); form1.Text = "Command Prompt"; form1.HelpButton = false; form1.FormBorderStyle = FormBorderStyle.FixedDialog; form1.MaximizeBox = false; form1.MinimizeBox = false; form1.CancelButton = button1; form1.StartPosition = FormStartPosition.CenterScreen; form1.Controls.Add(button1); form1.Controls.Add(textbox1); form1.ShowDialog(); if (textbox1.Text == "show console") { setConsoleWindowVisibility(true, "CMD"); } if (textbox1.Text == "hide console") { setConsoleWindowVisibility(false, "CMD"); } if (textbox1.Text == "preset") { string NF = "PreSetting.Pre"; if (File.Exists(NF)) { StreamReader SS = new StreamReader(NF); string Seta = SS.ReadToEnd(); SS.Close(); string Preset = Forma.CreateMyFormP(Seta, NF); } else { setConsoleWindowVisibility(true, "CMD"); Console.Write("Presetting = "); string Seta = Console.ReadLine(); StreamWriter SS = new StreamWriter(NF); SS.Write(Seta); SS.Close(); setConsoleWindowVisibility(false, "CMD"); string Preset = Forma.CreateMyFormP(Seta, NF); } } system(textbox1.Text); } } public static string CreateMyFormP(string Preset, string NF) { string S = " ";
int goo = 1; while (goo == 1) { Form form1 = new Form(); Button button1 = new Button (); TextBox textbox1 = new TextBox (); button1.Text = "Use"; textbox1.Text = Preset+S; textbox1.SuspendLayout(); textbox1.AcceptsReturn = true; textbox1.AcceptsTab = true; textbox1.Dock = DockStyle.Fill; button1.Location = new Point (0, 20); button1.Size = new Size(170, 23); textbox1.Location = new Point (button1.Left, button1.Height + button1.Top + 10); form1.ClientSize = new Size(170, 42); form1.Text = "Command Prompt"; form1.HelpButton = false; form1.FormBorderStyle = FormBorderStyle.FixedDialog; form1.MaximizeBox = false; form1.MinimizeBox = false; form1.CancelButton = button1; form1.StartPosition = FormStartPosition.CenterScreen; form1.Controls.Add(button1); form1.Controls.Add(textbox1); form1.ShowDialog(); if (textbox1.Text == "show console") { setConsoleWindowVisibility(true, "CMD"); } if (textbox1.Text == "hide console") { setConsoleWindowVisibility(false, "CMD"); } if (textbox1.Text == "reset") { File.Delete(NF); Test.Forma F = new Test.Forma(); F.CreateMyForm(); } system(textbox1.Text); } return Preset+NF; } public static void Main() { system("Title CMD"); setConsoleWindowVisibility(false, "CMD"); string NF = "PreSetting.Pre"; if (File.Exists(NF)) { StreamReader SS = new StreamReader(NF); string Seta = SS.ReadToEnd(); SS.Close(); string Preset = Forma.CreateMyFormP(Seta, NF); } Test.Forma F = new Test.Forma(); F.CreateMyForm(); } } }
|