How do I beep the computer’s speaker in a Windows Form application
There is no Windows Form function to beep your computer’s speaker. But you can just invoke the Win32 API MessageBeep. using System.Runtime.InteropServices; … [DllImport(‘user32.dll’)] public static extern int MessageBeep(uint n); private void button2_Click(object sender, System.EventArgs e) { MessageBeep(0x0); } Another method (suggested by [email protected] on microsoft.public.dotnet.framework.windowsforms) Reference the VB.NET runtime support and just use the Beep() method. The method is in: Microsoft.Visual Basic.NET Runtime The method is: Microsoft.VisualBasic.Interaction.Beep();
How do I make the arrow keys be accepted by a control (such as a button) and not handled automatically by the framework’s focus management
By default, the arrow keys are not handled by a control’s key processing code, but instead are filtered out for focus management. Hence, the control’s KeyDown, KeyUp and KeyPressed events are not hit when you press an arrow. If you want your control to handle these keyboard events, you tell the framework by overriding your control’s IsInputKey method. protected override bool IsInputKey(Keys key) { switch(key) { case Keys.Up: case Keys.Down: case Keys.Right: case Keys.Left: return true; } return base.IsInputKey(key); }
How can I get a string that contains RTF format codes into a RichTextBox
Use the Rtf property of the control. richTextBox1.Rtf = @'{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}\viewkind4\uc1\pard\b\i\f0\fs20 This is bold italics.\par }’;
How can I capture output from an arbitrary console application from within my Window Form application
Use the Process class found in the System.Diagnostic namespace. Process proc = new Process(); // test.exe is a console application generated by VC6 proc.StartInfo.FileName = @’C:\test\test.exe’; proc.StartInfo.Arguments = ”; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); string output = proc.StandardOutput.ReadToEnd(); //output now holds what text.exe would have displayed to the console
How do I create and use a component
Take a look at Mahash Chand’s Creating C# Class Library (Dll) found on C# Corner.