问题描述
比如:菜单--数值微分(DDA)法点击菜单项“数值微分(DDA)法”时,弹出对话框,通过该对话框用户可以选择“自由划线(通过鼠标来画线),精确划线(通过对话框来输入相应的值)如直线要求输入两端点的xy坐标,然后画出直线。
解决方案
解决方案二:
gdi,gdiplus
解决方案三:
我怎么看不到jinjazz的回帖!!!!!
解决方案四:
to:jinjazz这个我知道的关键是要设计的函数的有哪些
解决方案五:
再弱弱问一句,这个容易实现不?重载的函数涉及哪些?
解决方案六:
一个最简单的例子usingSystem;usingSystem.ComponentModel;usingSystem.Windows.Forms;usingSystem.Drawing;namespaceWindowsApplication4{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatebooldrawing;privatePointpStart;privatevoidForm1_MouseUp(objectsender,MouseEventArgse){this.drawing=!this.drawing;pStart=e.Location;}privatevoidForm1_MouseMove(objectsender,MouseEventArgse){if(this.drawing){using(Graphicsg=this.CreateGraphics()){g.Clear(this.BackColor);g.DrawLine(Pens.Blue,pStart,e.Location);}}}}}
解决方案七:
画图方式:先声明画笔Penmypen=newPen(Color.Black,1);再声明画图的地方:Graphicsgraph=this.CreateGraphics;(this指你要画图的控件,可以使窗体,也可以是别的,很对空间都有CreateGraphics方法)最后画上就行了:graph.DrawLine(mypen,point1,point2);(point是坐标类,也可以用pointf)
解决方案八:
谢谢jinjazz,你给的这个简单例子很像我要实现的“自由画图”的功能。我遇到的问题是弹出对话框的参数进行传递后,如何实现窗体的”精确划线“的功能。具体要调用什么函数?还是感谢jinjazz!!!
解决方案九:
把参数传进来直接g.DrawLine(Pens.Blue,pStart,e.Location)就可以了,你如果理解前面的代码了就不会问这个问题了
解决方案十:
tojinjazz:感谢你耐心回复。我在描述问题方面可能不清楚。参数传递我理解的也能实现。问题是,我不清楚在点击对话框中的确定按钮后,如何在窗体上实现绘制一条直线的功能。也许问题我可以说的更简洁些:点击窗体1中的菜单后窗体2(我说的对话框)出现,点击窗体2的某按钮后,窗体2消失并在窗体1上绘制一条直线。如何设计窗体2的点击事件使得在窗体1上绘制直线呢?
解决方案十一:
你应该先学会基础的窗体交互再去做复杂的事情form1privatevoidbutton1_Click(objectsender,EventArgse){Form2frm=newForm2();if(frm.ShowDialog()==DialogResult.OK){using(Graphicsg=this.CreateGraphics()){g.DrawLine(Pens.Blue,frm.pStart,frm.pEnd);}}}
form2usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceWindowsApplication4{publicpartialclassForm2:Form{publicForm2(){InitializeComponent();}publicPointpStart;publicPointpEnd;privatevoidbutton1_Click(objectsender,EventArgse){pStart=newPoint(100,100);pEnd=newPoint(300,300);this.DialogResult=DialogResult.OK;this.Close();}}}
解决方案十二:
tojinjazz:c#的窗体交互的基础知识哪边有详细介绍?请推荐下c#的好教材。谢谢
解决方案十三:
PublicClassForm1PrivatemMenuAsContextMenuStripPrivatep1,p2AsPointPrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.LoadmMenu=NewContextMenuStripmMenu.Items.Add("自由画线",Nothing,AddressOfMenuItemClick)mMenu.Items.Add("精确画线",Nothing,AddressOfMenuItemClick)Me.ContextMenuStrip=mMenuEndSubPrivateSubMenuItemClick(ByValsenderAsObject,ByValeAsSystem.EventArgs)DimitemAsToolStripMenuItem=CType(sender,ToolStripMenuItem)SelectCaseitem.TextCase"自由画线"CType(mMenu.Items(0),ToolStripMenuItem).Checked=TrueCType(mMenu.Items(1),ToolStripMenuItem).Checked=FalseCase"精确画线"CType(mMenu.Items(0),ToolStripMenuItem).Checked=FalseCType(mMenu.Items(1),ToolStripMenuItem).Checked=TrueDimValueAsString=InputBox("请输入精确画线的两点坐标,格式为:x1,y1-x2,y2","精确画线","10,10-100,100")IfValue<>""ThenDimp()AsString=Value.Split("-")p1=NewPoint(CInt(p(0).Split(",")(0)),CInt(p(0).Split(",")(1)))p2=NewPoint(CInt(p(1).Split(",")(0)),CInt(p(1).Split(",")(1)))Me.CreateGraphics.DrawLine(Pens.Red,p1,p2)EndIfEndSelectEndSubPrivateSubForm1_MouseDown(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.MouseEventArgs)HandlesMe.MouseDownIfCType(mMenu.Items(0),ToolStripMenuItem).CheckedThenIfe.Button=Windows.Forms.MouseButtons.LeftThenp1=e.LocationEndIfEndSubPrivateSubForm1_MouseUp(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.MouseEventArgs)HandlesMe.MouseUpIfCType(mMenu.Items(0),ToolStripMenuItem).CheckedThenIfe.Button=Windows.Forms.MouseButtons.LeftThenp2=e.LocationMe.CreateGraphics.DrawLine(Pens.Red,p1,p2)EndIfEndIfEndSubEndClass
关于详细的鼠标画线请参考