コード例 #1
0
ファイル: Form1.cs プロジェクト: piferrari/QRCode-Csharp
        private void CreateSquares(ByteMatrix byteMatrix, int squareSize)
        {
            squares = new Square[(byteMatrix.Width / squareSize) + 1, (byteMatrix.Height / squareSize) + 1];

            for (int y = 0, cntY = 0; y < byteMatrix.Height; y+=squareSize, cntY++)
            {
                for (int x = 0, cntX = 0; x < byteMatrix.Width; x+=squareSize, cntX++)
                {
                    Color clr;
                    if (byteMatrix.Array[x][y] == 0)
                        clr = Color.Black;
                    else
                        clr = Color.White;

                    squares[cntX, cntY] = new Square(
                        new Size(squareSize, squareSize),
                        new System.Drawing.Point(cntX * squareSize, cntY * squareSize)
                        );
                    squares[cntX, cntY].Color = clr;
                }
            }
        }
コード例 #2
0
ファイル: fmMain.cs プロジェクト: JeromeVancouver/One45
        private void btBrowse_Click(object sender, EventArgs e)
        {
            tbFile.Text = "";
            lbOutput.Items.Clear();
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "*.csv | *.*";
            dialog.InitialDirectory = Directory.GetCurrentDirectory().ToString();
            dialog.Title = "Select CSV File";
            if (dialog.ShowDialog() == DialogResult.OK)
            {

                string filename = dialog.FileName;
                tbFile.Text = filename;
                var reader = new System.IO.StreamReader(File.OpenRead(filename));
                List<string> listA = new List<string>();
                List<string> listB = new List<string>();
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    string output = "Default";
                    if(line.Equals(""))
                    {
                        output = "No Data Found";
                    }
                    else
                    {
                        var values = line.Split(',');
                        string shape = values[0];
                        string length = values[1];
                        double n;
                        bool isNumeric = double.TryParse(length, out n);
                        if (isNumeric)
                        {
                            switch (shape)
                            {
                                case "circle":
                                    Circle c = new Circle(length);
                                    output = c.GetOutput();
                                    break;
                                case "triangle":
                                    Triangle t = new Triangle(length);
                                    output = t.GetOutput();
                                    break;
                                case "square":
                                    Square s = new Square(length);
                                    output = s.GetOutput();
                                    break;
                                case "pentagon":
                                    Pentagon p = new Pentagon(length);
                                    output = p.GetOutput();
                                    break;
                                default:
                                    // You can use the default case.
                                    output = "Shape " + shape + " is not a valid shape";
                                    break;
                            }
                        }
                        else
                            output = "Shape " + shape + " does not have a numeric value ( " +  length + " )";

                    }
                    lbOutput.Items.Add(output);
                }
            }
        }