C# Textbox and AutoCompleteMode Conflicts with KeyPress.

Filed Under (Code) by Mystalia on 11-07-2008

Tagged Under : , , , , ,

Ok, personally I was using a textbox and when you pressed “Enter” it would complete a task, BUT I also wanted the textbox to be autocompletive (if that’s a valid term).

When I actually went to test it all out I found that instead of running the Keypress event, it just highlighted the text and did nothing else… Googled to find there is no valid reason why, but there is a work around, and it’s simple.

Abandon KeyPress and use the KeyDown function, setup your keydown event correctly, and it will work.

    private void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Enter)
    }

Suppress WMP ActiveX Error “Bad Image” in C#

Filed Under (Code) by Mystalia on 26-05-2008

Tagged Under : , , , , ,

For some reason, the Visual Studio debugger suppresses this automatically, but the release does not.
It has something to do with DRM signatures, anyway the fix is to open up the entry point in the application (program.cs) and make these changes…

using System;
using System.Collections.Generic;
using System.Windows.Forms;
<span style="color: #ff0000;"> using System.Runtime.InteropServices;</span>

namespace Program
{
[Flags]
public enum ErrorModes : uint
{
SYSTEM_DEFAULT = 0×0,
SEM_FAILCRITICALERRORS = 0×0001,
SEM_NOALIGNMENTFAULTEXCEPT = 0×0004,
SEM_NOGPFAULTERRORBOX = 0×0002,
SEM_NOOPENFILEERRORBOX = 0×8000
}

static class Program
{
// Suppresses “Bad Image” error.
[DllImport("kernel32.dll")]
static extern ErrorModes SetErrorMode(ErrorModes uMode);
[DllImport("kernel32.dll")]
static extern ErrorModes GetErrorMode();

///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] Args)
{
SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(Args));
}
}
}