Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
Cómo calcular el tamaño de un fragmento de texto en Win2D

Estoy escribiendo una aplicación para Windows 10 usando Win2D y estoy tratando de dibujar una forma que se escala dinámicamente para adaptarse a cualquier texto que se encuentre en ella.

Lo que me gustaría hacer es calcular qué tan grande sería una cadena en particular con un CanvasTextFormat dado y luego usarlo para establecer el tamaño de la forma.

Mi problema es que parece que no puedo encontrar una manera de calcular qué tan grande será la cuerda.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Consulte el código a continuación para calcular el tamaño requerido (busque "theRectYouAreLookingFor")

 private void CanvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args) { CanvasDrawingSession drawingSession = args.DrawingSession; float xLoc = 100.0f; float yLoc = 100.0f; CanvasTextFormat format = new CanvasTextFormat {FontSize = 30.0f, WordWrapping = CanvasWordWrapping.NoWrap}; CanvasTextLayout textLayout = new CanvasTextLayout(drawingSession, "Hello World!", format, 0.0f, 0.0f); Rect theRectYouAreLookingFor = new Rect(xLoc + textLayout.DrawBounds.X, yLoc + textLayout.DrawBounds.Y, textLayout.DrawBounds.Width, textLayout.DrawBounds.Height); drawingSession.DrawRectangle(theRectYouAreLookingFor, Colors.Green, 1.0f); drawingSession.DrawTextLayout(textLayout, xLoc, yLoc, Colors.Yellow); }
over 4 years ago · Santiago Trujillo Report

0

Si crea un CanvasTextLayout con un ancho requestedWidth de 0 , como en el ejemplo de Michael Vach , es posible que desee deshabilitar Word Wrap en Win2D 1.23. Me gusta:

 var textLayout = new CanvasTextLayout(drawingSession, "Hello World!", fontFormat, 0.0f, 0.0f) { WordWrapping = CanvasWordWrapping.NoWrap }; var completeOuterSize = textLayout.LayoutBounds

(No tengo permitido comentar)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!