Overriding Mouse Down...

W

William Ryan

I have an app that uses the VoiceRecorder control (C#) but I have my own
buttons and just make the calls behind the scenese so that it looks better
and is easier for users to access the buttons.

Here's the problem, if I show the recorder modally, then the user actually
has to click on it and I don't want them to physically use the control or
even see it. If I don't show it modally, then eveyrhting works fine, but if
the user taps anywhere on the form, the VoiceRecorder ends recording.

I've tried overriding MouseDown
protected override void OnMouseDown(MouseEventArgs e) ... but there's not
way to indicate 'handled' that I can tell with MouseEventArgs. So I'm stuck
b/c I don't want the user to have to use the actual control, but if they
don't , then it looks like anytime they tap anywhere (on any of the buttons
or on the form) recording stops. This won't work either.

Any ideas?

Thanks,

Bill
 
M

MichaelLipp[MS]

Not sure how your app works, but keep in mind not all controls support all
inherited events and properties.

It sounds like you should derive a custom control from the Control class
which supports all mouse/keyboard events. If you want to override an
event, just make sure you don't call the base class (which would do the
default functionality).




using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;

namespace test
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;

public Form1()
{
InitializeComponent();

myControl x = new myControl();
x.Parent = this;
x.Bounds = new Rectangle(10, 10, 200, 40);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
//
// Form1
//
this.Menu = this.mainMenu1;
this.Text = "Form1";

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>

static void Main()
{
Application.Run(new Form1());
}
}


public class myControl : Control
{
public myControl()
{
this.BackColor = Color.Green;
}

protected override void OnGotFocus(EventArgs e)
{
this.BackColor = Color.Red;
base.OnGotFocus (e);
}

protected override void OnMouseDown(MouseEventArgs e)
{
// don't call the base class so you can eat all the MouseDown
events...
// base.OnMouseDown (e);
}
}
}




NETCF Beta FAQ's -- http://www.gotdotnet.com/team/netcf/FAQ.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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