错误 2 “Demo.WindowsForms.Forms.GMapMarkerGoogleGreen.GMapMarkerGoogleGreen(GMap.NET.PointLatLng)”必须声明主体,因为它未标记为 abstract、extern 或 partial C:\Users\Cat\Documents\ypmap\ypmap - 副本\Demo.WindowsForms\Forms\GMapMarkerGoogleGreen.cs 13 16 Demo.WindowsForms
代码如下
using System;
using System.Collections.Generic;
using System.Text;
using GMap.NET.WindowsForms;
using GMap.NET;
namespace Demo.WindowsForms.Forms
{
class GMapMarkerGoogleGreen:GMapMarker
{
public float? Bearing;
public GMapMarkerGoogleGreen(PointLatLng p);
public override void OnRender(System.Drawing.Graphics g)
{
base.OnRender(g);
}
}
}
这个是父类
using GMap.NET.WindowsForms.ToolTips;
namespace GMap.NET.WindowsForms
{
using System;
using System.Drawing;
using System.Runtime.Serialization;
using System.Windows.Forms;
/// <summary>
/// GMap.NET marker
/// </summary>
[Serializable]
#if !PocketPC
public abstract class GMapMarker : ISerializable, IDisposable
#else
public class GMapMarker: IDisposable
#endif
{
#if PocketPC
static readonly System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
static GMapMarker()
{
attr.SetColorKey(Color.White, Color.White);
}
#endif
GMapOverlay overlay;
public GMapOverlay Overlay
{
get
{
return overlay;
}
internal set
{
overlay = value;
}
}
private PointLatLng position;
public PointLatLng Position
{
get
{
return position;
}
set
{
if(position != value)
{
position = value;
if(IsVisible)
{
if(Overlay != null && Overlay.Control != null)
{
Overlay.Control.UpdateMarkerLocalPosition(this);
}
}
}
}
}
public object Tag;
Point offset;
public Point Offset
{
get
{
return offset;
}
set
{
if(offset != value)
{
offset = value;
if(IsVisible)
{
if(Overlay != null && Overlay.Control != null)
{
Overlay.Control.UpdateMarkerLocalPosition(this);
}
}
}
}
}
Rectangle area;
/// <summary>
/// marker position in local coordinates, internal only, do not set it manualy
/// </summary>
public Point LocalPosition
{
get
{
return area.Location;
}
set
{
if(area.Location != value)
{
area.Location = value;
{
if(Overlay != null && Overlay.Control != null)
{
if(!Overlay.Control.HoldInvalidation)
{
Overlay.Control.Core.Refresh.Set();
}
}
}
}
}
}
/// <summary>
/// ToolTip position in local coordinates
/// </summary>
public Point ToolTipPosition
{
get
{
Point ret = area.Location;
ret.Offset(-Offset.X, -Offset.Y);
return ret;
}
}
public Size Size
{
get
{
return area.Size;
}
set
{
area.Size = value;
}
}
public Rectangle LocalArea
{
get
{
return area;
}
}
internal Rectangle LocalAreaInControlSpace
{
get
{
Rectangle r = area;
if(Overlay != null && Overlay.Control != null)
{
r.Offset((int)Overlay.Control.Core.renderOffset.X, (int)overlay.Control.Core.renderOffset.Y);
}
return r;
}
}
public GMapToolTip ToolTip;
public MarkerTooltipMode ToolTipMode = MarkerTooltipMode.OnMouseOver;
string toolTipText;
public string ToolTipText
{
get
{
return toolTipText;
}
set
{
if(ToolTip == null)
{
#if !PocketPC
ToolTip = new GMapRoundedToolTip(this);
#else
ToolTip = new GMapToolTip(this);
#endif
}
toolTipText = value;
}
}
private bool visible = true;
/// <summary>
/// is marker visible
/// </summary>
public bool IsVisible
{
get
{
return visible;
}
set
{
if(value != visible)
{
visible = value;
if(Overlay != null && Overlay.Control != null)
{
if(visible)
{
Overlay.Control.UpdateMarkerLocalPosition(this);
}
{
if(!Overlay.Control.HoldInvalidation)
{
Overlay.Control.Core.Refresh.Set();
}
}
}
}
}
}
/// <summary>
/// if true, marker will be rendered even if it's outside current view
/// </summary>
public bool DisableRegionCheck = false;
/// <summary>
/// can maker receive input
/// </summary>
public bool IsHitTestVisible = true;
private bool isMouseOver = false;
/// <summary>
/// is mouse over marker
/// </summary>
public bool IsMouseOver
{
get
{
return isMouseOver;
}
internal set
{
isMouseOver = value;
}
}
public GMapMarker(PointLatLng pos)
{
this.Position = pos;
}
public virtual void OnRender(Graphics g)
{
//
}
#if PocketPC
protected void DrawImageUnscaled(Graphics g, Bitmap inBmp, int x, int y)
{
g.DrawImage(inBmp, new Rectangle(x, y, inBmp.Width, inBmp.Height), 0, 0, inBmp.Width, inBmp.Height, GraphicsUnit.Pixel, attr);
}
#endif
#if !PocketPC
#region ISerializable Members
/// <summary>
/// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with the data needed to serialize the target object.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> to populate with data.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"/>) for this serialization.</param>
/// <exception cref="T:System.Security.SecurityException">
/// The caller does not have the required permission.
/// </exception>
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Position", this.Position);
info.AddValue("Tag", this.Tag);
info.AddValue("Offset", this.Offset);
info.AddValue("Area", this.area);
info.AddValue("ToolTip", this.ToolTip);
info.AddValue("ToolTipMode", this.ToolTipMode);
info.AddValue("ToolTipText", this.ToolTipText);
info.AddValue("Visible", this.IsVisible);
info.AddValue("DisableregionCheck", this.DisableRegionCheck);
info.AddValue("IsHitTestVisible", this.IsHitTestVisible);
}
/// <summary>
/// Initializes a new instance of the <see cref="GMapMarker"/> class.
/// </summary>
/// <param name="info">The info.</param>
/// <param name="context">The context.</param>
protected GMapMarker(SerializationInfo info, StreamingContext context)
{
this.Position = Extensions.GetStruct<PointLatLng>(info, "Position", PointLatLng.Empty);
this.Tag = Extensions.GetValue<object>(info, "Tag", null);
this.Offset = Extensions.GetStruct<Point>(info, "Offset", Point.Empty);
this.area = Extensions.GetStruct<Rectangle>(info, "Area", Rectangle.Empty);
this.ToolTip = Extensions.GetValue<GMapToolTip>(info, "ToolTip", null);
this.ToolTipMode = Extensions.GetStruct<MarkerTooltipMode>(info, "ToolTipMode", MarkerTooltipMode.OnMouseOver);
this.ToolTipText = info.GetString("ToolTipText");
this.IsVisible = info.GetBoolean("Visible");
this.DisableRegionCheck = info.GetBoolean("DisableregionCheck");
this.IsHitTestVisible = info.GetBoolean("IsHitTestVisible");
}
#endregion
#endif
#region IDisposable Members
bool disposed = false;
public virtual void Dispose()
{
if(!disposed)
{
disposed = true;
Tag = null;
if(ToolTip != null)
{
toolTipText = null;
ToolTip.Dispose();
ToolTip = null;
}
}
}
#endregion
}
public delegate void MarkerClick(GMapMarker item, MouseEventArgs e);
public delegate void MarkerEnter(GMapMarker item);
public delegate void MarkerLeave(GMapMarker item);
/// <summary>
/// modeof tooltip
/// </summary>
public enum MarkerTooltipMode
{
OnMouseOver,
Never,
Always,
}
}
你这个构造函数没有实现。
public GMapMarkerGoogleGreen(PointLatLng p)
{
this.Position = p;
}
这样实现还是报错,郁闷啊
@我是一只小小的菜鸟:这次报啥错?
@幻天芒: 最好贴出父类。
@幻天芒: 还是未声明主体
@我是一只小小的菜鸟:
public GMapMarkerGoogleGreen(PointLatLng p)
{
this.Position = p;
}
错误 4 “GMap.NET.WindowsForms.GMapMarker”不包含采用“0”个参数的构造函数 C:\Users\Cat\Documents\ypmap\ypmap - 副本\Demo.WindowsForms\Forms\GMapMarkerGoogleGreen.cs 13 16 Demo.WindowsForms
@我是一只小小的菜鸟: 是你调用的问题,不是类申明的问题吧。
@幻天芒: 调用命名空间有问题?
@我是一只小小的菜鸟:就是你在别的地方可能调用了,不过没带参数。 GMapMarkerGoogleGreen g=new GMapMarkerGoogleGreen();
@幻天芒: 好多警告,还有未将对象引用到实例
if (!Stuff.PingNetwork("pingtest.net"))
{
MainMap.Manager.Mode = AccessMode.ServerAndCache;
MessageBox.Show("No internet connection available, going to CacheOnly mode.", "GMap.NET - Demo.WindowsForms", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
@我是一只小小的菜鸟: 你这段代码在干啥?
@幻天芒: 设置电子地图的获取方式,服务器跟缓存
@我是一只小小的菜鸟: 哦,应该和构造函数无关。你的问题ok了?
public GMapMarkerGoogleGreen(PointLatLng p);方法你没有写方法体,只有抽象类和接口才可以只声明不实现,否则必须写方法体
class GMapMarkerGoogleGreen:GMapMarker这个父类是抽象类,里面的构造函数,我试过加方法体,但还是报同样的错误。实在不知到底是哪里问题
@我是一只小小的菜鸟: 有方法体还能报错?是不是哪写错了,或者是没有重新编译
还有方法后面不用加分号
public GMapMarkerGoogleGreen(PointLatLng p):base(p)
{
}
public GMapMarkerGoogleGreen(PointLatLng p)
:base (PointLatLng pos)
{
this.Position=p;
}
}
错误 2 “GMap.NET.WindowsForms.GMapMarker”不包含采用“0”个参数的构造函数 C:\Users\Cat\Documents\ypmap\ypmap - 副本\Demo.WindowsForms\Forms\GMapMarkerGoogleGreen.cs 13 16 Demo.WindowsForms
错误 5 应输入 ) C:\Users\Cat\Documents\ypmap\ypmap - 副本\Demo.WindowsForms\Forms\GMapMarkerGoogleGreen.cs 15 32 Demo.WindowsForms
哥们 ,再看下
@我是一只小小的菜鸟:
父类构造函数没有参数就这样写:
public GMapMarkerGoogleGreen(PointLatLng p)
:base ()
{
this.Position=p;
}
@tubo:
public GMapMarkerGoogleGreen(PointLatLng p)
: base(p)
{
this.Position = p;
}
恩是这样,但我想不通我引用父类的带参数的构造函数,本来应该是: base(pos),它报错说pos这个参数不存在,写成p没事,不知道为什么?昨天抱歉,没分豆给你,第一次搞提问,以为只能给一个人,实在不好意思。。。。
@我是一只小小的菜鸟:
:base(p)是调用父类的方法,不是声明。
@tubo: 不是调用它的构造函数吗
@Danny@yang: 是调用,你的写法弄成了声明了
:base (PointLatLng pos)
@tubo: 噢,这些终于翻篇了,谢谢你
你可以试试为GMapMarkerGoogleGreen定义一个无参的构造函数
public GMapMarkerGoogleGreen(){}
要带参数的
@我是一只小小的菜鸟: 你添加一个无参的
public GMapMarkerGoogleGreen(){}
public GMapMarkerGoogleGreen(PointLatLng p)
{
}
这两个都写上 可能是构造函数的执行顺序造成的
@wolfy:
错误 2 “GMap.NET.WindowsForms.GMapMarker”不包含采用“0”个参数的构造函数 C:\Users\Cat\Documents\ypmap\ypmap - 副本\Demo.WindowsForms\Forms\GMapMarkerGoogleGreen.cs 13 16 Demo.WindowsForms
@我是一只小小的菜鸟: 我考了你的部分代码 在我这里试了 有方法体 编译通过了啊
@wolfy: 我这边的还牵扯到调用呢,不知道你是怎么弄的
@我是一只小小的菜鸟:
class GMapMarkerGoogleGreen : GMapMarker
{
public float? Bearing;
//我这里将参数类型改为string类型的 就没问题了 因为代码没拷贝完 只拷贝了父类和子类
public GMapMarkerGoogleGreen(string p){}
}