How to arrangement of points on the chart in check

2019-09-14 18:43发布

I'm trying to make a chart in checkerboard (as pictured in the screenshot), but I can not think of an algorithm for its construction. How can I change my algorithm so that I can build it?

            // location for the first point
            double x = FirstStationX;
            double y = FirstStationY;
            double x1 = 0, y1 = 0;
            // button separation inline
            double spacingX = InlineStations * (InlineSpacing - 1);
            // button separation crossline
            double spacingY = CrosslineStations * (CrosslineSpacing - 1);
            // Cycle by number of blocks (buttons) along the X axis
            for (int i = 0; i < InlineButtons; i++)
            {
                if (i > 0) x = x1 + spacingX + InlineSeparation;
                // Cycle by number of blocks (buttons) along the Y axis
                for(int j = 0; j < CrosslineButtons; j++)
                {
                    if (j > 0)
                    {
                        y = y1 + spacingY + CrosslineSeparation;
                    }
                    // Cycle by number of point in buttons along the X axis
                    for(int k = 0; k < InlineStations; k++)
                    {
                        if (k == 0) x1 = x;
                        else x1 = x1 + InlineSpacing;
                        // Cycle by number of point in buttons along the Y axis
                        for(int h = 0; h < CrosslineStations; h++)
                        {
                            if (h == 0) y1 = y;
                            else y1 = y1 + CrosslineSpacing;
                            listPointsButtonStation.Add(new ObservablePoint(x1, y1));
                        }
                    }
                }
            }

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-14 19:12

Try code like this

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication26
{
    public partial class Form1 : Form
    {
        const string IMAGE_FILENAME = @"c:\temp\image1.jpg";

        const int NUMBER_OF_CHART_COLUMNS = 8;
        const int NUMBER_OF_CHART_ROWS = 8;
        const int MAIN_PANEL_TOP = 20;
        const int MAIN_PANEL_LEFT = 20;
        const int MAIN_PANEL_WIDTH = 1000;
        const int MAIN_PANEl_HEIGHT = 1000;

        const int CHART_LEFT = 20;
        const int CHART_TOP = 20;
        const int CHART_WIDTH = 100;
        const int CHART_HEIGHT = 100;
        const int CHART_SPACE = 10;


        List<MyChart> charts = new List<MyChart>();
        public Form1()
        {
            InitializeComponent();

            Panel mainPanel = new Panel();
            mainPanel.Left = MAIN_PANEL_LEFT;
            mainPanel.Top = MAIN_PANEL_TOP;
            mainPanel.Height = MAIN_PANEl_HEIGHT;
            mainPanel.Width = MAIN_PANEL_WIDTH;

            this.Controls.Add(mainPanel);

            for(int row = 0; row < NUMBER_OF_CHART_ROWS; row++)
            {
                for (int col = 0; col < NUMBER_OF_CHART_COLUMNS; col++)
                {
                    MyChart newChart = new MyChart();
                    newChart.row = row;
                    newChart.col = col;

                    newChart.Width = CHART_WIDTH;
                    newChart.Height = CHART_HEIGHT;

                    newChart.Left = col * (CHART_WIDTH + CHART_SPACE);
                    newChart.Top = row * (CHART_HEIGHT + CHART_SPACE);

                    newChart.Image = Image.FromFile(IMAGE_FILENAME);

                    mainPanel.Controls.Add(newChart);
                    charts.Add(newChart);
                }
            }
        }

    }
    public class MyChart : PictureBox 
    {
        public int row { get; set; }
        public int col { get; set; }
    }
}
查看更多
登录 后发表回答