BehaviorService 클래스

정의

디자이너의 사용자 인터페이스를 관리합니다. 이 클래스는 상속될 수 없습니다.

C#
public sealed class BehaviorService : IDisposable
상속
BehaviorService
구현

예제

다음 코드 예제에서는 사용자 클릭에 응답 하는 고유한 Behavior 기반 클래스를 만드는 방법을 보여 줍니다.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Text;
using System.Windows.Forms.Design;
using System.Windows.Forms.Design.Behavior;

namespace BehaviorServiceSample
{
    class Form1 : Form
    {
        private UserControl1 userControl;

        public Form1()
        {
            InitializeComponent();
        }

        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.userControl = new BehaviorServiceSample.UserControl1();
            this.SuspendLayout();

            this.userControl.Location = new System.Drawing.Point(12, 13);
            this.userControl.Name = "userControl";
            this.userControl.Size = new System.Drawing.Size(143, 110);
            this.userControl.TabIndex = 0;
            
            this.ClientSize = new System.Drawing.Size(184, 153);
            this.Controls.Add(this.userControl);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
        }

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }
    }

    [Designer(typeof(MyDesigner))]
    public class UserControl1 : UserControl
    {
        private System.ComponentModel.IContainer components = null;

        public UserControl1()
        {
            InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.Name = "UserControl1";
            this.Size = new System.Drawing.Size(170, 156);
        }
    }

    class MyDesigner : ControlDesigner
    {
        private Adorner myAdorner;

        protected override void Dispose(bool disposing)
        {
            if (disposing && myAdorner != null)
            {
                BehaviorService b = BehaviorService;
                if (b != null)
                {
                    b.Adorners.Remove(myAdorner);
                }
            }
        }

        public override void Initialize(IComponent component)
        {
            base.Initialize(component);

            // Add the custom set of glyphs using the BehaviorService. 
            // Glyphs live on adornders.
            myAdorner = new Adorner();
            BehaviorService.Adorners.Add(myAdorner);
            myAdorner.Glyphs.Add(new MyGlyph(BehaviorService, Control));
        }
    }

    class MyGlyph : Glyph
    {
        Control control;
        BehaviorService behaviorSvc;

        public MyGlyph(BehaviorService behaviorSvc, Control control) : 
            base(new MyBehavior())
        {
            this.behaviorSvc = behaviorSvc;
            this.control = control;
        }

        public override Rectangle Bounds
        {
            get
            {
                // Create a glyph that is 10x10 and sitting
                // in the middle of the control.  Glyph coordinates
                // are in adorner window coordinates, so we must map
                // using the behavior service.
                Point edge = behaviorSvc.ControlToAdornerWindow(control);
                Size size = control.Size;
                Point center = new Point(edge.X + (size.Width / 2), 
                    edge.Y + (size.Height / 2));

                Rectangle bounds = new Rectangle(
                    center.X - 5,
                    center.Y - 5,
                    10,
                    10);

                return bounds;
            }
        }

        public override Cursor GetHitTest(Point p)
        {
            // GetHitTest is called to see if the point is
            // within this glyph.  This gives us a chance to decide
            // what cursor to show.  Returning null from here means
            // the mouse pointer is not currently inside of the glyph.
            // Returning a valid cursor here indicates the pointer is
            // inside the glyph, and also enables our Behavior property
            // as the active behavior.
            if (Bounds.Contains(p))
            {
                return Cursors.Hand;
            }

            return null;
        }

        public override void Paint(PaintEventArgs pe)
        {
            // Draw our glyph. It is simply a blue ellipse.
            pe.Graphics.FillEllipse(Brushes.Blue, Bounds);
        }

        // By providing our own behavior we can do something interesting
        // when the user clicks or manipulates our glyph.
        class MyBehavior : Behavior
        {
            public override bool OnMouseUp(Glyph g, MouseButtons button)
            {
                MessageBox.Show("Hey, you clicked the mouse here");
                return true; // indicating we processed this event.
            }
        }
    }
}

설명

BehaviorService 만들어지면 디자이너 프레임 위에 투명한 창이 추가됩니다. 그런 다음 이 BehaviorService 창을 사용하여 개체라고 하는 Glyph 사용자 인터페이스 요소를 렌더링하고 모든 마우스 메시지를 catch할 수 있습니다. 이러한 방식으로 는 디자이너 동작을 BehaviorService 제어할 수 있습니다.

클래스는 BehaviorService 개체를 푸시할 수 있는 Behavior 동작 스택을 지원합니다. 투명 창을 BehaviorService 통해 메시지를 가로채면 는 스택 맨 위에 있는 에 메시지를 Behavior 보낼 수 있습니다. 이렇게 하면 현재 푸시된 에 따라 다른 사용자 인터페이스 모드를 Behavior사용할 수 있습니다. 는 BehaviorService 선택 테두리, 크기 조정 핸들 및 스마트 태그와 같은 모든 Glyph 개체를 렌더링하는 데 사용됩니다. 또한 는 BehaviorService 맞춤선 사용, 끌기 및 선택과 같은 많은 디자인 타임 동작을 제어합니다.

자세한 내용은 동작 서비스 개요를 참조하세요.

속성

Adorners

BehaviorServiceAdornerCollection를 가져옵니다.

AdornerWindowGraphics

표시기(Adorner) 창의 Graphics를 가져옵니다.

CurrentBehavior

동작 스택의 맨 위에서 Behavior를 제거하지 않고 가져옵니다.

메서드

AdornerWindowPointToScreen(Point)

표시기 창의 Point를 화면 좌표로 변환합니다.

AdornerWindowToScreen()

화면 좌표에서 표시기 창 위치를 가져옵니다.

ControlRectInAdornerWindow(Control)

Rectangle의 경계 Control을 반환합니다.

ControlToAdornerWindow(Control)

표시기 창 좌표로 변환된 Control의 위치를 반환합니다.

Dispose()

BehaviorService에서 사용하는 모든 리소스를 해제합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetNextBehavior(Behavior)

동작 스택에서 지정된 Behavior 바로 다음에 있는 Behavior를 반환합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
Invalidate()

BehaviorService의 표시기 창을 무효화합니다.

Invalidate(Rectangle)

표시기 창 내에서 BehaviorService의 지정된 영역을 무효화합니다.

Invalidate(Region)

표시기 창 내에서 BehaviorService의 지정된 영역을 무효화합니다.

MapAdornerWindowPoint(IntPtr, Point)

핸들 좌표계 위치를 표시기 창 좌표로 변환합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
PopBehavior(Behavior)

스택의 맨 위에서 Behavior를 제거하고 반환합니다.

PushBehavior(Behavior)

Behavior를 동작 스택에 푸시합니다.

PushCaptureBehavior(Behavior)

Behavior를 동작 스택에 푸시하고 동작에 마우스 캡처를 할당합니다.

ScreenToAdornerWindow(Point)

화면 좌표 위치를 BehaviorService의 표시기 창 좌표로 변환합니다.

SyncSelection()

모든 선택 문자 모양을 동기화합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

이벤트

BeginDrag

BehaviorService에서 끌어서 놓기 작업을 시작할 때 발생합니다.

EndDrag

BehaviorService에서 끌기 작업을 완료할 때 발생합니다.

Synchronize

현재 선택 내용을 새로 고쳐야 할 경우에 발생합니다.

적용 대상

제품 버전
.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, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

추가 정보