我想要解决我的问题 [英] I want a solution for my problem

查看:74
本文介绍了我想要解决我的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码允许您选择矩形和方形区域。



但我不希望这些区域发生干扰。



这意味着你无法重新选择该区域。

请求帮助我。



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"


这篇关于我想要解决我的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆