Aplikacje - Visual Studio.pdf
(
456 KB
)
Pobierz
Aplikacje - Visual Studio
Włączanie i wyłączanie programu
Kod programu
// włączanie klakulatora
private void
button1_Click(object sender, EventArgs e)
{
Process.Start("calc");
}
// wyłaczanie programu
private void
button2_Click(object sender, EventArgs e)
{
foreach(var
process
in
Process.GetProcessesByName(comboBox1.Text))
{
process.Kill();
}
}
Aplikacje – Visual Studio
1
Kalkulator – Pensja (salary)
private void
button1_Click(object sender, EventArgs e)
{
try
{
double
salary = Convert.ToDouble(textBox1.Text);
double
taxRate = 0.0;
if
(salary <= 100000)
taxRate = 0.37;
else if
(salary >= 100000.01 && salary <= 250000)
taxRate = 0.44;
else if
(salary >= 250000.01)
taxRate = 0.51;
double
taxDue = salary * taxRate;
taxDue = Math.Round(taxDue);
}
catch(FormatException
ex)
{
MessageBox.Show("Niepoprawny
format");
}
catch(Exception
ex)
{
MessageBox.Show("Inny
wyjątek");
}
textBox2.Text = taxDue.ToString();
}
Aplikacje – Visual Studio
2
Kalkulator prosty
Klasa Math
namespace
ClassLibrary1
{
public class
MyMath
{
public int
Add(int a,
int
b)
{
return
a + b;
}
public int
Sub(int a,
int
b)
{
return
a - b;
}
public int
Mul(int a,
int
b)
{
return
a + b;
}
public double
Div(int a,
int
b)
{
return
a / b;
}
}
}
Wygląd programu
Aplikacje – Visual Studio
3
Cały kod
private void
button1_Click(object sender, EventArgs e)
{
MyMath math =
new
MyMath();
textBox3.Text =
string.Format("a
+ b = {0}",
// Użyjemy string.Format
math.Add(Convert.ToInt32(textBox1.Text),
Convert.ToInt32(textBox2.Text)));
}
private void
button2_Click(object sender, EventArgs e)
{
MyMath math =
new
MyMath();
textBox3.Text =
string.Format("a
- b = {0}",
math.Sub(Convert.ToInt32(textBox1.Text),
Convert.ToInt32(textBox2.Text)));
}
private void
button3_Click(object sender, EventArgs e)
{
MyMath math =
new
MyMath();
textBox3.Text =
string.Format("a
* b = {0}",
math.Mul(Convert.ToInt32(textBox1.Text),
Convert.ToInt32(textBox2.Text)));
}
private void
button4_Click(object sender, EventArgs e)
{
MyMath math =
new
MyMath();
textBox3.Text =
string.Format("a
/ b = {0}",
math.Div(Convert.ToInt32(textBox1.Text),
Convert.ToInt32(textBox2.Text)));
}
Aplikacje – Visual Studio
4
Kalkulator
Wygląd
Cały kod
// dodawanie
private void
buttonAdd_Click(object sender, EventArgs e)
{
if
(textBox1.Text !=
""
&& textBox2.Text !=
"")
{
double
num1 =
double.Parse(textBox1.Text);
double
num2 =
double.Parse(textBox2.Text);
decimal
result = (decimal)num1 + (decimal)num2;
textBox3.Text = result.ToString();
}
else
{
}
}
MessageBox.Show("Oba
pola maja być uzupełnione.");
// odejmowanie
private void
buttonSubtract_Click(object sender, EventArgs e)
{
if
(textBox1.Text !=
""
&& textBox2.Text !=
"")
{
double
num1 =
double.Parse(textBox1.Text);
double
num2 =
double.Parse(textBox2.Text);
decimal
result = (decimal)num1 - (decimal)num2;
textBox3.Text = result.ToString();
}
else
{
}
}
MessageBox.Show("Oba
pola maja być uzupełnione.");
Aplikacje – Visual Studio
5
Plik z chomika:
godor
Inne pliki z tego folderu:
Wielowątkowość w Windows Forms.pdf
(241 KB)
Strumienie i Pliki - Teoria.pdf
(254 KB)
Notatki w bazach danych w C#.pdf
(948 KB)
Język C# - Dodajemy kontrolki w kodzie w Windows Forms.pdf
(493 KB)
Graficzny interfejs użytkownika.pdf
(2136 KB)
Inne foldery tego chomika:
Język C#
Język C# ASP.NET
Programowanie Webowe
Zgłoś jeśli
naruszono regulamin