İngilizce dilinde oku

Aracılığıyla paylaş


TextBoxRenderer Sınıf

Tanım

Metin kutusu denetimini görsel stillerle işlemek için kullanılan yöntemler sağlar. Bu sınıf devralınamaz.

C#
public sealed class TextBoxRenderer
C#
public static class TextBoxRenderer
Devralma
TextBoxRenderer

Örnekler

Aşağıdaki kod örneği, bir metin kutusu çizmek için yöntemini kullanan özel bir denetimin DrawTextBox nasıl oluşturulacağını gösterir. Denetim, kullanıcının metin kutusu metnine uygulanacak değerlerden birini TextFormatFlags seçmesine de olanak tanır.

C#
using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace TextBoxRendererSample
{
    class Form1 : Form
    {
        public Form1()
            : base()
        {
            this.Size = new Size(350, 200);
            CustomTextBox TextBox1 = new CustomTextBox();
            Controls.Add(TextBox1);
        }

        [STAThread]
        static void Main()
        {
            // The call to EnableVisualStyles below does not affect whether 
            // TextBoxRenderer draws the text box; as long as visual styles 
            // are enabled by the operating system, TextBoxRenderer will 
            // draw the text box.
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }
    }

    public class CustomTextBox : Control
    {
        private TextFormatFlags textFlags = TextFormatFlags.Default;
        ComboBox comboBox1 = new ComboBox();
        Rectangle textBorder = new Rectangle();
        Rectangle textRectangle = new Rectangle();
        StringBuilder textMeasurements = new StringBuilder();

        public CustomTextBox()
            : base()
        {
            this.Location = new Point(10, 10);
            this.Size = new Size(300, 200);
            this.Font = SystemFonts.IconTitleFont;
            this.Text = "This is a long sentence that will exceed " +
                "the text box bounds";

            textBorder.Location = new Point(10, 10);
            textBorder.Size = new Size(200, 50);
            textRectangle.Location = new Point(textBorder.X + 2,
                textBorder.Y + 2);
            textRectangle.Size = new Size(textBorder.Size.Width - 4,
                textBorder.Height - 4);

            comboBox1.Location = new Point(10, 100);
            comboBox1.Size = new Size(150, 20);
            comboBox1.SelectedIndexChanged +=
                new EventHandler(comboBox1_SelectedIndexChanged);

            // Populate the combo box with the TextFormatFlags value names.
            foreach (string name in Enum.GetNames(typeof(TextFormatFlags)))
            {
                comboBox1.Items.Add(name);
            }

            comboBox1.SelectedIndex = 0;
            this.Controls.Add(comboBox1);
        }

        // Use DrawText with the current TextFormatFlags.
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (TextBoxRenderer.IsSupported)
            {
                TextBoxRenderer.DrawTextBox(e.Graphics, textBorder, this.Text,
                    this.Font, textRectangle, textFlags, TextBoxState.Normal);

                this.Parent.Text = "CustomTextBox Enabled";
            }
            else
            {
                this.Parent.Text = "CustomTextBox Disabled";
            }
        }

        // Assign the combo box selection to the display text.
        void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.textFlags = (TextFormatFlags)Enum.Parse(
                typeof(TextFormatFlags),
                (string)comboBox1.Items[comboBox1.SelectedIndex]);
            Invalidate();
        }
    }
}

Açıklamalar

sınıfı, TextBoxRenderer bir metin kutusu denetimini işletim sisteminin geçerli görsel stiliyle işlemek için kullanılabilecek bir dizi static yöntem sağlar. Denetimin işlenmesi, denetimin kullanıcı arabirimini çizmeyi ifade eder. Geçerli görsel stilinin görünümüne sahip olması gereken özel bir denetim çiziyorsanız bu yararlı olur. Metin kutusu çizmek için yöntemlerden DrawTextBox birini kullanın. Bu yöntemler, metin biçimlendirmesi uygulama veya metin sınırlarını belirtme gibi çeşitli seçenekler sağlar.

İşletim sisteminde görsel stiller etkinleştirilirse ve uygulama pencerelerinin istemci alanına görsel stiller uygulanırsa, DrawTextBox metin kutusunu geçerli görsel stiliyle çizer. Aksi takdirde, DrawTextBox bir InvalidOperationExceptionoluşturur. Bu sınıfın üyelerinin kullanılıp kullanılamayacağını belirlemek için özelliğinin IsSupported değerini de kontrol edebilirsiniz.

Bu sınıf, sınıfın öğelerinden birine ayarlanmış bir System.Windows.Forms.VisualStyles.VisualStyleRenderer işlevini sarmalar System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox.TextEdit . Daha fazla bilgi için bkz . Görsel Stiller ile İşleme Denetimleri.

Özellikler

IsSupported

Sınıfın TextBoxRenderer görsel stiller içeren bir metin kutusu çizmek için kullanılıp kullanılamayacağını belirten bir değer alır.

Yöntemler

DrawTextBox(Graphics, Rectangle, String, Font, Rectangle, TextBoxState)

Belirtilen durumda ve sınırlarda ve belirtilen metin ve metin sınırlarıyla bir metin kutusu denetimi çizer.

DrawTextBox(Graphics, Rectangle, String, Font, Rectangle, TextFormatFlags, TextBoxState)

Belirtilen durumda ve sınırlarda ve belirtilen metin, metin sınırları ve metin biçimlendirmesiyle bir metin kutusu denetimi çizer.

DrawTextBox(Graphics, Rectangle, String, Font, TextBoxState)

Belirtilen durumda ve sınırlarda ve belirtilen metinle bir metin kutusu denetimi çizer.

DrawTextBox(Graphics, Rectangle, String, Font, TextFormatFlags, TextBoxState)

Belirtilen durumda ve sınırlarda ve belirtilen metin ve metin biçimlendirmesiyle bir metin kutusu denetimi çizer.

DrawTextBox(Graphics, Rectangle, TextBoxState)

Belirtilen durumda ve sınırlarda bir metin kutusu denetimi çizer.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

Ayrıca bkz.