用C#画圆与矩形 求助高手,用C#画圆与矩形的方法~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Graphics 晕 MSDN就有myGraphics.DrawRectangle(myPen, 100, 50, 80, 40);http://blog.csdn.net/stone0419/archive/2007/10/04/1811412.aspx private void button1_Click(object sender, EventArgs e) { Graphics _Graphics = Graphics.FromHwnd(pictureBox1.Handle); _Graphics.DrawEllipse(new Pen(Brushes.Yellow, 2), GetEllopse(new Point(50, 50), 10)); _Graphics.Dispose(); } /// <summary> /// 根据圆心和半径获取图形坐标 /// </summary> /// <param name="p_CenterPoint">圆心</param> /// <param name="p_Radius">半径</param> /// <returns>坐标</returns> public Rectangle GetEllopse(Point p_CenterPoint, int p_Radius) { int _X = p_CenterPoint.X - p_Radius; int _Y = p_CenterPoint.Y - p_Radius; return new Rectangle(_X, _Y, p_Radius * 2, p_Radius * 2); } Graphics g = e.Graphics; //创建画板Pen p = new Pen(Color.Blue, 2);g.DrawRectangle(p, 10, 10, 100, 100);//在画板上画矩形,起始坐标为(10,10),宽为,高为g.DrawEllipse(p, 10, 10, 100, 100);//在画板上画椭圆,起始坐标为(10,10) 完全不是一个概念,你的地图不会是google或者其他网页上的吧?不然一个图你怎么会有经纬度信息? 把这个话与你八楼的话对比看一下,有些矛盾吧,逻辑 或者 表达画圆->在圆上画经纬度?有了经纬度(这个么可以自己定义的咯?)->画圆? google上画?google上有自己的API呀 Graphics g = e.Graphics; //创建画板Pen p = new Pen(Color.Blue, 2);g.DrawRectangle(p, 10, 10, 100, 100);//在画板上画矩形,起始坐标为(10,10),宽为,高为g.DrawEllipse(p, 10, 10, 100, 100);//在画板上画椭圆,起始坐标为(10,10) #region GoogleMap /// <summary> /// GoogleMap /// </summary> ///点,线坐标 public void GoogleMap(string allPoint, string allLine) { //webBrowser1.Navigate("http://localhost:2865/Default.aspx"); wbMap.ObjectForScripting = this; string szWebBrowserText = @" <html> <head> <title></title> <script src='http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&key=ABQIAAAAuLMCs813ETPzKnClYiBwuhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRogqzInHtHXDyDOAQDeSX3MxNWbg' type='text/javascript'></script> <script type='text/javascript'> function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById('map')); map.setCenter(new GLatLng(26.157042, 111.269531), 6); map.setUIToDefault(); function createMarker(point, prompt) { var baseIcon = new GIcon(G_DEFAULT_ICON); baseIcon.shadow = 'http://www.google.com/mapfiles/shadow50.png'; baseIcon.iconSize = new GSize(20, 34); baseIcon.shadowSize = new GSize(37, 34); baseIcon.iconAnchor = new GPoint(9, 34); baseIcon.infoWindowAnchor = new GPoint(9, 2); var redIcon = new GIcon(baseIcon); redIcon.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png'; erOptions = { icon:redIcon }; var er = new GMarker(point, erOptions); GEvent.addListener(er, 'mouseover', function() { er.openInfoWindowHtml(prompt); }); GEvent.addListener(er, 'click', function(){ var xlatlng = er.getLatLng(); window.external.ClickPoint(xlatlng.lat().toString(),xlatlng.lng().toString()); }); return er; } function createMarker02(point, prompt) { var baseIcon = new GIcon(G_DEFAULT_ICON); baseIcon.shadow = 'http://maps.google.com/mapfiles/arrowshadow.png'; baseIcon.iconSize = new GSize(20, 34); baseIcon.shadowSize = new GSize(37, 34); baseIcon.iconAnchor = new GPoint(9, 34); baseIcon.infoWindowAnchor = new GPoint(9, 2); var redIcon = new GIcon(baseIcon); redIcon.image = 'http://maps.google.com/mapfiles/arrow.png'; erOptions = { icon:redIcon }; var er = new GMarker(point, erOptions); GEvent.addListener(er, 'mouseover', function() { er.openInfoWindowHtml(prompt); }); GEvent.addListener(er, 'click', function(){ window.external.ClickMidPoint(prompt.toString()); }); return er; } " + allPoint + @" " + allLine + @" } } </script> </head> <body onload='initialize();' oncontextmenu='event.returnValue=false'> <div id='map' style='width: 950px; height: 525px;'> </div> </body> </html>"; wbMap.DocumentText = szWebBrowserText; } #endregion这个是C#利用google地图的一小段代码, 不是GOOGLE的,是用的我们自己的地图引擎。 在form paint 事件里Graphics g = e.Grahpics具体方法上面给出了。或者在load事件里Grahpics g = this.CreateGraphics();或者在某个控件里Grahpics g = button1.CreateGraphics();在图片里Bitmap mybit = new Bitmap(""e:/1.jpg);graphics g = pictureBox1.CreateGraphics(); 是桌面应用程序了,不是GOOGLE的API,只是用的他们的图片而已,就是要在图片上画圆啊 private void pictureBox1_Paint(object sender, PaintEventArgs e) { Rectangle r=new Rectangle(10,10,10,10); //圆 e.Graphics.DrawEllipse(new Pen(Color.Red),r); //Graphics.DrawEllipse画椭圆 } 画圆就是上面的代码e.Graphics.DrawEllipse(new Pen(Color.Red),r); 关键就是得到这个e,看你的图片放在什么地方了,放在picturebox的话,就是paint里话,还要用个变量保存你这些点的信息 About ObservableCollection 初学者问题 桌面程序运行在不同层次 怎么可以让图片在一个区域内来回移动? DataGridView使用中的问题! [求助]C#2003如何部署??急急急急急急~~~~~ 在pictureBox里画了一条直线,如何用鼠标去移动它? 问一个很菜的问题。Datetime对象 写文件时候编码问题,怎样用 shift-jis 将字符串写入文件!急 C# 链表问题 c#程序求解 C# 怎么获取当前时间
myGraphics.DrawRectangle(myPen, 100, 50, 80, 40);
http://blog.csdn.net/stone0419/archive/2007/10/04/1811412.aspx
{ Graphics _Graphics = Graphics.FromHwnd(pictureBox1.Handle); _Graphics.DrawEllipse(new Pen(Brushes.Yellow, 2), GetEllopse(new Point(50, 50), 10));
_Graphics.Dispose(); }
/// <summary>
/// 根据圆心和半径获取图形坐标
/// </summary>
/// <param name="p_CenterPoint">圆心</param>
/// <param name="p_Radius">半径</param>
/// <returns>坐标</returns>
public Rectangle GetEllopse(Point p_CenterPoint, int p_Radius)
{
int _X = p_CenterPoint.X - p_Radius;
int _Y = p_CenterPoint.Y - p_Radius;
return new Rectangle(_X, _Y, p_Radius * 2, p_Radius * 2);
}
Pen p = new Pen(Color.Blue, 2);
g.DrawRectangle(p, 10, 10, 100, 100);//在画板上画矩形,起始坐标为(10,10),宽为,高为
g.DrawEllipse(p, 10, 10, 100, 100);//在画板上画椭圆,起始坐标为(10,10)
画圆->在圆上画经纬度?
有了经纬度(这个么可以自己定义的咯?)->画圆?
Graphics g = e.Graphics; //创建画板
Pen p = new Pen(Color.Blue, 2);
g.DrawRectangle(p, 10, 10, 100, 100);//在画板上画矩形,起始坐标为(10,10),宽为,高为
g.DrawEllipse(p, 10, 10, 100, 100);//在画板上画椭圆,起始坐标为(10,10)
/// <summary>
/// GoogleMap
/// </summary>
///点,线坐标
public void GoogleMap(string allPoint, string allLine)
{
//webBrowser1.Navigate("http://localhost:2865/Default.aspx"); wbMap.ObjectForScripting = this; string szWebBrowserText = @"
<html>
<head>
<title></title> <script src='http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&key=ABQIAAAAuLMCs813ETPzKnClYiBwuhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRogqzInHtHXDyDOAQDeSX3MxNWbg'
type='text/javascript'></script>
<script type='text/javascript'> function initialize()
{
if (GBrowserIsCompatible())
{
var map = new GMap2(document.getElementById('map'));
map.setCenter(new GLatLng(26.157042, 111.269531), 6);
map.setUIToDefault(); function createMarker(point, prompt)
{
var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.shadow = 'http://www.google.com/mapfiles/shadow50.png';
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2); var redIcon = new GIcon(baseIcon);
redIcon.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
erOptions = { icon:redIcon };
var er = new GMarker(point, erOptions);
GEvent.addListener(er, 'mouseover', function() {
er.openInfoWindowHtml(prompt);
}); GEvent.addListener(er, 'click', function(){
var xlatlng = er.getLatLng();
window.external.ClickPoint(xlatlng.lat().toString(),xlatlng.lng().toString());
}); return er;
} function createMarker02(point, prompt)
{
var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.shadow = 'http://maps.google.com/mapfiles/arrowshadow.png';
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2); var redIcon = new GIcon(baseIcon);
redIcon.image = 'http://maps.google.com/mapfiles/arrow.png';
erOptions = { icon:redIcon };
var er = new GMarker(point, erOptions);
GEvent.addListener(er, 'mouseover', function() {
er.openInfoWindowHtml(prompt);
}); GEvent.addListener(er, 'click', function(){
window.external.ClickMidPoint(prompt.toString());
}); return er;
} " + allPoint + @" " + allLine + @"
}
} </script>
</head>
<body onload='initialize();' oncontextmenu='event.returnValue=false'> <div id='map' style='width: 950px; height: 525px;'>
</div> </body>
</html>"; wbMap.DocumentText = szWebBrowserText;
}
#endregion这个是C#利用google地图的一小段代码,
Graphics g = e.Grahpics
具体方法上面给出了。
或者在load事件里
Grahpics g = this.CreateGraphics();
或者在某个控件里
Grahpics g = button1.CreateGraphics();
在图片里
Bitmap mybit = new Bitmap(""e:/1.jpg);
graphics g = pictureBox1.CreateGraphics();
是桌面应用程序了,不是GOOGLE的API,只是用的他们的图片而已,就是要在图片上画圆啊
{
Rectangle r=new Rectangle(10,10,10,10); //圆
e.Graphics.DrawEllipse(new Pen(Color.Red),r); //Graphics.DrawEllipse画椭圆
}
e.Graphics.DrawEllipse(new Pen(Color.Red),r); 关键就是得到这个e,看你的图片放在什么地方了,放在picturebox的话,就是paint里话,还要用个变量保存你这些点的信息