對於我的其中一個項目,我重寫了一個AXShockwaveFlash控件以禁用右鍵單擊,我可以使用以下代碼管理它;重寫.NET WebBrowsers WndProc
public class FlashPlayer : AxShockwaveFlashObjects.AxShockwaveFlash
{
private const int WM_MOUSEMOVE = 0x0200;
private const int WM_MOUSEWHEEL = 0x020A;
private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_LBUTTONUP = 0x0202;
private const int WM_LBUTTONDBLCLK = 0x0203;
private const int WM_RBUTTONDOWN = 0x0204;
private const int WM_RBUTTONUP = 0x0205;
public new event MouseEventHandler DoubleClick;
public new event MouseEventHandler MouseDown;
public new event MouseEventHandler MouseUp;
public new event MouseEventHandler MouseMove;
public FlashPlayer()
{
this.HandleCreated += FlashPlayer_HandleCreated; // listen for the HandleCreated event.
}
void FlashPlayer_HandleCreated(object sender, EventArgs e) // make required configuration changes.
{
this.AllowFullScreen = "true";
this.AllowNetworking = "all";
this.AllowScriptAccess = "always";
}
protected override void WndProc(ref Message m) // Override's the WndProc and disables Flash activex's default right-click menu and if one exists shows the attached ContextMenuStrip.
{
switch (m.Msg)
{
case WM_LBUTTONDOWN:
if (this.MouseDown != null) this.MouseDown(this, new MouseEventArgs(MouseButtons.Left, 1, Cursor.Position.X, Cursor.Position.Y, 0));
break;
case WM_LBUTTONUP:
if (this.MouseUp != null) this.MouseUp(this, new MouseEventArgs(MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0));
break;
case WM_MOUSEMOVE:
if (this.MouseMove != null) this.MouseMove(this, new MouseEventArgs(MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0));
break;
case WM_RBUTTONDOWN:
if (this.ContextMenuStrip != null) this.ContextMenuStrip.Show(Cursor.Position.X, Cursor.Position.Y);
m.Result = IntPtr.Zero; // don't allow actual flash control process the message by flagging it as processed.
return;
case WM_LBUTTONDBLCLK:
if (this.DoubleClick != null) this.DoubleClick(this, new MouseEventArgs(MouseButtons.Left, 2, Cursor.Position.X, Cursor.Position.Y, 0));
m.Result = IntPtr.Zero; // don't allow actual flash control process the message by flagging it as processed.
return;
}
base.WndProc(ref m); // when we're done with processing the events, let the message pass to others also too.
}
}
我想使用的代碼也WebBrowser控件,但在web瀏覽器的WndProc我的點擊事件沒有被捕獲的。
任何想法?
更新:我想要做的是禁止在網絡瀏覽器完全用鼠標右鍵單擊,IsWebBrowserContextMenuEnabled
並不在我的條件下工作,因爲在網絡瀏覽器中的閃光成分仍然處理正確的點擊和渲染它是自己的菜單。
另一個右鍵單擊禁用..你想實現什麼?不要限制用戶的權利做他想做的事 – abatishchev 2011-02-08 15:27:32
對不起,我不會在這裏討論UI的決定。基本上這個想法是我自己的右鍵單擊菜單,我可以爲播放的電影提供諸如無邊界形式,聊天室等功能。 – HuseyinUslu 2011-02-08 15:37:42