АвтоАвтоматизацияАрхитектураАстрономияАудитБиологияБухгалтерияВоенное делоГенетикаГеографияГеологияГосударствоДомДругоеЖурналистика и СМИИзобретательствоИностранные языкиИнформатикаИскусствоИсторияКомпьютерыКулинарияКультураЛексикологияЛитератураЛогикаМаркетингМатематикаМашиностроениеМедицинаМенеджментМеталлы и СваркаМеханикаМузыкаНаселениеОбразованиеОхрана безопасности жизниОхрана ТрудаПедагогикаПолитикаПравоПриборостроениеПрограммированиеПроизводствоПромышленностьПсихологияРадиоРегилияСвязьСоциологияСпортСтандартизацияСтроительствоТехнологииТорговляТуризмФизикаФизиологияФилософияФинансыХимияХозяйствоЦеннообразованиеЧерчениеЭкологияЭконометрикаЭкономикаЭлектроникаЮриспунденкция

To draw wrapped text in a rectangle with GDI

Читайте также:
  1. How to: Draw Wrapped Text in a Rectangle

· Use the TextFormatFlags enumeration value to specify the text should be wrapped with the DrawText overloaded method, passing the text you want, Rectangle, Font and Color.

string text2 = "Draw text in a rectangle by passing a RectF to the DrawString method."; using (Font font2 = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point)) { Rectangle rect2 = new Rectangle(30, 10, 100, 122);   // Specify the text is wrapped. TextFormatFlags flags = TextFormatFlags.WordBreak; TextRenderer.DrawText(e.Graphics, text2, font2, rect2, Color.Blue, flags); e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(rect2));   }

Compiling the Code

The previous examples require:

· PaintEventArgse, which is a parameter of PaintEventHandler.

 


Рисование текста с переносом по словам в прямоугольнике с помощью GDI

· Используйте значение из перечисления TextFormatFlags, чтобы указать, что при выводе текста с помощью перегруженного метода DrawText текст должен переноситься по словам. При этом методу передаются нужный текст, а также объекты Rectangle, Font и Color.

ß--------

 

Компиляция кода

Для выполнения приведенных примеров требуются следующие компоненты.

· Объект PaintEventArgs e, являющийся параметром обработчика события PaintEventHandler.

 


How to: Draw Text with GDI

With the DrawText method in the TextRenderer class, you can access GDI functionality for drawing text on a form or control. GDI text rendering typically offers better performance and more accurate text measuring than GDI+.

Note:
The DrawText methods of the TextRenderer class are not supported for printing. When printing, always use the DrawString methods of the Graphics class.

Example

The following code example demonstrates how to draw text on multiple lines within a rectangle using the DrawText method.

private void RenderText6(PaintEventArgs e) { TextFormatFlags flags = TextFormatFlags.Bottom | TextFormatFlags.EndEllipsis; TextRenderer.DrawText(e.Graphics, "This is some text that will be clipped at the end.", this.Font, new Rectangle(10, 10, 100, 50), SystemColors.ControlText, flags); }

To render text with the TextRenderer class, you need an IDeviceContext, such as a Graphics and a Font, a location to draw the text, and the color in which it should be drawn. Optionally, you can specify the text formatting by using the TextFormatFlags enumeration.

Compiling the Code

The preceding code example is designed for use with Windows Forms, and it requires the PaintEventArgse, which is a parameter of PaintEventHandler.

 


1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 |

Поиск по сайту:



Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Студалл.Орг (0.003 сек.)