다음을 통해 공유


DynamicRenderer.ClipRectangle 속성

업데이트: 2007년 11월

동적으로 렌더링되는 스트로크를 그릴 Rectangle 구조체를 가져오거나 설정합니다.

네임스페이스:  Microsoft.StylusInput
어셈블리:  Microsoft.Ink(Microsoft.Ink.dll)

구문

‘선언
Public Property ClipRectangle As Rectangle
‘사용 방법
Dim instance As DynamicRenderer
Dim value As Rectangle

value = instance.ClipRectangle

instance.ClipRectangle = value
public Rectangle ClipRectangle { get; set; }
public:
property Rectangle ClipRectangle {
    Rectangle get ();
    void set (Rectangle value);
}
/** @property */
public Rectangle get_ClipRectangle()
/** @property */
public  void set_ClipRectangle(Rectangle value)
public function get ClipRectangle () : Rectangle
public function set ClipRectangle (value : Rectangle)

속성 값

형식: System.Drawing.Rectangle
동적으로 렌더링되는 스트로크를 그릴 사각형(픽셀 단위)입니다.

설명

다음 번에 그리는 스트로크에 적용되는 DrawingAttributes 속성과 달리 ClipRectangle 속성은 즉시 설정되어 현재 그리고 있는 스트로크에 적용됩니다. 따라서 스트로크를 그리면서 클립 사각형을 확장할 수 있습니다.

Paint 이벤트 처리기 내에서 DynamicRenderer 개체의 Refresh 메서드를 호출할 때는 DynamicRenderer 개체의 ClipRectangle 속성을 PaintEventArgs 개체의 ClipRectangle 속성으로 설정합니다.

참고

현재로서는 스트로크 중간에 ClipRectangle이 확장된 경우 DynamicRenderer.Refresh를 호출해야 새 잉크가 표시됩니다. 새 영역에 새 잉크가 나타나면 항상 Refresh를 호출해야 하지만 이렇게 하면 새 영역에 잉크를 그릴 때 성능이 저하될 수 있습니다.

예제

이 C# 예제에서는 스트로크가 창의 오른쪽 테두리에 근접하면 폼을 가로 방향으로 확장합니다. 오른쪽 테두리에서 100픽셀 이내에 있는 패킷이 수신되면 창이 100픽셀만큼 확장됩니다. 패킷이 새로 확장된 영역에 포함되어 있으면 DynamicRenderer.Refresh를 호출해야 하고, oldWidth 필드를 사용하여 해당 영역을 추적해야 합니다.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Ink;
using Microsoft.StylusInput;
using Microsoft.StylusInput.PluginData;


namespace TestDynamicRendererClipRectangle
{
    public class Form1 : System.Windows.Forms.Form, Microsoft.StylusInput.IStylusAsyncPlugin
    {
        private RealTimeStylus theRealTimeStylus;
        private DynamicRenderer theDynamicRenderer;
        private Renderer theRenderer;
        private int oldWidth;

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            InitializeComponent();

            theDynamicRenderer = new DynamicRenderer(this);
            theRenderer = new Renderer();

            // Create the real time stylus used to receive stylus notifications
            theRealTimeStylus = new RealTimeStylus(this, true);

            // Add the dynamic renderer to the synchronous plugin notification chain.
            // Synchronous notifications occur on the pen thread.
            theRealTimeStylus.SyncPluginCollection.Add(theDynamicRenderer);

            // Add the form to the asynchronous plugin notification chain.  This plugin
            // will be used to collect stylus data into an ink object.  Asynchronous
            // notifications occur on the UI thread.
            theRealTimeStylus.AsyncPluginCollection.Add(this);

            // Enable the real time stylus and the dynamic renderer
            theRealTimeStylus.Enabled = true;
            theDynamicRenderer.Enabled = true;  
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        // Use the oldWidth field to keep track of where the newly-expanded region is.
        private void Form1_Load(object sender, System.EventArgs e)
        {
            oldWidth = this.Width;
        }

        // Set interest in packets and stylus up
        public DataInterestMask DataInterest
        {
            get
            {
                return DataInterestMask.Packets |
                    DataInterestMask.StylusUp;
            }
        }

        // Check to see if we are drawing near the right side of the form.
        // Remember, this method needs to be "light-weight" in order not to
        // slow performance.
        public void Packets(RealTimeStylus sender, PacketsData data)
        {
            // Find out where we are drawing in pixel space.
            Point location = new Point(data[0], data[1]);
            Graphics formGraphics = this.CreateGraphics();
            theRenderer.InkSpaceToPixel(formGraphics, ref location);
            
            // Check to see if we are 100 pixels from the right edge
            if (this.Right - location.X < 100)
            {
                // Grow the form and the clip rectangle
                this.Width += 100;
                location = new Point(this.Right, this.Bottom);
                theRenderer.PixelToInkSpace(formGraphics, ref location);
                theDynamicRenderer.ClipRectangle = new Rectangle(0, 0, location.X, location.Y);
            }  

            // Currently, we need to call Refresh on the DynamicRenderer if we are in the new
            // region in order for the ink to show up.
            if (location.X >= oldWidth - 100)
            {
                theDynamicRenderer.Refresh();
            }
        }

        // Update the old width each time the stylus comes up
        public void StylusUp(RealTimeStylus sender, StylusUpData data)
        {
            oldWidth = this.Width;
        }

        // The remaining interface methods are not used in this sample application.
        public void CustomStylusDataAdded(RealTimeStylus sender, CustomStylusData data){}
        public void Error(RealTimeStylus sender, ErrorData data){}
        public void InAirPackets(RealTimeStylus sender, InAirPacketsData data){}
        public void RealTimeStylusDisabled(RealTimeStylus sender, RealTimeStylusDisabledData data) {}
        public void RealTimeStylusEnabled(RealTimeStylus sender, RealTimeStylusEnabledData data){}
        public void StylusDown(RealTimeStylus sender, StylusDownData data){}
        public void StylusOutOfRange(RealTimeStylus sender, StylusOutOfRangeData data) {}
        public void StylusInRange(RealTimeStylus sender, StylusInRangeData data) {}
        public void StylusButtonDown(RealTimeStylus sender, StylusButtonDownData data) {}
        public void StylusButtonUp(RealTimeStylus sender, StylusButtonUpData data) {}
        public void SystemGesture(RealTimeStylus sender, SystemGestureData data){}
        public void TabletAdded(RealTimeStylus sender, TabletAddedData data){}
        public void TabletRemoved(RealTimeStylus sender, TabletRemovedData data) {}
    }
}

이 Microsoft Visual Basic .NET 예제에서는 스트로크가 창의 오른쪽 테두리에 근접하면 폼을 가로 방향으로 확장합니다. 오른쪽 테두리에서 100픽셀 이내에 있는 패킷이 수신되면 창이 100픽셀만큼 확장됩니다. 패킷이 새로 확장된 영역에 포함되어 있으면 DynamicRenderer.Refresh를 호출해야 하고, oldWidth 필드를 사용하여 해당 영역을 추적해야 합니다.

Imports Microsoft.Ink
Imports Microsoft.StylusInput

Public Class Form1
    Inherits System.Windows.Forms.Form
    Implements IStylusAsyncPlugin

    Private theRealTimeStylus As RealTimeStylus
    Private theDynamicRenderer As DynamicRenderer
    Private theRenderer As Renderer
    Private oldWidth As Integer

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        Me.theDynamicRenderer = New DynamicRenderer(Me)
        Me.theRenderer = New Renderer()

        ' Create the real time stylus used to receive stylus notifications
        Me.theRealTimeStylus = New RealTimeStylus(Me, True)

        ' Add the dynamic renderer to the synchronous plugin notification chain.
        ' Synchronous notifications occur on the pen thread.
        Me.theRealTimeStylus.SyncPluginCollection.Add(theDynamicRenderer)

        ' Add the form to the asynchronous plugin notification chain.  This plugin
        ' will be used to collect stylus data into an ink object.  Asynchronous
        ' notifications occur on the UI thread.
        Me.theRealTimeStylus.AsyncPluginCollection.Add(Me)


        ' Enable the real time stylus and the dynamic renderer
        Me.theRealTimeStylus.Enabled = True
        Me.theDynamicRenderer.Enabled = True

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
        Me.Text = "Form1"
    End Sub

#End Region

    ' Use the oldWidth field to keep track of where the newly-expanded region is.
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.oldWidth = Me.Width
    End Sub

    ' Set interest in packets and stylus up
    Overridable Overloads ReadOnly Property DataInterest() As DataInterestMask Implements _
      IStylusAsyncPlugin.DataInterest
        Get
            Return DataInterestMask.Packets Or DataInterestMask.StylusUp
        End Get
    End Property

    ' Check to see if we are drawing near the right side of the form.
    ' Remember, this method needs to be "light-weight" in order not to
    ' slow performance.
    Public Sub Packets(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.PacketsData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.Packets
        ' Find out where we are drawing in pixel space.
        Dim location As New Point(data(0), data(1))
        Dim formGraphics As Graphics = Me.CreateGraphics()
        Me.theRenderer.InkSpaceToPixel(formGraphics, location)

        ' Check to see if we are 100 pixels from the right edge
        If Me.Right - location.X < 100 Then
            ' Grow the form and the clip rectangle
            Me.Width = Me.Width + 100
            location = New Point(Me.Right, Me.Bottom)
            Me.theRenderer.PixelToInkSpace(formGraphics, location)
            Me.theDynamicRenderer.ClipRectangle = New Rectangle(0, 0, location.X, location.Y)
        End If

        ' Currently, we need to call Refresh on the DynamicRenderer if we are in the new
        ' region in order for the ink to show up.
        If location.X >= oldWidth - 100 Then
            theDynamicRenderer.Refresh()
        End If
    End Sub

    ' Update the old width each time the stylus comes up
    Public Sub StylusUp(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.StylusUpData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.StylusUp
        Me.oldWidth = Me.Width
    End Sub

    ' The remaining interface methods are not used in this sample application.
    Public Sub CustomStylusDataAdded(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.CustomStylusData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.CustomStylusDataAdded
    End Sub

    Public Sub [Error](ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.ErrorData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.Error
    End Sub

    Public Sub InAirPackets(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.InAirPacketsData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.InAirPackets
    End Sub

    Public Sub RealTimeStylusDisabled(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.RealTimeStylusDisabledData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.RealTimeStylusDisabled
    End Sub

    Public Sub RealTimeStylusEnabled(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.RealTimeStylusEnabledData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.RealTimeStylusEnabled
    End Sub

    Public Sub StylusButtonDown(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.StylusButtonDownData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.StylusButtonDown
    End Sub

    Public Sub StylusButtonUp(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.StylusButtonUpData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.StylusButtonUp
    End Sub

    Public Sub StylusDown(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.StylusDownData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.StylusDown
    End Sub

    Public Sub StylusInRange(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.StylusInRangeData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.StylusInRange
    End Sub

    Public Sub StylusOutOfRange(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.StylusOutOfRangeData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.StylusOutOfRange
    End Sub

    Public Sub SystemGesture(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.SystemGestureData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.SystemGesture
    End Sub

    Public Sub TabletAdded(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.TabletAddedData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.TabletAdded
    End Sub

    Public Sub TabletRemoved(ByVal sender As Microsoft.StylusInput.RealTimeStylus, _
      ByVal data As Microsoft.StylusInput.PluginData.TabletRemovedData) Implements _
      Microsoft.StylusInput.IStylusAsyncPlugin.TabletRemoved
    End Sub

End Class

플랫폼

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

3.0에서 지원

참고 항목

참조

DynamicRenderer 클래스

DynamicRenderer 멤버

Microsoft.StylusInput 네임스페이스