Feedback

C# - Fenstertitel im ColorDialog festlegen

Veröffentlicht von am 6/13/2007
(1 Bewertungen)
Mit der Standardkomponente lässt sich der Fenstertitel nicht festlegen. Die Klasse im vorliegenden Code wird von ColorDialog abgeleitet und setzt den Fenstertitel in der Hookprozedur fest. Der Titel selbst wird im Konstruktor übergegeben.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
  public class ColorDialogEx : ColorDialog
  {
    private const Int32 WM_INITDIALOG = 0x0110;

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern bool SetWindowText(IntPtr hWnd, string text);

    private string _Title;

    public ColorDialogEx(string Title)
      : base()
    {
      _Title = Title;
    }

    protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
    {
      if (msg == WM_INITDIALOG)
        SetWindowText(hWnd, _Title);

      return base.HookProc(hWnd, msg, wparam, lparam);
    }
  }
}

Abgelegt unter ColorDialog, Title, Titel, Text, Fenster.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!