What's wrong in my code?

  • Thread starter jean-dot-paul-at-opelwilly-dot-com
  • Start date
J

jean-dot-paul-at-opelwilly-dot-com

Hello,

I want to swalow all mousclicks in a comboBox control.
I created wy own 'public class roComboBox : System.Windows.Forms.ComboBox '
Created a property ReadOnly and call only the base events if the ReadOnly is
false (see code beneath) but the mousclicks still pass.

Is there such thing as in KeyPress like .Handeled = true ?

Who knows what Im doing wrong ?

Jean Paul

protected override void OnMouseDown(MouseEventArgs e)

{

if (!lokReadOnly)

{

base.OnMouseDown(e);

}

}

protected override void OnMouseUp(MouseEventArgs e)

{

if (!lokReadOnly)

{

base.OnMouseUp (e);

}

}

protected override void OnClick(EventArgs e)

{

if (!lokReadOnly)

{

base.OnClick (e);

}

}


public bool ReadOnly

{

get

{

return lokReadOnly;

}

set

{

lokReadOnly = value;

if (lokReadOnly)

{

this.BackColor = Color.Yellow;

}

else

{

this.BackColor = Color.White;

}

}

}
 
K

Kennedy Kok

I suspect that when the code reaches OnMouseDown, the default behavior of a
mouse down has already occured. In other words, it's too late. You might
have to override WndProc and catch the WM_MOUSEDOWN message there.

Kennedy
 
S

sadhu

I think Kennedy is right. I guess the ComboBox baseclass does not rely
on derived classes to call base.XXX() from overridden methods. I'd
suggest you override WndProc and handle it there.

Regards
Senthil
 
J

jean-dot-paul-at-opelwilly-dot-com

tnx Senthil and Kennedy, I begon to have those ideas to. I look for other
sollution.

Greets

Jean Paul
 

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