重分酬谢:请求解决自定义控件不显示图片的问题。(200分)

A

Aliama

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟在开发过程中碰到如此问题:
我在做一个画图软件,vs2005,C#, 自定义了空间Canves 继承自PictureBox,代码如下:
碰到问题是,用这个控件使用中怎么都不显示背景图片,因为我想在背景图片基础上画图。
请求解决,感激不尽阿。如果愿意联系,我的msn:Ali0288@hotmail.com
using System;
using Paint.Event;
using Paint.Manager;
using System.Windows.Forms;
using Paint.Canvas;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Paint.GUI
{
/// <summary>
/// Paint
/// </summary>
public class PaintCanvas : System.Windows.Forms.PictureBox
{

public static void RedrawAll()
{
if(InternalCallRedraw != null)
InternalCallRedraw(null);
}
//public override i
public override Image BackgroundImage
{
get
{
return base.BackgroundImage;
}
set
{
base.BackgroundImage = value;
}
}
delegate void Redraw(Graphics g);
static Redraw InternalCallRedraw;
public PaintCanvas()
{
InternalCallRedraw += new Redraw(RedrawAllShape);
}
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{
InteractiveEvent ie =
new InteractiveEvent(this,InteractiveEvent.EVENT_TYPE.KEY_PRESS,
new Point(0,0,0),(uint)Form.ModifierKeys,(byte)e.KeyChar);
HandleEvent(ie);
base.OnKeyPress (e);
}

protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
{
InteractiveEvent ie =
new InteractiveEvent(this,InteractiveEvent.EVENT_TYPE.MOUSE_MOVE,
new Point(e.X,e.Y,0),(uint)Form.ModifierKeys,0);
HandleEvent(ie);
base.OnMouseMove (e);
}

protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
{
InteractiveEvent.EVENT_TYPE EventType;
// switch(e.Clicks)
// {
// case 1:
// if(e.Button == MouseButtons.Left)
// {
// EventType = InteractiveEvent.EVENT_TYPE.MOUSE_LBCLICK;
// }
// else
// {
// EventType = InteractiveEvent.EVENT_TYPE.MOUSE_RBCLICK;
// }
// break;
// case 2:
// if(e.Button == MouseButtons.Left)
// {
// EventType = InteractiveEvent.EVENT_TYPE.MOUSE_LBDBCLICK;
// }
// else
// {
// EventType = InteractiveEvent.EVENT_TYPE.MOUSE_RBDBCLICK;
// }
// break;
// default:
// if(e.Button == MouseButtons.Left)
// {
// EventType = InteractiveEvent.EVENT_TYPE.MOUSE_LBUP;
// }
// else
// {
// EventType = InteractiveEvent.EVENT_TYPE.MOUSE_RBUP;
// }
// break;
// }
EventType = (e.Button == MouseButtons.Left)?InteractiveEvent.EVENT_TYPE.MOUSE_LBUP:InteractiveEvent.EVENT_TYPE.MOUSE_RBUP;
InteractiveEvent ie =
new InteractiveEvent(this,
EventType,
new Point(e.X,e.Y,0),(uint)Form.ModifierKeys,0);
HandleEvent(ie);
base.OnMouseUp (e);
}

protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
InteractiveEvent.EVENT_TYPE EventType;
switch(e.Clicks)
{
// case 1:
// if(e.Button == MouseButtons.Left)
// {
// EventType = InteractiveEvent.EVENT_TYPE.MOUSE_LBCLICK;
// }
// else
// {
// EventType = InteractiveEvent.EVENT_TYPE.MOUSE_RBCLICK;
// }
// break;
case 2:
if(e.Button == MouseButtons.Left)
{
EventType = InteractiveEvent.EVENT_TYPE.MOUSE_LBDBCLICK;
}
else
{
EventType = InteractiveEvent.EVENT_TYPE.MOUSE_RBDBCLICK;
}
break;
default:
if(e.Button == MouseButtons.Left)
{
EventType = InteractiveEvent.EVENT_TYPE.MOUSE_LBDOWN;
}
else
{
EventType = InteractiveEvent.EVENT_TYPE.MOUSE_RBDOWN;
}
break;
}
InteractiveEvent ie =
new InteractiveEvent(this,EventType,
new Point(e.X,e.Y,0),(uint)Form.ModifierKeys,0);
HandleEvent(ie);
base.OnMouseDown (e);
}

private void HandleEvent(InteractiveEvent ie)
{
Point p = (Point)ie.MousePosition.Clone();
ChiefManager.getInstance().HandleEvent(ie);
if(ie.IsMouseCaptured)
this.Capture = true;
else
this.Capture = false;
if(p.x != ie.MousePosition.x || p.y != ie.MousePosition.y )
Cursor.Position = this.PointToScreen(new System.Drawing.Point(ie.MousePosition.x,ie.MousePosition.y));

if(ie.Redraw)
{
this.Invalidate();//new Rectangle(0,0,this.Width,this.Height));
//this.Update();
}
}
private void RedrawAllShape(Graphics g)
{
ICanvas canvas = new Paint.Canvas.MSCanvas(g == null?this.CreateGraphics():g,new Rect(0,0,this.Width,this.Height),ChiefManager.getInstance().GetGlobalFont().BackColor);
ChiefManager.getInstance().Draw(canvas);
}

protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint (pe);
this.RedrawAllShape(pe.Graphics);
}
private void InitializeComponent()
{
((System.ComponentModel.ISupportInitialize)(this)).begin
Init();
this.SuspendLayout();
//
// PaintCanvas
//
this.BackgroundImage = global::paint.Properties.Resources.DSCN2004;
this.Image = global::paint.Properties.Resources.DSCN2004;
this.InitialImage = global::paint.Properties.Resources.DSCN2004;
((System.ComponentModel.ISupportInitialize)(this)).EndInit();
this.ResumeLayout(false);
}
}
}
 
自己结了,原因是重载
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint (pe);
this.RedrawAllShape(pe.Graphics);
}
的时候 base.OnPaint (pe);
this.RedrawAllShape(pe.Graphics);有点冲突
 
那俺就顺便蹭点分吧
 
C的代码在大富翁讨论[:(]
 
你说这个分怎么分配阿?
好像还不能给自己的,郁闷,挂在这里?
过几天我散分了,来的人都有份。
 
顶部