Hoi Allemaal,
Ik ben nieuw met c# en ik probeerde om een smiley te maken. Dit was gelukt, maar daarna wilde ik natuurlijk meer. Door middel van een trackbar wil ik de vrolijkheid van mijn smiley kunnen aanpassen. Helaas lukt het mij niet om dit te doen (weet niet waarom het niet lukt). Zou iemand kunnen kijken wat ik fout doe? PS. Ik weet niet hoe ik mijn code beter kan neerzetten, sorry
Alvast bedankt,
William
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
namespace Test_Windows3
{
class HalloForm : Form
{
TrackBar tbar = new TrackBar();
TextBox tbox = new TextBox();
int testVrolijk;
public HalloForm()
{
this.Text = "Smiley";
this.BackColor = Color.White;
this.Size = new Size(500, 500);
this.Paint += this.tekenScherm;
}
void tekenScherm(object obj, PaintEventArgs pea)
{
//Trackbar
tbar.Location = new System.Drawing.Point(0, 320);
tbar.Height = 40;
tbar.Width = 300;
tbar.Maximum = 100;
tbar.Minimum = -100;
tbar.LargeChange = 10;
tbar.SmallChange = 5;
tbar.TickFrequency = 0;
Controls.Add(tbar);
tbar.Scroll += new System.EventHandler(tbar_Scroll);
tbox.Location = new System.Drawing.Point(400, 16);
tbox.Size = new System.Drawing.Size(48, 20);
Controls.Add(tbox);
this.tekenSmiley(pea.Graphics, 0, 0, 300, 300, Brushes.Blue, Brushes.Black);
}
public void tbar_Scroll(object sender, System.EventArgs e)
{
// Display the trackbar value in the text box.
testVrolijk = tbar.Value;
tbox.Text = "" + testVrolijk;
}
void tekenSmiley(Graphics gr, int x, int y, int width, int height, Brush kleur, Brush oogKleur)
{
//Kijken of het positief of negatief is
int vrolijkBreed;
int vrolijkHoog;
if (testVrolijk < 0) {
vrolijkBreed = -180;
vrolijkHoog = 2;
} else {
vrolijkBreed = 180;
vrolijkHoog = (2 + (testVrolijk/50));
}
Pen blackPen = new Pen(Color.Black, 3);
// Draw ellipse to screen.
gr.DrawEllipse(blackPen, x, y, width, height);
gr.FillEllipse(kleur, x, y, width - 1, height - 1); //Gele kleur
gr.FillEllipse(oogKleur, x+(width / 4), y+(height / 4), (width / 6), (width / 6)); //Linkeroog
gr.FillEllipse(oogKleur,x+(width - (width / 3) - (width/12)), y+(height / 4), (width / 6), (width / 6)); //Rechteroog
gr.DrawArc(Pens.Black, x+(width / 4), y+(height / vrolijkHoog), (width / 2), (int)(height / (4.0 - Math.Abs(testVrolijk)/50.0)), 0, vrolijkBreed); //Mond
}
}
class HalloWin3
{
static void Main()
{
HalloForm scherm;
scherm = new HalloForm();
Application.Run(scherm);
}
}
}
Ik ben nieuw met c# en ik probeerde om een smiley te maken. Dit was gelukt, maar daarna wilde ik natuurlijk meer. Door middel van een trackbar wil ik de vrolijkheid van mijn smiley kunnen aanpassen. Helaas lukt het mij niet om dit te doen (weet niet waarom het niet lukt). Zou iemand kunnen kijken wat ik fout doe? PS. Ik weet niet hoe ik mijn code beter kan neerzetten, sorry

Alvast bedankt,
William
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
namespace Test_Windows3
{
class HalloForm : Form
{
TrackBar tbar = new TrackBar();
TextBox tbox = new TextBox();
int testVrolijk;
public HalloForm()
{
this.Text = "Smiley";
this.BackColor = Color.White;
this.Size = new Size(500, 500);
this.Paint += this.tekenScherm;
}
void tekenScherm(object obj, PaintEventArgs pea)
{
//Trackbar
tbar.Location = new System.Drawing.Point(0, 320);
tbar.Height = 40;
tbar.Width = 300;
tbar.Maximum = 100;
tbar.Minimum = -100;
tbar.LargeChange = 10;
tbar.SmallChange = 5;
tbar.TickFrequency = 0;
Controls.Add(tbar);
tbar.Scroll += new System.EventHandler(tbar_Scroll);
tbox.Location = new System.Drawing.Point(400, 16);
tbox.Size = new System.Drawing.Size(48, 20);
Controls.Add(tbox);
this.tekenSmiley(pea.Graphics, 0, 0, 300, 300, Brushes.Blue, Brushes.Black);
}
public void tbar_Scroll(object sender, System.EventArgs e)
{
// Display the trackbar value in the text box.
testVrolijk = tbar.Value;
tbox.Text = "" + testVrolijk;
}
void tekenSmiley(Graphics gr, int x, int y, int width, int height, Brush kleur, Brush oogKleur)
{
//Kijken of het positief of negatief is
int vrolijkBreed;
int vrolijkHoog;
if (testVrolijk < 0) {
vrolijkBreed = -180;
vrolijkHoog = 2;
} else {
vrolijkBreed = 180;
vrolijkHoog = (2 + (testVrolijk/50));
}
Pen blackPen = new Pen(Color.Black, 3);
// Draw ellipse to screen.
gr.DrawEllipse(blackPen, x, y, width, height);
gr.FillEllipse(kleur, x, y, width - 1, height - 1); //Gele kleur
gr.FillEllipse(oogKleur, x+(width / 4), y+(height / 4), (width / 6), (width / 6)); //Linkeroog
gr.FillEllipse(oogKleur,x+(width - (width / 3) - (width/12)), y+(height / 4), (width / 6), (width / 6)); //Rechteroog
gr.DrawArc(Pens.Black, x+(width / 4), y+(height / vrolijkHoog), (width / 2), (int)(height / (4.0 - Math.Abs(testVrolijk)/50.0)), 0, vrolijkBreed); //Mond
}
}
class HalloWin3
{
static void Main()
{
HalloForm scherm;
scherm = new HalloForm();
Application.Run(scherm);
}
}
}