关于二维数组排座的问题,有点难

luli327 luli327 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
winform程序,先在form上画坐标

Pen p1 = new Pen(Color.Yellow);
Pen p2 = new Pen(Color.Yellow);
//p1.Width = 1;
//p1.DashCap = DashCap.Triangle;
Graphics g = e.Graphics;
SolidBrush ff = new SolidBrush(Color.Yellow);
// g.FillRectangle(ff, 100, 150, 700, 350);
g.DrawRectangle(p1, 0, 0, 600, 600);

for (int i = 0; i <= 600;)
{
g.DrawLine(p2, new Point(i, 0), new Point(i, 600));
g.DrawLine(p2, new Point(0, i), new Point(600, i));
i = i + 20;
}


然后鼠标点击坐标内的格子,动态生成一个按扭

void Form1_MouseClick(object sender, MouseEventArgs e)
{
AddButton(e.X, e.Y);
}
private void AddButton(int x, int y)
{

Button b = new Button();
b.Width = 20;
b.Height = 20;
b.Location = new System.Drawing.Point((x / 20) * 20, ((y / 20)) * 20);
b.UseVisualStyleBackColor = true;
b.Click += new EventHandler(b_Click);
this.Controls.Add(b);

}

保存排座坐标

Point p;
string txt = string.Empty;
foreach (Control ctrl in this.Controls)
{
if (ctrl.GetType() == typeof(Button))
{
if (((Button)ctrl).Name != "save" && ((Button)ctrl).Name != "read" && ((Button)ctrl).Name != "sort")
{
p = ((Button)ctrl).Location;
txt += p.X / 20 + "|" + p.Y / 20 + "\r\n";
}
}
}
WriteFile(txt);


问题是,如何排座位号,比如,同一行的从左到右或者从右到左按1,2,3,4,5,6排
注:坐标上的行都是未知的
我思考了下 貌似要找到2位数组中相同的行(行未知),再按冒泡排序,但是,我不知道怎么样在2位数组中找到相同的行,这个算法怎么写,高手指点下
...全文

相关推荐

评论 23
收藏 已收藏
分享
返回顶部
luli327
C# 111,130 成员 642,540 内容