我想要解决我的问题

编程入门 行业动态 更新时间:2024-10-17 18:15:21
本文介绍了我想要解决我的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

此代码允许您选择矩形和方形区域。 但我不希望这些区域发生干扰。 这意味着你无法重新选择该区域。 请求帮助我。

This code allows you to select a rectangular and square areas. But I do not want these areas to interfere. It means you can not re-select the region. pleas help me.

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Random r = new Random(); int x1, y1, tag = 0; int bLeft, bTop; int sLeft, sTop; Button[] q = new Button[84]; Color bc; Color col; private void Form1_Load(object sender, EventArgs e) { int scale = 28; pictureBox1.Width = scale * 35; pictureBox1.Height = scale * 24; Width = pictureBox1.Width + pictureBox1.Left + 17; Height = pictureBox1.Height + pictureBox1.Top + 40; int c = 0; for (int a = 0; a <= 22 * scale; a += 2 * scale) { for (int b = 0; b <= 30 * scale; b += 5 * scale) { q[c] = new Button(); q[c].Left = b; q[c].Top = a; q[c].Width = 5 * scale; q[c].Height = 2 * scale; q[c].MouseDown += new MouseEventHandler(down); q[c].MouseMove += new MouseEventHandler(move); q[c].MouseUp += new MouseEventHandler(up); q[c].Text = (c + 1).ToString(); pictureBox1.Controls.Add(q[c]); c++; } } } void down(Object s, MouseEventArgs e) { col = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256)); Button b = (Button)s; x1 = b.Left; y1 = b.Top; } void move(Object s, MouseEventArgs e) { } void up(object s, MouseEventArgs e) { Button b = (Button)s; int State = 0; if (e.X > 0 && e.Y > 0 ) { State = 1; } else if (e.X < 0 && e.Y > 0) { State = 2; } else if (e.X > 0 && e.Y < 0) { State = 3; } else if (e.X < 0 && e.Y < 0) { State = 4; } if (e.X > 0) { bLeft = b.Left + e.X; sLeft = x1; } else { bLeft = x1; sLeft = b.Left + e.X; } if (e.Y > 0) { bTop = b.Top + e.Y; sTop = y1; } else { bTop = y1; sTop = b.Top + e.Y; } foreach (Button item in q) { switch (State) { case 1: if (item.Left >= sLeft && item.Left <= bLeft && item.Top >= sTop && item.Top <= bTop) { item.BackColor = col; } break; case 2: if (item.Left + item.Width >= sLeft && item.Left <= bLeft && item.Top >= sTop && item.Top <= bTop) { item.BackColor = col; } break; case 3: if (item.Left >= sLeft && item.Left <= bLeft && item.Top + item.Height >= sTop && item.Top <= bTop) { item.BackColor = col; } break; case 4: if (item.Left + item.Width >= sLeft && item.Left <= bLeft && item.Top + item.Height >= sTop && item.Top <= bTop) { item.BackColor = col; } break; default: break; } } Button d = s as Button; Text = (d.Left / 28 * 10).ToString() + " " + (d.Top / 28 * 10).ToString(); int m = Convert.ToInt32((d.Left / 28 * 10)); int n = Convert.ToInt32((d.Top / 28 * 10)); } } }

我尝试过: 此代码允许您选择矩形和方形区域。 但我不希望这些区域发生干扰。 这意味着您无法重新选择该区域。

What I have tried: This code allows you to select a rectangular and square areas. But I do not want these areas to interfere. It means you can not re-select the region.

推荐答案

使用地区类 [ ^ ]它是Intersect方法 - 如果结果区域非空,他们干涉 Use the Region class[^] and it's Intersect method - if the resulting region is non-empty, they "interfere"

更多推荐

我想要解决我的问题

本文发布于:2023-11-01 01:58:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547919.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我想要

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!