Tinkering in Windows Forms. According to the results, I will need to have a (mathematical) function to build a graph. In this regard, I want to understand how to depict a point on the form.

    3 answers 3

    Using Bitmap, namely the Bitmap.SetPixel(). function Bitmap.SetPixel().

    But if you want to draw graphics, then this is not the best way. There is a Chart element in Windows Forms. You can use it like this:

     chart->Series[0]->Points->AddXY(x, f(x)); 

    There you can configure the type of interpolation function. I think the spline will be the most suitable for you.

      This answer was in English so

       e.Graphics.FillRectangle(aBrush, x, y, 1, 1); 

        In Windows Forms, the Chart tool is used for plotting. To select the type of "Chart", select in Properties -> Series -> Revenue property -> ChartType. In the drop-down list, select the desired type of chart. We consider the Chart methods using the following code as an example for constructing cosine and sine functions with comments:

         private void buttonCalc_Click(object sender, EventArgs e) { // Π‘Ρ‡ΠΈΡ‚Ρ‹Π²Π°Π΅ΠΌ с Ρ„ΠΎΡ€ΠΌΡ‹ Ρ‚Ρ€Π΅Π±ΡƒΠ΅ΠΌΡ‹Π΅ значСния double Xmin = double.Parse(textBoxXmin.Text); double Xmax = double.Parse(textBoxXmax.Text); double Step = double.Parse(textBoxStep.Text); // ΠšΠΎΠ»ΠΈΡ‡Π΅ΡΡ‚Π²ΠΎ Ρ‚ΠΎΡ‡Π΅ΠΊ Π³Ρ€Π°Ρ„ΠΈΠΊΠ° int count = (int)Math.Ceiling((Xmax - Xmin) / Step) + 1; // Массив Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ X – ΠΎΠ±Ρ‰ΠΈΠΉ для ΠΎΠ±ΠΎΠΈΡ… Π³Ρ€Π°Ρ„ΠΈΠΊΠΎΠ² double[] x = new double[count]; // Π”Π²Π° массива Y – ΠΏΠΎ ΠΎΠ΄Π½ΠΎΠΌΡƒ для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Π³Ρ€Π°Ρ„ΠΈΠΊΠ° double[] y1 = new double[count]; double[] y2 = new double[count]; // РасчитываСм Ρ‚ΠΎΡ‡ΠΊΠΈ для Π³Ρ€Π°Ρ„ΠΈΠΊΠΎΠ² Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ for (int i = 0; i < count; i++) { // ВычисляСм Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ X x[i] = Xmin + Step * i; // ВычисляСм Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΉ Π² Ρ‚ΠΎΡ‡ΠΊΠ΅ X y1[i] = Math.Sin(x[i]); y2[i] = Math.Cos(x[i]); } // НастраиваСм оси Π³Ρ€Π°Ρ„ΠΈΠΊΠ° chart1.ChartAreas[0].AxisX.Minimum = Xmin; chart1.ChartAreas[0].AxisX.Maximum = Xmax; // ΠžΠΏΡ€Π΅Π΄Π΅Π»ΡΠ΅ΠΌ шаг сСтки chart1.ChartAreas[0].AxisX.MajorGrid.Interval = Step; // ДобавляСм вычислСнныС значСния Π² Π³Ρ€Π°Ρ„ΠΈΠΊΠΈ chart1.Series[0].Points.DataBindXY(x, y1); chart1.Series[1].Points.DataBindXY(x, y2); } 

        Here is a link to an example .