作者yauhh (喲)
看板C_Sharp
標題Re: [問題] minimum spanning tree
時間Sun Apr 11 19:59:44 2010
※ 引述《dreamday1023 (也許我就是我,好好愛自己)》之銘言:
: ※ 引述《yauhh (喲)》之銘言:
: 不好意思大大們
: 我想問的的是
: 目前我利用mouseclick在我的form上直接點擊繪畫出"*"的點
: 而現在我希可以將mouseposition.X 存成X[]
: mouseposition.Y 存成Y[](以利minimum spanning tree的計算)
: 而我目前碰的的問題是 必須使用"new關鍵字建立物件執行個體"
: 我想請問在此我必須用new的什麼屬性 來儲存到我的X[]及Y[]
MouseEventArgs e 的e.X和e.Y都是整數,代表滑鼠遊標在Form的位置.
取點的程式大概像這樣:
public partial class Form1 : Form
{
ArrayList points;
public Form1()
{
InitializeComponent();
points = new ArrayList();
}
/* Form1 MouseClick事件 */
private void click_takeGraph(object sender, MouseEventArgs e)
{
int[] point = new int[2];
point[0] = e.X;
point[1] = e.Y;
points.Add(point);
form_showGraph();
}
private void form_showGraph()
{
int[] pt;
msg.Text = "";
foreach (object p in points)
{
pt = (int[]) p;
msg.Text += "(" + pt[0].ToString() + ","
+ pt[1].ToString() + ") ";
}
}
}
接下來你可以想想在表單上拉線要用哪些事件,以及線段如何儲存.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.160.213.121
→ F23ko:等等.... 你的int[] point宣告在方法內的話,出了函式就會 04/11 20:06
→ F23ko:不見了喔 04/11 20:06
→ F23ko:抱歉.... 沒注意到你用ArrayList裝 = =||| 04/11 20:07
→ yauhh:IDE早幫我檢查好了,一點都不必擔心 04/11 20:23
→ ogamenewbie:耶? 沒注意過IDE會檢查scope, 等下來玩看看 04/12 21:59
→ yauhh:不是在講這一回事 04/13 08:16
推 dreamday1023:不好意思喔 當我在mouseclick取的值後 我想在buttom 04/15 01:13
→ dreamday1023:上用 我應該樣把直用在別種物件上呢 04/15 01:13
→ yauhh:我程式中顯示給你看了,取到值之後存進外部變數中,或是放到 04/15 11:25
→ yauhh:別的物件上 04/15 11:26