public override void OnMouseDown(int Button, int Shift, int X, int Y),void下面出现红线
你要确定以下两点,
1,这个方法所在的类是否继承自另一个类。
2.,该类的基类不否有一个public static void OnMouseDown的方法。
画点
[C#]
public void OnMouseDown(int Button, int Shift, int X, int Y)
{
IMxDocument mxDoc = m_App.Document as IMxDocument;
IActiveView activeView = mxDoc.FocusMap as IActiveView;
IScreenDisplay screenDisplay = activeView.ScreenDisplay;
screenDisplay.StartDrawing(screenDisplay.hDC, (short) esriScreenCache.esriNoScreenCache);
screenDisplay.SetSymbol(new SimpleMarkerSymbolClass());
screenDisplay.DrawPoint(mxDoc.CurrentLocation);
screenDisplay.FinishDrawing();
}
画线
public void OnMouseDown(int Button, int Shift, int X, int Y)
{
IMxDocument mxDoc = m_App.Document as IMxDocument;
IActiveView activeView = mxDoc.FocusMap as IActiveView;
IScreenDisplay screenDisplay = activeView.ScreenDisplay;
ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
IRgbColor rgbColor = new RgbColorClass();
rgbColor.Red = 255;
lineSymbol.Color = rgbColor;
IRubberBand rubberLine = new RubberLineClass();
IPolyline newPolyline = (IPolyline)rubberLine.TrackNew(screenDisplay, (ISymbol)lineSymbol);
screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
screenDisplay.SetSymbol((ISymbol)lineSymbol);
screenDisplay.DrawPolyline(newPolyline);
screenDisplay.FinishDrawing();
}
画线2
{
ICartographicLineSymbol pCartoLineSyl;
pCartoLineSyl = new CartographicLineSymbolClass();
pCartoLineSyl.Color = getRGB(255, 110, 210);
pCartoLineSyl.Cap = esriLineCapStyle.esriLCSButt;
pCartoLineSyl.Join = esriLineJoinStyle.esriLJSBevel;
pCartoLineSyl.Width=4;
pCartoLineSyl.MiterLimit=4;
ILineProperties pLinePro ;
pLinePro = pCartoLineSyl as ILineProperties;//取地址
ISimpleLineDecorationElement pSimpleLineDecoEle;
pSimpleLineDecoEle = new SimpleLineDecorationElementClass();
pSimpleLineDecoEle.FlipAll = true;
pSimpleLineDecoEle.FlipFirst = true;
ILineDecoration pLineDeco;
pLineDeco = new LineDecorationClass();
pLineDeco.AddElement(pSimpleLineDecoEle);
pLinePro.LineDecoration = pLineDeco;
pLinePro.DecorationOnTop=true;
IGeometry pGeo;
pGeo = axMapControl2.TrackLine();
object oLineSymbol = pCartoLineSyl;
axMapControl2.DrawShape(pGeo, ref oLineSymbol);
}
画线3
private void axMapControl2_OnMouseDown(object sender, AxESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvent e)
{
// ISimpleLineSymbol pLineSyl;
// pLineSyl = new SimpleLineSymbolClass();
// pLineSyl.Color = getRGB(30, 60, 90);
// pLineSyl.Width = 4;
// pLineSyl.Style = esriSimpleLineStyle.esriSLSDashDot;
ICartographicLineSymbol pCartoLineSyl;
pCartoLineSyl = new CartographicLineSymbolClass();
//pCartoLineSyl.Color = getRGB(255, 110, 210);
pCartoLineSyl.Cap = esriLineCapStyle.esriLCSButt;
pCartoLineSyl.Join = esriLineJoinStyle.esriLJSBevel;
pCartoLineSyl.Width=10;
pCartoLineSyl.MiterLimit=4;
ILineProperties pLinePro ;
pLinePro = pCartoLineSyl as ILineProperties;//取地址
ISimpleLineDecorationElement pSimpleLineDecoEle;
pSimpleLineDecoEle = new SimpleLineDecorationElementClass();
pSimpleLineDecoEle.FlipAll = true;
pSimpleLineDecoEle.FlipFirst = true;
ILineDecoration pLineDeco;
pLineDeco = new LineDecorationClass();
pLineDeco.AddElement(pSimpleLineDecoEle);
pLinePro.LineDecoration = pLineDeco;
pLinePro.DecorationOnTop=true;
ILineFillSymbol pLineFillSymbol =new LineFillSymbolClass();
pLineFillSymbol.Offset=3;
pLineFillSymbol.Angle=45;
pLineFillSymbol.Offset=10;
IFillSymbol pFillSymbol =pLineFillSymbol as IFillSymbol;
pFillSymbol.Color=getRGB(0,0,200);
pFillSymbol.Outline=pCartoLineSyl;
ICharacterMarkerSymbol pCharacterMarkerSymbol;
pCharacterMarkerSymbol = new CharacterMarkerSymbolClass();
//设置它的字符,114为‘r’
pCharacterMarkerSymbol.CharacterIndex = 114;
IMarkerFillSymbol pMarkerFillSymbol =new MarkerFillSymbolClass();
pMarkerFillSymbol.Outline=pCartoLineSyl;
pMarkerFillSymbol.Style=esriMarkerFillStyle.esriMFSRandom;
pMarkerFillSymbol.MarkerSymbol=pCharacterMarkerSymbol;
pMarkerFillSymbol.GridAngle=45;
pMarkerFillSymbol.Color=getRGB(0,255,255);
IGeometry pGeo;
pGeo = axMapControl2.TrackLine();
object oLineSymbol = pCartoLineSyl;
axMapControl2.DrawShape(pGeo, ref oLineSymbol);
}
画面
public void OnMouseDown(int Button, int Shift, int X, int Y)
{
IMxDocument mxDoc = m_App.Document as IMxDocument;
IActiveView activeView = mxDoc.FocusMap as IActiveView;
IScreenDisplay screenDisplay = activeView.ScreenDisplay;
ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
IRgbColor rgbColor = new RgbColorClass();
rgbColor.Red = 255;
fillSymbol.Color = rgbColor;
IRubberBand rubberPolygon = new RubberPolygonClass();
IPolygon newPolygon = (IPolygon)rubberPolygon.TrackNew(screenDisplay, (ISymbol)fillSymbol);
screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
screenDisplay.SetSymbol((ISymbol)fillSymbol);
screenDisplay.DrawPolygon(newPolygon);
screenDisplay.FinishDrawing();
}
画矩形
public void OnMouseDown(int Button, int Shift, int X, int Y)
{
IMxDocument mxDoc = m_App.Document as IMxDocument;
IActiveView activeView = mxDoc.FocusMap as IActiveView;
IScreenDisplay screenDisplay = activeView.ScreenDisplay;
ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
IRgbColor rgbColor = new RgbColorClass();
rgbColor.Red = 255;
fillSymbol.Color = rgbColor;
IRubberBand rubberEnv = new RubberEnvelopeClass();
IEnvelope newEnvelope = (IEnvelope)rubberEnv.TrackNew(screenDisplay, (ISymbol)fillSymbol);
screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
screenDisplay.SetSymbol((ISymbol)fillSymbol);
screenDisplay.DrawRectangle(newEnvelope);
screenDisplay.FinishDrawing();
}
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.WinForms;
using System.Data;
/// <summary>
/// Summary description for Form1.
/// </summary>
public class FiveForm : System.WinForms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components;
private System.WinForms.ImageList imageListbw;
//define the hot Rectangle
private Rectangle[] pointSquares;
//chess information
private int[] chessTable;
private int nextTurn;
private const int bTurn = 1;
private const int wTurn = 2;
private Stack chessIndex;
public FiveForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
chessIndex = new Stack();
nextTurn = bTurn;
chessTable = new int[225];
pointSquares = new Rectangle[225];
Size size = new Size(18,18);
int x = 0;
int y = 0;
for(int i = 0;i < 225;i++)
{
x = i%15;
y = i/15;
pointSquares[i].Size = size;
pointSquares[i].Offset(9+x*20,6+y*20);
chessTable[i] = 0;
}
}
protected override void OnPaint(PaintEventArgs e)
{
//you may paint
Graphics g = e.Graphics;
}
protected override void OnMouseDown(System.WinForms.MouseEventArgs e)
{
switch( e.Button )
{
//take left button down
case MouseButtons.Left:
OnLButtonDown(new Point(e.X,e.Y));
break;
//take right button down
case MouseButtons.Right:
OnRButtonDown(new Point(e.X,e.Y));
break;
}
base.OnMouseDown(e);
}
private void OnLButtonDown(Point p)
{
int nPos = GetRectID(p);
//click hot Rectangle witch have no chess
if(nPos != -1&&chessTable[nPos] == 0)
{
Graphics g = this.CreateGraphics();
if(nextTurn==bTurn)
{
//draw white chess
DrawBlack(g,nPos);
chessTable[nPos] = bTurn;
nextTurn = wTurn;
chessIndex.Push(bTurn);
chessIndex.Push(nPos);
}
else
{
//draw Black chess
DrawWhite(g,nPos);
chessTable[nPos] = wTurn;
nextTurn = bTurn;
chessIndex.Push(wTurn);
chessIndex.Push(nPos);
}
g.Dispose();
//witch win
CheckGameResult(nPos,nextTurn);
}
}
private void CheckGameResult(int nPos,int nextTurn)
{
//witch win
Stack isFive = new Stack();
int thisTurn = (nextTurn == bTurn)?wTurn:bTurn;
int x = nPos%15;
int y = nPos/15;
//scan x have five
for(int i=0;i<15;i++)
{
if(chessTable[y*15+i] == thisTurn)
{
isFive.Push(y*15+i);
if(isFive.Count == 5)
{
MessageBox.Show("Game Over","Notes",MessageBox.OK);
ReSetGame();
return;
}
}
else
{
isFive.Clear();
}
}
isFive.Clear();
//scan y have five
for(int i=0;i<15;i++)
{
if(chessTable[i*15+x] == thisTurn)
{
isFive.Push(i*15+x);
if(isFive.Count == 5)
{
MessageBox.Show("Game Over","Notes",MessageBox.OK);
ReSetGame();
return;
}
}
else
{
isFive.Clear();
}
}
isFive.Clear();
//scan x=y have five
for(int i=-14;i<15;i++)
{
if(x+i<0||x+i>14||y-i<0||y-i>14)
{
continue;
}
else
{
if(chessTable[(y-i)*15+x+i] == thisTurn)
{
isFive.Push((y-i)*15+x+i);
if(isFive.Count == 5)
{
MessageBox.Show("Game Over","Notes",MessageBox.OK);
ReSetGame();
return;
}
}
else
{
isFive.Clear();
}
}
}
isFive.Clear();
//scan x=-y have five
for(int i=-14;i<15;i++)
{
if(x+i<0||x+i>14||y+i<0||y+i>14)
{
continue;
}
else
{
if(chessTable[(y+i)*15+x+i] == thisTurn)
{
isFive.Push((y+i)*15+x+i);
if(isFive.Count == 5)
{
MessageBox.Show("Game Over","Notes",MessageBox.OK);
ReSetGame();
return;
}
}
else
{
isFive.Clear();
}
}
}
isFive.Clear();
}
private void ReSetGame()
{
//reset game
nextTurn = bTurn;
for(int i=0;i<225;i++)
{
chessTable[i] = 0;
}
this.Invalidate();
}
private int GetRectID(Point p)
{
//get witch rectangle click
for(int i = 0;i < 225;i++)
{
if(pointSquares[i].Contains( p ))
{
return i;
}
}
return -1;
}
private void OnRButtonDown(Point p)
{
//regret chess
int nPos,x,y;
if(chessIndex.Count != 0)
{
nPos = (int)chessIndex.Pop();
x = nPos%15;
y = nPos/15;
chessTable[nPos] = 0;
nextTurn = (int)chessIndex.Pop();
this.Invalidate(new Rectangle(new Point(8+x*20,5+y*20),new Size(20,20)));
}
}
private void DrawBlack(Graphics g,int nPos)
{
//draw Black chess
int x,y;
x = nPos%15;
y = nPos/15;
imageListbw.DrawImage(g,8+20*x,5+20*y,20,20,0,0);
}
private void DrawWhite(Graphics g,int nPos)
{
//draw White chess
int x,y;
x = nPos%15;
y = nPos/15;
imageListbw.DrawImage(g,8+20*x,5+20*y,20,20,0,1);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
public override void Dispose()
{
base.Dispose();
components.Dispose();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof(FiveForm));
this.components = new System.ComponentModel.Container ();
this.imageListbw = new System.WinForms.ImageList ();
//@this.TrayHeight = 90;
//@this.TrayLargeIcon = false;
//@this.TrayAutoArrange = true;
//@imageListbw.SetLocation (new System.Drawing.Point (7, 7));
imageListbw.ImageSize = new System.Drawing.Size (20, 20);
imageListbw.ImageStream = (System.WinForms.ImageListStreamer) resources.GetObject ("imageListbw.ImageStream");
imageListbw.ColorDepth = System.WinForms.ColorDepth.Depth8Bit;
imageListbw.TransparentColor = System.Drawing.Color.Yellow;
this.Text = "FiveForm";
this.MaximizeBox = false;
this.AutoScaleBaseSize = new System.Drawing.Size (6, 14);
this.BorderStyle = System.WinForms.FormBorderStyle.FixedSingle;
this.BackgroundImage = (System.Drawing.Image) resources.GetObject ("$this.BackgroundImage");
this.TransparencyKey = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size (314, 311);
}
/// <summary>
/// The main entry point for the application.
/// </summary>
public static int Main(string[] args)
{
Application.Run(new FiveForm());
return 0;
}
}
}
范罗氟氯: A b = new B(); //注意这里,你new的是子类B,所以b不能称之为父类A的实例 A c = new C(); // 同上 b.Show(); //这里的b实际上是子类B的实例,所以调用的show方法是在B类里重写后的方法 c.Show(); //同上如果你想调用A类里的方法就不能那样写,要这样写: A b = new A(); A c = new A(); b.Show(); c.Show(); 这样输出的结果就是:A.Show() A.Show() 如果看不明白,可以再问我
呼伦贝尔市17565029050: c# 中 override 什么作用 - ?
范罗氟氯: Public abstract class A {public string TestMethod(){return "返回一个字符串";} } public class B:A {public override string TestMethod(){//blablablabla....} } Override就是来重写基类的方法的,可以实现面向对象的多态这个特性
呼伦贝尔市17565029050: Java中的@Override是什么意思? - ?
范罗氟氯: @Override是伪代码,表示重写(当然不写也可以) 建议写上,有如下好处: 1、可以当注释用,方便阅读; 2、编译器可以给你验证@Override下面的方法名是否是你父类中所有的,如果没有则报错,比如你如果没写@Override而你下面的方法名又写错了,这时你的编译器是可以通过的(它以为这个方法是你的子类中自己增加的方法).
呼伦贝尔市17565029050: c#里面的override和new究竟有什么区别啊 - ?
范罗氟氯: override是重载所继承的类型方法的 而被继承的类方法必须加virtual 才可以被重载 new 运算符 1.用于创建对象和调用构造函数 例:Class_Test MyClass = new Class_Test(); 2.也用于为值类型调用默认的构造函数 例:int myInt = new int(); myInt 初...
呼伦贝尔市17565029050: C#中的virtual和override的用法 - ?
范罗氟氯: overrride表示重写 这个类是继承于Shape类 <br>public override double Area 这个属性再shape中肯定存在 但是这里我们不想用shape中的 所以要重写 virtual是告诉其它想继承于他的类 你可以重写我的这个方法或属性,否则不允许. 给你一个生动的例子 老爸表示基类(被继承的类) 儿子表示子类(继承的类) 老爸用virtual告诉儿子:"孩子,你要继承我的事业,在这块上面可以自己继续发展你自己的" 儿子用override告诉全世界:"这个我可不是直接拿我爸的,他只是指个路给我,是我自己奋斗出来的"
呼伦贝尔市17565029050: asp.net中override是什么意思,什么时候可以用?有什么作用? - ?
范罗氟氯: 一般是实现虚方法的时候需要的关键字 [虚方法声明关键字virtual] 要扩展或修改继承的方法、属性、索引器或事件的抽象实现或虚实现,必须使用 override 修饰符 比如:class TestOverride { public class Employee { public string name; // Basepay ...
呼伦贝尔市17565029050: C#中 override和new关键字的区别 - ?
范罗氟氯: 建一个控制台工程,复制一下代码:using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { public class A { public virtual void MethodA() { Console.WriteLine("A.MethodA"); } public void MethodB...
呼伦贝尔市17565029050: C#的override怎么用? - ?
范罗氟氯: override 方法提供从基类继承的成员的新实现. 由 override 声明重写的方法称为重写基方法. 重写的基方法必须与 override 方法具有相同的签名. 有关继承的信息,请参见继承(C# 编程指南).不能重写非虚方法或静态方法. 重写的基方法...
呼伦贝尔市17565029050: 怎么在android中实现一个按钮的多个监听事件 - ?
范罗氟氯: 1、先申明一个监听对象2、不同按钮设置同一个监听对象3、监听中,通过按钮的id判断是哪个按钮的点击事件 代码如下1、new监听 OnClickListener clickListener = new OnClickListener(){ @Override public void onClick(View v) { if (v.getId()==R.id....
呼伦贝尔市17565029050: android button 双击操作如何监听 - ?
范罗氟氯: android里面没有监听双击事件的操作,如果想实现的话我的建议是在 private int count = 0; button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {count++;if(cout == 2){.监听处理.count = 0;}} }) ; 这样...