Ahojte
V kode vid. nizsie chcem zobrazit vypocet S = 3.14 * (r * r); v textboxe "TbObsahKruhu". Akosy to nejde. Neviete prosim vas poradit preco. Diki vopred za odpovede.
using System;
using System.Drawing;
using System.Windows.Forms;
public partial class PlochaKruhu : Form
{
double r;
double S;
public static void Main()
{
Application.Run(new PlochaKruhu());
}
public PlochaKruhu()
{
Text = "Výpočet obsahu kruhu";
BackColor = SystemColors.Window;
ForeColor = SystemColors.WindowText;
ClientSize = new Size(500, 500);
MaximizeBox = false;
FormBorderStyle = FormBorderStyle.Fixed3D;
GroupBox GbZadanie = new GroupBox();
GbZadanie.Parent = this;
GbZadanie.Text = "Zadanie:";
GbZadanie.Location = new Point(20, 20);
TextBox TbPolomerKruhu = new TextBox();
TbPolomerKruhu.Location = new Point(7, 46);
TbPolomerKruhu.Parent = GbZadanie;
Label PolomerKruhu = new Label();
PolomerKruhu.Parent = GbZadanie;
PolomerKruhu.Location = new Point(7, 28);
PolomerKruhu.AutoSize = true;
PolomerKruhu.Text = "Polomer kruhu - r[m]:";
Button PolomerHelp = new Button();
PolomerHelp.Parent = GbZadanie;
PolomerHelp.Location = new Point(116, 44);
PolomerHelp.AutoSize = true;
PolomerHelp.Text = "? r[m]";
PolomerHelp.Click += new EventHandler(PolomerHelp_Click);
GroupBox GbVysledok = new GroupBox();
GbVysledok.Parent = this;
GbVysledok.Text = "Výsledok";
GbVysledok.Location = new Point(280, 20);
TextBox TbObsahKruhu = new TextBox();
TbObsahKruhu.Location = new Point(7, 46);
TbObsahKruhu.Parent = GbVysledok;
TbObsahKruhu.AutoSize = true;
TbObsahKruhu.ReadOnly = true;
TbObsahKruhu.Text = S.ToString("#.##");
r = 5;
S = 3.14 * (r * r);
Label ObsahKruhu = new Label();
ObsahKruhu.Location = new Point(7, 28);
ObsahKruhu.Parent = GbVysledok;
ObsahKruhu.AutoSize = true;
ObsahKruhu.Text = "Obsah kruhu - S[m2]:";
Button ButtonObsahKruhu = new Button();
ButtonObsahKruhu.Parent = GbVysledok;
ButtonObsahKruhu.Location = new Point(116, 44);
ButtonObsahKruhu.AutoSize = true;
ButtonObsahKruhu.Text = "? S[m2]";
ButtonObsahKruhu.Click += new EventHandler(ButtonObsahKruhu_Click);
GroupBox GbGrafickeVykreslenie = new GroupBox();
GbGrafickeVykreslenie.Parent = this;
GbGrafickeVykreslenie.Text = "Grafické vykreslenie";
GbGrafickeVykreslenie.Location = new Point(20, 140);
GbGrafickeVykreslenie.Size = new Size(460, 340);
GbGrafickeVykreslenie.Paint += new PaintEventHandler(GbGrafickeVykreslenieOnPaint);
Button ButtonVypocitaj = new Button();
ButtonVypocitaj.Parent = GbZadanie;
ButtonVypocitaj.Text = "Vypočítaj";
ButtonVypocitaj.Location = new Point(116, 70);
ButtonVypocitaj.AutoSize = true;
}
void GbGrafickeVykreslenieOnPaint(object obj, PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
Pen pen = new Pen(ForeColor);
grfx.FillEllipse(Brushes.YellowGreen, 90, 37, 270, 270);
Point StredKruznice;
StredKruznice = new Point(225, 172);
Rectangle PravouholnikStredu = new Rectangle(StredKruznice, Size.Empty);
PravouholnikStredu.Inflate(2, 2);
grfx.FillEllipse(Brushes.Black, PravouholnikStredu);
grfx.DrawLine(pen, 225, 172, 360, 172);
grfx.DrawString("r = 5 m", Font, Brushes.Black, 265, 155);
grfx.DrawString("S = π x r2 = 78.5 m2", Font, Brushes.Black, 180, 230);
}
void ButtonObsahKruhu_Click(object obj, EventArgs pea)
{
MessageBox.Show("Obsah kruhu sa vypočíta: S = π x r2[m2] , kde π = 3,14 a je to Ludolfovo " +
"číslo.\nr - polomer kruhu[m].", "Výpočet obsahu kruhu", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
void PolomerHelp_Click(object obj, EventArgs pea)
{
MessageBox.Show("r = d / 2[m], kde d - priemer kruhu.", "Výpočet obsahu kruhu", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}