تسجيل الدخول

مشاهدة النسخة كاملة : Mouse events not triggered



C# Programming
09-04-2009, 07:23 PM
Hi,
I have a Form called from another Form. I've put events in both forms. The called forms mouse events aren't being triggered. The OnClosing event is triggered. Any and all help appreciated!

Please note: the events that only have a Console.Writeln in them are for debug purposes only.

Non-working code follows:

using DataObject;
using SvgNet;
using SvgNet.SvgElements;
using SvgNet.SvgTypes;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections.Generic;

namespace PiPe
{
///
/// Summary description for ImageRevealViewer.
///
public class ImageRevealViewer : Form
{
///
/// Required designer variable.
///
private Container components = null;

private SubObjectCollection items = new SubObjectCollection();
private SubObject selecteditem;
private List iRBoxes;
private ImageRevealBox imageItem;
private ImageRevealLink iRLink;
private Catalogue Catalogue;
private Panel imageBox;
private GroupBox imageDisplayer;
private Point offset = new Point();
private Point negOffset;
private UserControl parent; // the calling object
private int maximum;
private NewPToolTip toolTip = new NewPToolTip();
private SubObject imageObject;
private SubObject citem = new MailToLink();

private bool toolTipShown;
private bool parentIsCanvas;
private int originalClientHeight;
private int originalClientWidth;


///
/// To show one ImageRevealBox.
///
/// An ImageRevealLink
/// The parent catalogue we are using
/// An offset. All start and end ********s will be displaced by this offest
public ImageRevealViewer(ImageRevealLink aLink, Catalogue cat, Point os, Canvas uC)
{
InitializeComponent();
iRLink = aLink;
items.Add(iRLink);
parent = uC;
imageItem = iRLink.ImageRevealItems[0];
iRBoxes = new List(iRLink.ImageRevealItems.Count);
iRBoxes.AddRange(iRLink.ImageRevealItems);
this.Catalogue = cat;
this.StartPosition = FormStartPosition.Manual;
MaximumLength = 1;
offset = os;
negOffset = new Point(0 - offset.X, 0 - offset.Y);
parentIsCanvas = true;

drawObject(MOTION.NONE);
}

// Currently we allow only one image. We may allow more in the future
private struct MOTION
{
public const int NONE = 0;
//public const int FORWARD = 1;
//public const int BACK = 2;
}

///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.imageBox = new System.Windows.Forms.Panel();
this.imageDisplayer = new System.Windows.Forms.GroupBox();
this.imageDisplayer.SuspendLayout();
this.SuspendLayout();
//
// imageBox
//
this.imageBox.******** = new System.Drawing.Point(0, 0);
this.imageBox.Margin = new System.Windows.Forms.Padding(0);
this.imageBox.Name = "imageBox";
this.imageBox.Size = new System.Drawing.Size(800, 600);
this.imageBox.TabIndex = 1;
this.imageBox.Paint += new System.Windows.Forms.PaintEventHandler(this.imageBox_Paint);
this.imageBox.Invalidated += new System.Windows.Forms.InvalidateEventHandler(this.imageBox_Invalidated);
//
// imageDisplayer
//
this.imageDisplayer.Controls.Add(this.imageBox);
this.imageDisplayer.******** = new System.Drawing.Point(0, 0);
this.imageDisplayer.Margin = new System.Windows.Forms.Padding(0);
this.imageDisplayer.Name = "imageDisplayer";
this.imageDisplayer.Padding = new System.Windows.Forms.Padding(0);
this.imageDisplayer.Size = new System.Drawing.Size(800, 600);
this.imageDisplayer.TabIndex = 15;
this.imageDisplayer.TabStop = false;
//
// ImageRevealViewer
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.ClientSize = new System.Drawing.Size(800, 600);
this.Controls.Add(this.imageDisplayer);
this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ImageRevealViewer";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.TransparencyKey = System.Drawing.SystemColors.Control;
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ImageRevealViewer_MouseUp);
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ImageRevealViewer_MouseClick);
this.MouseCaptureChanged += new System.EventHandler(this.ImageRevealViewer_MouseCaptureChanged);
this.MouseEnter += new System.EventHandler(this.ImageRevealViewer_MouseEnter);
this.Leave += new System.EventHandler(this.ImageRevealViewer_Leave);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ImageRevealViewer_MouseDown);
this.MouseLeave += new System.EventHandler(this.ImageRevealViewer_MouseLeave);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OnClosing);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove);
this.MouseHover += new System.EventHandler(this.ImageRevealViewer_MouseHover);
this.imageDisplayer.ResumeLayout(false);
this.ResumeLayout(false);

}

void imageBox_Invalidated(object sender, InvalidateEventArgs e)
{

}

void imageBox_Paint(object sender, PaintEventArgs e)
{
Console.WriteLine("imageBox_Paint");
if (imageObject != null)
{
Graphics g = imageBox.CreateGraphics();
imageObject.Draw(g);
}
}
#endregion

// Currently we only allow one image for Image Reveal. In the future we may allow more...
private void ImageSelect(int direction)
{
//if(direction == MOTION.FORWARD) // go to next image
//{
// if(this.current != this.maximum) this.current++;

//}
//else // go to previous image
//{
// if(this.current!=0) this.current--;
//}
//current = 0;

}// end ImageSelect

///
/// This method draws a new image. This method is called by either
/// clicking up or clicking down in the slide show viewer.
///
/// This method calls ImageSelect(bool svg, bool forward).
///
///
private void drawObject(int direction)
{//begin method
imageBox.Paint -= new PaintEventHandler(imageBox_Paint);

Point newStart******** = imageItem.Start********;
newStart********.Offset(offset);

calcClientHeightWidth();

imageBox.Size = imageItem.StartSize;
this.******** = newStart********;

this.imageBox.*******();
Graphics g = this.imageBox.CreateGraphics();
SubObject so = imageItem as SubObject;

so.Draw(g);
imageObject = so;
imageBox.Paint += new PaintEventHandler(imageBox_Paint);
}// end method


private void calcClientHeightWidth()
{
int pHeight = 0;
int pWidth = 0;
int dispHeight;
int dispWidth;

originalClientHeight = imageItem.ClientHeight;
originalClientWidth = imageItem.ClientWidth;

if (parentIsCanvas)
{
pHeight = (parent as Canvas).Height;
pWidth = (parent as Canvas).Width;
}

dispHeight = imageItem.Start********.Y + pHeight;
dispWidth = imageItem.Start********.X + pWidth;

if (imageItem.ClientHeight > dispHeight &&
imageItem.ClientWidth > dispWidth)
{
Size dispSize = new Size(dispWidth, dispHeight);
imageDisplayer.Size = dispSize;
this.Size = dispSize;
imageItem.ClientHeight = dispHeight;
imageItem.ClientWidth = dispWidth;
}
else if (imageItem.ClientHeight > dispHeight)
{
Size dispSize = new Size(imageItem.ClientWidth, dispHeight);
imageDisplayer.Size = dispSize;
this.Size = dispSize;
imageItem.ClientHeight = dispHeight;
}
else if (imageItem.ClientWidth > dispWidth)
{
Size dispSize = new Size(dispWidth, imageItem.ClientHeight);
imageDisplayer.Size = dispSize;
this.Size = dispSize;
imageItem.ClientWidth = dispWidth;
}
else
{
Size dispSize = new Size(imageItem.ClientWidth, imageItem.ClientHeight);
imageDisplayer.Size = dispSize;
this.Size = dispSize;
}
}



protected override void OnMouseMove(MouseEventArgs e)
{
OnMouseMove(this, e);
base.OnMouseMove(e);
}

private void OnMouseMove(object sender, MouseEventArgs e)
{
Point current = new Point(e.X, e.Y);

current.Offset(negOffset);
Point point = GscToGoc(current);

bool result = items.LinkTest(point);

if (!result || !citem.Equals(selecteditem))
{
if (toolTipShown)
remove();

this.Cursor = Cursors.Default;
}

if (result)
{
citem = items.GetLinkItemAt(point);

if (citem != null)
{
selecteditem = citem;

Point tpoint = new Point();
if (parentIsCanvas)
tpoint = (parent as Canvas).CalcToolTipPoint(e);

if ((parent as Canvas).LinkItem != null && citem.Equals((parent as Canvas).LinkItem))
{
toolTip.******** = tpoint;
return;
}

ProcessLink(tpoint);

if (parentIsCanvas)
(parent as Canvas).ShowLinks();
}
}
if (toolTipShown)
{
toolTip.Show();
}
}
private void remove()
{
if (parentIsCanvas)
{
(parent as Canvas).removeToolTip();
(parent as Canvas).RemoveRevealedImage();
}

toolTipShown = false;
}

public void ProcessLink(Point tpoint)
{
if (parentIsCanvas)
{
(parent as Canvas).LinkItem.DrawLinkArea = true;
toolTip.Title = (parent as Canvas).LinkItem.ToolTipTitle;
toolTip.ToolTip = (parent as Canvas).LinkItem.Description;
}

toolTip.******** = tpoint;
toolTipShown = true;
toolTip.BringToFront();

this.Cursor = Cursors.Hand;
}

private Point GscToGoc(Point current)
{
if (parentIsCanvas)
return (parent as Canvas).GscToGoc(current);

return new Point();
}

private void OnClosing(object sender, FormClosingEventArgs e)
{
imageItem.ClientHeight = originalClientHeight;
imageItem.ClientWidth = originalClientWidth;
}

private void ImageRevealViewer_MouseEnter(object sender, EventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseEnter");
}

private void ImageRevealViewer_MouseCaptureChanged(object sender, EventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseCaptureChanged");
}

private void ImageRevealViewer_MouseClick(object sender, MouseEventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseClick");
}

private void ImageRevealViewer_MouseDown(object sender, MouseEventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseDown");
}

private void ImageRevealViewer_MouseHover(object sender, EventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseHover");
}

private void ImageRevealViewer_MouseLeave(object sender, EventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseLeave");
}

private void ImageRevealViewer_MouseUp(object sender, MouseEventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseUp");
}

private void ImageRevealViewer_Leave(object sender, EventArgs e)
{
Console.WriteLine("ImageRevealViewer_Leave");
}
}
}