Pregunta

Hey all i am trying to add 4 boxes to an image that's 1280 x 720.

I am wanting to add the boxes to the top of the image but space them out evenly across the 1280 width.

Dim g As Graphics = Graphics.FromImage(image)

g.FillRectangle(New SolidBrush(Color.FromArgb(90, 255, 255, 255)), New Rectangle(3, 7, 270, 25)) 'The transparent square for Date
g.DrawString(Format(DateTime.Now, "MM/dd/yyyy HH:mm:ss tt"), New Font("Arial", 18), Brushes.Black, New PointF(3, 5)) 'The date

g.FillRectangle(New SolidBrush(Color.FromArgb(90, 255, 255, 255)), New Rectangle(350, 7, 170, 25)) 'The transparent square for Latitude
g.DrawString("Lat: " & "30.976154", New Font("Arial", 18), Brushes.Black, New PointF(352, 5))

g.FillRectangle(New SolidBrush(Color.FromArgb(90, 255, 255, 255)), New Rectangle(670, 7, 180, 25)) 'The transparent square for longitude
g.DrawString("Lng: " & "33.351328", New Font("Arial", 18), Brushes.Black, New PointF(672, 5))

g.FillRectangle(New SolidBrush(Color.FromArgb(90, 255, 255, 255)), New Rectangle(970, 7, 120, 25)) 'The transparent square for MPH
g.DrawString("MPH: " & "000", New Font("Arial", 18), Brushes.Black, New PointF(972, 5))

g.Dispose()

However i haven't found a sure fire way to making them even across the screen since each rectangle/text is a different width than the ones around it.

Any ideas, thoughts would be great!

¿Fue útil?

Solución

Simply divide the width by the number of labels. Here's some pseudocode:

const int NUM_LABELS = 4; 
int divWidth = width / NUM_LABELS;
int i;
for i = 0 to (NUM_LABELS - 1)
    FillRect(i * divWidth, LABEL_HEIGHT, (i + 1) * divWidth, 0); // or whatever you want to do
    MoveTo (i * divWidth, LABEL_HEIGHT);
    DrawString("some string");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top