İngilizce dilinde oku

Aracılığıyla paylaş


CheckBoxRenderer Sınıf

Tanım

Onay kutusu denetimini görsel stillerle veya stiller olmadan işlemek için kullanılan yöntemleri sağlar. Bu sınıf devralınamaz.

C#
public sealed class CheckBoxRenderer
C#
public static class CheckBoxRenderer
Devralma
CheckBoxRenderer

Örnekler

Aşağıdaki kod örneği, fare tıklamalarına yanıt veren bir onay kutusu çizmek için yöntemini kullanan DrawCheckBox özel bir denetimin nasıl yazıldığını gösterir.

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

namespace CheckBoxRendererSample
{
    class Form1 : Form
    {
        public Form1()
            : base()
        {
            CustomCheckBox CheckBox1 = new CustomCheckBox();
            Controls.Add(CheckBox1);

            if (Application.RenderWithVisualStyles)
                this.Text = "Visual Styles Enabled";
            else
                this.Text = "Visual Styles Disabled";
        }

        [STAThread]
        static void Main()
        {
            // If you do not call EnableVisualStyles below, then 
            // CheckBoxRenderer.DrawCheckBox automatically detects 
            // this and draws the check box without visual styles.
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }
    }

    public class CustomCheckBox : Control
    {
        private Rectangle textRectangleValue = new Rectangle();
        private Point clickedLocationValue = new Point();
        private bool clicked = false;
        private CheckBoxState state = CheckBoxState.UncheckedNormal;

        public CustomCheckBox()
            : base()
        {
            this.Location = new Point(50, 50);
            this.Size = new Size(100, 20);
            this.Text = "Click here";
            this.Font = SystemFonts.IconTitleFont;
        }

        // Calculate the text bounds, exluding the check box.
        public Rectangle TextRectangle
        {
            get
            {
                using (Graphics g = this.CreateGraphics())
                {
                    textRectangleValue.X = ClientRectangle.X +
                        CheckBoxRenderer.GetGlyphSize(g,
                        CheckBoxState.UncheckedNormal).Width;
                    textRectangleValue.Y = ClientRectangle.Y;
                    textRectangleValue.Width = ClientRectangle.Width -
                        CheckBoxRenderer.GetGlyphSize(g,
                        CheckBoxState.UncheckedNormal).Width;
                    textRectangleValue.Height = ClientRectangle.Height;
                }

                return textRectangleValue;
            }
        }

        // Draw the check box in the current state.
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            CheckBoxRenderer.DrawCheckBox(e.Graphics,
                ClientRectangle.Location, TextRectangle, this.Text,
                this.Font, TextFormatFlags.HorizontalCenter,
                clicked, state);
        }

        // Draw the check box in the checked or unchecked state, alternately.
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (!clicked)
            {
                clicked = true;
                this.Text = "Clicked!";
                state = CheckBoxState.CheckedPressed;
                Invalidate();
            }
            else
            {
                clicked = false;
                this.Text = "Click here";
                state = CheckBoxState.UncheckedNormal;
                Invalidate();
            }
        }

        // Draw the check box in the hot state. 
        protected override void OnMouseHover(EventArgs e)
        {
            base.OnMouseHover(e);
            state = clicked ? CheckBoxState.CheckedHot :
                CheckBoxState.UncheckedHot;
            Invalidate();
        }

        // Draw the check box in the hot state. 
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            this.OnMouseHover(e);
        }

        // Draw the check box in the unpressed state.
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            state = clicked ? CheckBoxState.CheckedNormal :
                CheckBoxState.UncheckedNormal;
            Invalidate();
        }
    }
}

Açıklamalar

sınıfı, CheckBoxRenderer onay kutusu denetimini işlemek için kullanılabilecek bir yöntem kümesi static sağlar. Denetimin işlenmesi, denetimin kullanıcı arabirimini çizmeyi ifade eder. Onay kutusu çizmek için yöntemlerden birini DrawCheckBox kullanın. Bu yöntemler metin çizme veya onay kutusu içeren bir resim gibi çeşitli seçenekler sağlar.

İşletim sisteminde görsel stiller etkinleştirilirse ve geçerli uygulamaya görsel stilleri uygulanırsa, DrawCheckBox geçerli görsel stiliyle onay kutusunu çizer. Aksi takdirde, DrawCheckBox onay kutusunu klasik Windows stiliyle çizer. bu, işletim sisteminin geçerli görsel stili ayarıyla otomatik olarak eşleşmesi gereken özel bir denetim çiziyorsanız kullanışlıdır.

Bu sınıf, sınıfı tarafından kullanıma sunulan öğelerden birine ayarlanan bir System.Windows.Forms.VisualStyles.VisualStyleRenderer işlevini sarmalar System.Windows.Forms.VisualStyles.VisualStyleElement.Button.CheckBox . Daha fazla bilgi için bkz . Görsel Stiller ile Denetimleri İşleme.

Özellikler

RenderMatchingApplicationState

İşleyicinin işleme stilini belirlemek için uygulama durumunu kullanıp kullanmadığını belirten bir değer alır veya ayarlar.

Yöntemler

DrawCheckBox(Graphics, Point, CheckBoxState)

Belirtilen durumda ve konumda bir onay kutusu denetimi çizer.

DrawCheckBox(Graphics, Point, Rectangle, String, Font, Boolean, CheckBoxState)

Belirtilen durumda ve konumda, belirtilen metinle ve isteğe bağlı bir odak dikdörtgeniyle bir onay kutusu denetimi çizer.

DrawCheckBox(Graphics, Point, Rectangle, String, Font, Image, Rectangle, Boolean, CheckBoxState)

Belirtilen durumda ve konumda, belirtilen metin ve görüntüyle ve isteğe bağlı bir odak dikdörtgeniyle bir onay kutusu denetimi çizer.

DrawCheckBox(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Boolean, CheckBoxState)

Belirtilen durumda ve konumda, belirtilen metin ve metin biçimlendirmesiyle ve isteğe bağlı bir odak dikdörtgeniyle bir onay kutusu denetimi çizer.

DrawCheckBox(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, CheckBoxState)

Belirtilen durumda ve konumda bir onay kutusu denetimi çizer; belirtilen metin, metin biçimlendirmesi ve resimle; ve isteğe bağlı bir odak dikdörtgeni ile.

DrawParentBackground(Graphics, Rectangle, Control)

Belirtilen alanda denetimin üst öğesinin arka planını çizer.

GetGlyphSize(Graphics, CheckBoxState)

Onay kutusu karakteri boyutunu döndürür.

IsBackgroundPartiallyTransparent(CheckBoxState)

Onay kutusunun arka planının yarı saydam mı yoksa alfa karışık parçalar mı olduğunu gösterir.

Ş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.