covertx 0 Newbie Poster

Hi all, I'm trying to add a little bit of extra functionality to my programme by using the Graphics class to draw lines in accordance to values held within text boxes...

I've converted the values of two textboxes to Int32's like so:

gUK = Convert.ToInt32(tbUK.Text);
gNotUK = Convert.ToInt32(tbNotUK.Text);

(I have code to prevent the conversion occuring if the text boxes contain null values in another part of the programme)

And now I'm drawing the lines:

int total = gUK + gNotUK+400;

            Graphics clear = CreateGraphics();
Graphics graphicsUK = CreateGraphics();
            Graphics graphicsNotUK = CreateGraphics();
            Pen pUK = new Pen(Color.Crimson);
            Pen pNotUK = new Pen(Color.Crimson);
            
            try
            {
                clear.FillRectangle(Brushes.LightGray, ClientRectangle);                
                graphicsUK.DrawRectangle(pUK, 0, 300, 0 + (gNotUK/total), 5);
            }
            catch
            {
                MessageBox.Show("No NotUK number");
            }              
            
            try
            {                
                graphicsNotUK.DrawRectangle(pNotUK, 0, 310, 0 + (gUK/total), 5);
            }
            catch
            {
                MessageBox.Show("No UK number");
            }

As you can see from the code above, I'm comparing the two values gUK and gNotUK. I would like to use an algorithm to do the following:

If for example, the first value is gUK = 1 (assuming that the text box carrying the gNotUK is still null)... gUK is 100% of the total as this is the only value... So I would like a line representing the gUK value as 100%. As soon as the gNotUK has a value (e.g. 1 again) gUK would only be 50% of the total and so the line would be halved and the two lines representing the values would be in line. I've tried numerous algorithms but failed each time!

I'm creating this programme on the assumption that there will be more than 100,000 entries, so this percentage algorithm is particularly important as the lines have to stay within the form...

Thanks for reading!

Rob

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.