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
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 .