GrapeCity.Win.Pickers 名前空間 > GcColorPicker クラス : OwnerDraw プロパティ |
次のサンプルコードは、内容がオーナー描画されるGcColorPickerコントロールを作成する方法を示します。この例では、OwnerDrawプロパティをtrueに設定してDrawContentイベントを処理しています。このサンプルコードを実行するには、以下のコードをSystem.Windows.Forms.Formプロジェクトに追加し、ここで作成したメソッドをコンストラクターまたはフォーム上の別のメソッドから呼び出します。
private void CreateOwnerDrawGcColorPicker() { // Create an instance of GcColorPicker control. GcColorPicker gcColorPicker = new GcColorPicker(); // Initialize the Name and Location of the gcColorPicker. gcColorPicker.Name = "gcColorPicker"; gcColorPicker.Location = new Point(10, 50); // Enables the owner draw of gcColorPicker. gcColorPicker.OwnerDraw = true; // Handles the DrawContent event to draw the content of gcColorPicker. gcColorPicker.DrawContent += new EventHandler<DrawContentEventArgs>(GcColorPicker_DrawContent); // adds gcColorPicker to the form. this.Controls.Add(gcColorPicker); } private void GcColorPicker_DrawContent(object sender, DrawContentEventArgs e) { GcColorPicker gcColorPicker = sender as GcColorPicker; // Use the current selected color to fill the content area of gcColorPicker. using (SolidBrush solidBrush = new SolidBrush(gcColorPicker.SelectedColor)) { e.Graphics.FillRectangle(new SolidBrush(gcColorPicker.SelectedColor), e.Bounds); } }
Private Sub CreateOwnerDrawGcColorPicker() ' Create an instance of GcColorPicker control. Dim gcColorPicker As New GcColorPicker() ' Initialize the Name and Location of the gcColorPicker. gcColorPicker.Name = "gcColorPicker" gcColorPicker.Location = New Point(10, 50) ' Enables the owner draw of gcColorPicker. gcColorPicker.OwnerDraw = True ' Handles the DrawContent event to draw the content of gcColorPicker. AddHandler gcColorPicker.DrawContent, AddressOf GcColorPicker_DrawContent ' adds gcColorPicker to the form. Me.Controls.Add(gcColorPicker) End Sub Private Sub GcColorPicker_DrawContent(ByVal sender As Object, ByVal e As DrawContentEventArgs) Dim gcColorPicker As GcColorPicker = TryCast(sender, GcColorPicker) ' Use the current selected color to fill the content area of gcColorPicker. Using solidBrush As New SolidBrush(gcColorPicker.SelectedColor) e.Graphics.FillRectangle(New SolidBrush(gcColorPicker.SelectedColor), e.Bounds) End Using End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2