ComboBox KeyPress Event?

T

Tomer

Hi,
I need to have a KeyPress event for the combobox so I've created a new
control that inherits a combobox and overrided the keypress event

the code goes like this:

using System;
using System.Windows.Forms;
using System.Drawing;

#if NETCFDESIGNTIME
using System.ComponentModel;
#endif

#if NETCFDESIGNTIME
[assembly: System.CF.Design.RuntimeAssemblyAttribute("ExComboBox,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
#endif

namespace New.Controls
{
/// <summary>
/// ExComboBox Class
/// </summary>
public class ExComboBox : System.Windows.Forms.ComboBox
{
#region Vars
#endregion

/// <summary>
/// KeyPress event
/// </summary>
public new event KeyPressEventHandler KeyPress;

#region Constructors/Destructors
#endregion

/// <summary>
/// Constructor
/// </summary>
public ExComboBox()
{
// hookup events
this.KeyPress += new KeyPressEventHandler(this.OnKeyPress);
}

#region Functions
#endregion

#region Events
#endregion

/// <summary>
/// ComboBox OnKeyPress Event
/// </summary>
private void OnKeyPress(object sender, KeyPressEventArgs e)
{
base.OnKeyPress(e);
}

#region Properties
#endregion
}
}

now, this doesn't do the trick! I've also tried adding [Browsable(true)]
before the event code, but i get a compilation error that I am missing an
assembly or a reference (have no idea why)

Any help would be greatly appreciated! Tomer.
 
T

Tomer

Hi,
When I add the override keyword and change the function from private to
public (compiler asks to do so), I get an error:

New.Controls.ExComboBox.OnKeyPress(object,
System.Windows.Forms.KeyPressEventArgs)': no suitable method found to
override

This could mean that the original combobox has no OnKeyPress function, I'm
not sure.
I've also tried add another KeyPressEvent of my own and I do see it in
design time, but nothing happens when I press any key when the app is
running.

Tomer.

Alex Yakhnin said:
First of all, in your code you don't override KeyPress, but just hook up
into its handler.
In order to override it you'd need to put something like that:

protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
}

Second of all, make sure that you have SP2 for CF installed...

--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Tomer said:
Hi,
I need to have a KeyPress event for the combobox so I've created a new
control that inherits a combobox and overrided the keypress event

the code goes like this:

using System;
using System.Windows.Forms;
using System.Drawing;

#if NETCFDESIGNTIME
using System.ComponentModel;
#endif

#if NETCFDESIGNTIME
[assembly: System.CF.Design.RuntimeAssemblyAttribute("ExComboBox,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
#endif

namespace New.Controls
{
/// <summary>
/// ExComboBox Class
/// </summary>
public class ExComboBox : System.Windows.Forms.ComboBox
{
#region Vars
#endregion

/// <summary>
/// KeyPress event
/// </summary>
public new event KeyPressEventHandler KeyPress;

#region Constructors/Destructors
#endregion

/// <summary>
/// Constructor
/// </summary>
public ExComboBox()
{
// hookup events
this.KeyPress += new KeyPressEventHandler(this.OnKeyPress);
}

#region Functions
#endregion

#region Events
#endregion

/// <summary>
/// ComboBox OnKeyPress Event
/// </summary>
private void OnKeyPress(object sender, KeyPressEventArgs e)
{
base.OnKeyPress(e);
}

#region Properties
#endregion
}
}

now, this doesn't do the trick! I've also tried adding [Browsable(true)]
before the event code, but i get a compilation error that I am missing an
assembly or a reference (have no idea why)

Any help would be greatly appreciated! Tomer.
 
A

Alex Yakhnin, MVP

Here is the code that works for me:

public class MyComboBox : ComboBox
{
public MyComboBox()
{
//
// TODO: Add constructor logic here
//
}

protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
}

}

--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Tomer said:
Hi,
When I add the override keyword and change the function from private to
public (compiler asks to do so), I get an error:

New.Controls.ExComboBox.OnKeyPress(object,
System.Windows.Forms.KeyPressEventArgs)': no suitable method found to
override

This could mean that the original combobox has no OnKeyPress function, I'm
not sure.
I've also tried add another KeyPressEvent of my own and I do see it in
design time, but nothing happens when I press any key when the app is
running.

Tomer.

Alex Yakhnin said:
First of all, in your code you don't override KeyPress, but just hook up
into its handler.
In order to override it you'd need to put something like that:

protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
}

Second of all, make sure that you have SP2 for CF installed...

--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Tomer said:
Hi,
I need to have a KeyPress event for the combobox so I've created a new
control that inherits a combobox and overrided the keypress event

the code goes like this:

using System;
using System.Windows.Forms;
using System.Drawing;

#if NETCFDESIGNTIME
using System.ComponentModel;
#endif

#if NETCFDESIGNTIME
[assembly: System.CF.Design.RuntimeAssemblyAttribute("ExComboBox,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
#endif

namespace New.Controls
{
/// <summary>
/// ExComboBox Class
/// </summary>
public class ExComboBox : System.Windows.Forms.ComboBox
{
#region Vars
#endregion

/// <summary>
/// KeyPress event
/// </summary>
public new event KeyPressEventHandler KeyPress;

#region Constructors/Destructors
#endregion

/// <summary>
/// Constructor
/// </summary>
public ExComboBox()
{
// hookup events
this.KeyPress += new KeyPressEventHandler(this.OnKeyPress);
}

#region Functions
#endregion

#region Events
#endregion

/// <summary>
/// ComboBox OnKeyPress Event
/// </summary>
private void OnKeyPress(object sender, KeyPressEventArgs e)
{
base.OnKeyPress(e);
}

#region Properties
#endregion
}
}

now, this doesn't do the trick! I've also tried adding [Browsable(true)]
before the event code, but i get a compilation error that I am missing an
assembly or a reference (have no idea why)

Any help would be greatly appreciated! Tomer.
 
T

Tomer

The code compiles but I still don't see the KeyPress event on the designer.
Perhaps it's just a matter of letting the compiler/designer know that the
event is visible (browsable?)


Alex Yakhnin said:
Here is the code that works for me:

public class MyComboBox : ComboBox
{
public MyComboBox()
{
//
// TODO: Add constructor logic here
//
}

protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
}

}

--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Tomer said:
Hi,
When I add the override keyword and change the function from private to
public (compiler asks to do so), I get an error:

New.Controls.ExComboBox.OnKeyPress(object,
System.Windows.Forms.KeyPressEventArgs)': no suitable method found to
override

This could mean that the original combobox has no OnKeyPress function, I'm
not sure.
I've also tried add another KeyPressEvent of my own and I do see it in
design time, but nothing happens when I press any key when the app is
running.

Tomer.

Alex Yakhnin said:
First of all, in your code you don't override KeyPress, but just hook up
into its handler.
In order to override it you'd need to put something like that:

protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
}

Second of all, make sure that you have SP2 for CF installed...

--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Hi,
I need to have a KeyPress event for the combobox so I've created a new
control that inherits a combobox and overrided the keypress event

the code goes like this:

using System;
using System.Windows.Forms;
using System.Drawing;

#if NETCFDESIGNTIME
using System.ComponentModel;
#endif

#if NETCFDESIGNTIME
[assembly: System.CF.Design.RuntimeAssemblyAttribute("ExComboBox,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
#endif

namespace New.Controls
{
/// <summary>
/// ExComboBox Class
/// </summary>
public class ExComboBox : System.Windows.Forms.ComboBox
{
#region Vars
#endregion

/// <summary>
/// KeyPress event
/// </summary>
public new event KeyPressEventHandler KeyPress;

#region Constructors/Destructors
#endregion

/// <summary>
/// Constructor
/// </summary>
public ExComboBox()
{
// hookup events
this.KeyPress += new KeyPressEventHandler(this.OnKeyPress);
}

#region Functions
#endregion

#region Events
#endregion

/// <summary>
/// ComboBox OnKeyPress Event
/// </summary>
private void OnKeyPress(object sender, KeyPressEventArgs e)
{
base.OnKeyPress(e);
}

#region Properties
#endregion
}
}

now, this doesn't do the trick! I've also tried adding [Browsable(true)]
before the event code, but i get a compilation error that I am
missing
an
assembly or a reference (have no idea why)

Any help would be greatly appreciated! Tomer.
 
A

Alex Yakhnin, MVP

Since the Key events have been added to most of the controls only in SP2, I
suspect they still carry a non browsable attribute or something...

--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Tomer said:
The code compiles but I still don't see the KeyPress event on the designer.
Perhaps it's just a matter of letting the compiler/designer know that the
event is visible (browsable?)


Alex Yakhnin said:
Here is the code that works for me:

public class MyComboBox : ComboBox
{
public MyComboBox()
{
//
// TODO: Add constructor logic here
//
}

protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
}

}
hook
up
into its handler.
In order to override it you'd need to put something like that:

protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
}

Second of all, make sure that you have SP2 for CF installed...

--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Hi,
I need to have a KeyPress event for the combobox so I've created a new
control that inherits a combobox and overrided the keypress event

the code goes like this:

using System;
using System.Windows.Forms;
using System.Drawing;

#if NETCFDESIGNTIME
using System.ComponentModel;
#endif

#if NETCFDESIGNTIME
[assembly: System.CF.Design.RuntimeAssemblyAttribute("ExComboBox,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
#endif

namespace New.Controls
{
/// <summary>
/// ExComboBox Class
/// </summary>
public class ExComboBox : System.Windows.Forms.ComboBox
{
#region Vars
#endregion

/// <summary>
/// KeyPress event
/// </summary>
public new event KeyPressEventHandler KeyPress;

#region Constructors/Destructors
#endregion

/// <summary>
/// Constructor
/// </summary>
public ExComboBox()
{
// hookup events
this.KeyPress += new KeyPressEventHandler(this.OnKeyPress);
}

#region Functions
#endregion

#region Events
#endregion

/// <summary>
/// ComboBox OnKeyPress Event
/// </summary>
private void OnKeyPress(object sender, KeyPressEventArgs e)
{
base.OnKeyPress(e);
}

#region Properties
#endregion
}
}

now, this doesn't do the trick! I've also tried adding [Browsable(true)]
before the event code, but i get a compilation error that I am missing
an
assembly or a reference (have no idea why)

Any help would be greatly appreciated! Tomer.
 
T

Tomer

So the question is how do we change the attribute, but i don't think that it
depends on the SP because the problem is in the IDE, and not in runtime.

Tomer.


Alex Yakhnin said:
Since the Key events have been added to most of the controls only in SP2, I
suspect they still carry a non browsable attribute or something...

--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Tomer said:
The code compiles but I still don't see the KeyPress event on the designer.
Perhaps it's just a matter of letting the compiler/designer know that the
event is visible (browsable?)


Alex Yakhnin said:
Here is the code that works for me:

public class MyComboBox : ComboBox
{
public MyComboBox()
{
//
// TODO: Add constructor logic here
//
}

protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
}

}

--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Hi,
When I add the override keyword and change the function from private to
public (compiler asks to do so), I get an error:

New.Controls.ExComboBox.OnKeyPress(object,
System.Windows.Forms.KeyPressEventArgs)': no suitable method found to
override

This could mean that the original combobox has no OnKeyPress
function,
I'm
not sure.
I've also tried add another KeyPressEvent of my own and I do see it in
design time, but nothing happens when I press any key when the app is
running.

Tomer.

First of all, in your code you don't override KeyPress, but just
hook
up
into its handler.
In order to override it you'd need to put something like that:

protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
}

Second of all, make sure that you have SP2 for CF installed...

--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Hi,
I need to have a KeyPress event for the combobox so I've created
a
new
control that inherits a combobox and overrided the keypress event

the code goes like this:

using System;
using System.Windows.Forms;
using System.Drawing;

#if NETCFDESIGNTIME
using System.ComponentModel;
#endif

#if NETCFDESIGNTIME
[assembly: System.CF.Design.RuntimeAssemblyAttribute("ExComboBox,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
#endif

namespace New.Controls
{
/// <summary>
/// ExComboBox Class
/// </summary>
public class ExComboBox : System.Windows.Forms.ComboBox
{
#region Vars
#endregion

/// <summary>
/// KeyPress event
/// </summary>
public new event KeyPressEventHandler KeyPress;

#region Constructors/Destructors
#endregion

/// <summary>
/// Constructor
/// </summary>
public ExComboBox()
{
// hookup events
this.KeyPress += new KeyPressEventHandler(this.OnKeyPress);
}

#region Functions
#endregion

#region Events
#endregion

/// <summary>
/// ComboBox OnKeyPress Event
/// </summary>
private void OnKeyPress(object sender, KeyPressEventArgs e)
{
base.OnKeyPress(e);
}

#region Properties
#endregion
}
}

now, this doesn't do the trick! I've also tried adding
[Browsable(true)]
before the event code, but i get a compilation error that I am missing
an
assembly or a reference (have no idea why)

Any help would be greatly appreciated! Tomer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top