wesley

if/else and then graphic

2 posts in this topic

Hey,

I'm working with C # and with an if / else statement. But this does not work.
With the count you count function the amount of rows in the listbox.

The idea is if there are five or fewer rows that one oval (graphic) will be placed and if six or more rows than will show up a different graphic.
This does not work because the oval there always will be placed and the other graphic is never executed.

My question is: how can I get if / else working?

thank you in advance.

my code is:

private void pnlStatus_Paint(object sender, PaintEventArgs e)
    {
        int aantal = haven.Schepen.Count;
        int number = 5;
        if (aantal <= number)
        {
            Graphics g = e.Graphics;                
            int breedte = 50;
            int hoogte = 50;
            g.FillEllipse(Brushes.Green, 10, 10, breedte, hoogte);
        }
        else
        {
            Graphics gr = e.Graphics;
            using (Pen p = new Pen(Color.Red, 5))
            {
                gr.DrawLine(p, 0, 0, 50, 50);
                gr.DrawLine(p, 0, 50, 50, 0);
            }
        }
    }

//In the class haven is this the list
public List<Schip> Schepen { get { return schepen; } }
1 person likes this

Share this post


Link to post
Share on other sites

It sounds like aantal is always less than or equal to number. It would be easy enough to print the values to verify that. Maybe there's something wrong with the value you're getting for aantal.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now