none
Tooltip ohne Schlagschatten RRS feed

  • Frage

  • Hallöchen

    ich habe enie kleines Problem. Der Titel verrät es bereits, undzwar möchte ich einfach eine Tooltip ohne Schlagschatten.

    Freue mich auf Antworten.

    Lg Bagerfahrer

    Sonntag, 29. Juli 2012 15:52

Antworten

  • Es tut mir leid aber ich habe es vor eine etwas längeren Zeit gefunden habe. Aber ich kann natürlich den Code selbst reinschreiben, wen es überhaupt erlaubt ist!? Ich habe kein Copyright gefunden im Code.

    FloatControl:

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.IO;
    using System.Runtime.InteropServices;
    
    namespace vbAccelerator.Components.Controls
    {
    
        /// <summary>
        /// An version of a <see cref="System.Windows.Forms.Control"/> 
        /// which can be shown floating, like a tooltip.  If you
        /// want to use Me control in conjunction with mouse events
        /// then you must ensure that the mouse is never in any part of the 
        /// control when it is shown (like a tooltip). Otherwise, 
        /// <see cref="System.Windows.Forms.MouseEnter"/> and 
        /// <see cref="System.Windows.Forms.MouseLeave"/> events
        /// are broken, and the Forms Message Filter
        /// goes into a continuous loop when attempting to show
        /// the control.
        /// </summary>
        public class FloatControl : Control
        {
            [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    
    
            private static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
            [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    
            private static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
    
            private const int WS_EX_TOOLWINDOW = 0x80;
            private const int WS_EX_NOACTIVATE = 0x8000000;
    
            private const int WS_EX_TOPMOST = 0x8;
            private const int WM_NCHITTEST = 0x84;
    
            private const System.Int32 HTTRANSPARENT = (-1);
    
            /// <summary>
            /// Shows the control as a floating Window child 
            /// of the desktop.  To hide the control again,
            /// use the <see cref="Visible"/> property.
            /// </summary>
            public void ShowFloating()
            {
                if ((this.Handle.Equals(IntPtr.Zero)))
                {
                    base.CreateControl();
                }
                SetParent(base.Handle, IntPtr.Zero);
                ShowWindow(base.Handle, 1);
            }
    
            /// <summary>
            /// Get the <see cref="System.Windows.Forms.CreateParams"/>
            /// used to create the control.  Me override adds the
            /// <code>WS_EX_NOACTIVATE</code>, <code>WS_EX_TOOLWINDOW</code>
            /// and <code>WS_EX_TOPMOST</code> extended styles to make
            /// the Window float on top.
            /// </summary>
            protected override System.Windows.Forms.CreateParams CreateParams
            {
                get
                {
                    CreateParams p = base.CreateParams;
                    p.ExStyle = p.ExStyle | (WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST);
                    p.Parent = IntPtr.Zero;
                    return p;
                }
            }
    
    
            /// <summary>
            /// Overrides the standard Window Procedure to ensure the
            /// window is transparent to all mouse events.
            /// </summary>
            /// <param name="m">Windows message to process.</param>
            protected override void WndProc(ref Message m)
            {
                if ((m.Msg == WM_NCHITTEST))
                {
                    m.Result = new IntPtr(HTTRANSPARENT);
                }
                else
                {
                    base.WndProc(ref m);
                }
            }
    
    
            /// <summary>
            /// Overrides the standard painting procedure to render
            /// the text associated with the control.
            /// </summary>
            /// <param name="e">PaintEvent Arguments</param>
            protected override void OnPaint(PaintEventArgs e)
            {
                if ((base.Text.Length > 0))
                {
                    Brush br = new SolidBrush(this.ForeColor);
                    e.Graphics.DrawString(base.Text, this.Font, br, new PointF(1f, 1f));
                    br.Dispose();
                }
                e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, 0, 0, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1);
            }
    
            /// <summary>
            /// Constructs a new instance of Me control.
            /// </summary>
            public FloatControl()
            {
                // intentionally blank
            }
    
        }
    
    }

    Ich hab den Code auch nochmal komplett in VB.Net aber das ist ja der falsche unter Forum.

    Gruss Lervinus


    • Als Antwort markiert Elmar BoyeEditor Mittwoch, 1. August 2012 13:35
    • Bearbeitet Lervinus Montag, 17. November 2014 22:43
    Mittwoch, 1. August 2012 13:18

Alle Antworten

  • Es hat sich erledigt, ich habe einfach einen Control aus dem Internet genommen natürlich OpenSource.

    Lg Bagerfahrer

    Mittwoch, 1. August 2012 09:27
  • Hi,

    und welches Control wäre das? Andere User, die evtl. auch mal sowas suchen, sind sicher froh, wenn Sie den Link dann hier finden.


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community

    Mittwoch, 1. August 2012 09:30
    Moderator
  • Es tut mir leid aber ich habe es vor eine etwas längeren Zeit gefunden habe. Aber ich kann natürlich den Code selbst reinschreiben, wen es überhaupt erlaubt ist!? Ich habe kein Copyright gefunden im Code.

    FloatControl:

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.IO;
    using System.Runtime.InteropServices;
    
    namespace vbAccelerator.Components.Controls
    {
    
        /// <summary>
        /// An version of a <see cref="System.Windows.Forms.Control"/> 
        /// which can be shown floating, like a tooltip.  If you
        /// want to use Me control in conjunction with mouse events
        /// then you must ensure that the mouse is never in any part of the 
        /// control when it is shown (like a tooltip). Otherwise, 
        /// <see cref="System.Windows.Forms.MouseEnter"/> and 
        /// <see cref="System.Windows.Forms.MouseLeave"/> events
        /// are broken, and the Forms Message Filter
        /// goes into a continuous loop when attempting to show
        /// the control.
        /// </summary>
        public class FloatControl : Control
        {
            [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    
    
            private static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
            [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    
            private static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
    
            private const int WS_EX_TOOLWINDOW = 0x80;
            private const int WS_EX_NOACTIVATE = 0x8000000;
    
            private const int WS_EX_TOPMOST = 0x8;
            private const int WM_NCHITTEST = 0x84;
    
            private const System.Int32 HTTRANSPARENT = (-1);
    
            /// <summary>
            /// Shows the control as a floating Window child 
            /// of the desktop.  To hide the control again,
            /// use the <see cref="Visible"/> property.
            /// </summary>
            public void ShowFloating()
            {
                if ((this.Handle.Equals(IntPtr.Zero)))
                {
                    base.CreateControl();
                }
                SetParent(base.Handle, IntPtr.Zero);
                ShowWindow(base.Handle, 1);
            }
    
            /// <summary>
            /// Get the <see cref="System.Windows.Forms.CreateParams"/>
            /// used to create the control.  Me override adds the
            /// <code>WS_EX_NOACTIVATE</code>, <code>WS_EX_TOOLWINDOW</code>
            /// and <code>WS_EX_TOPMOST</code> extended styles to make
            /// the Window float on top.
            /// </summary>
            protected override System.Windows.Forms.CreateParams CreateParams
            {
                get
                {
                    CreateParams p = base.CreateParams;
                    p.ExStyle = p.ExStyle | (WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST);
                    p.Parent = IntPtr.Zero;
                    return p;
                }
            }
    
    
            /// <summary>
            /// Overrides the standard Window Procedure to ensure the
            /// window is transparent to all mouse events.
            /// </summary>
            /// <param name="m">Windows message to process.</param>
            protected override void WndProc(ref Message m)
            {
                if ((m.Msg == WM_NCHITTEST))
                {
                    m.Result = new IntPtr(HTTRANSPARENT);
                }
                else
                {
                    base.WndProc(ref m);
                }
            }
    
    
            /// <summary>
            /// Overrides the standard painting procedure to render
            /// the text associated with the control.
            /// </summary>
            /// <param name="e">PaintEvent Arguments</param>
            protected override void OnPaint(PaintEventArgs e)
            {
                if ((base.Text.Length > 0))
                {
                    Brush br = new SolidBrush(this.ForeColor);
                    e.Graphics.DrawString(base.Text, this.Font, br, new PointF(1f, 1f));
                    br.Dispose();
                }
                e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, 0, 0, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1);
            }
    
            /// <summary>
            /// Constructs a new instance of Me control.
            /// </summary>
            public FloatControl()
            {
                // intentionally blank
            }
    
        }
    
    }

    Ich hab den Code auch nochmal komplett in VB.Net aber das ist ja der falsche unter Forum.

    Gruss Lervinus


    • Als Antwort markiert Elmar BoyeEditor Mittwoch, 1. August 2012 13:35
    • Bearbeitet Lervinus Montag, 17. November 2014 22:43
    Mittwoch, 1. August 2012 13:18
  • Hallo Christoph,

    wenn die Basis von vbAccelerator.com stammt, wie der Namespace vermuten lässt,
    gilt hier: http://www.vbaccelerator.com/home/The_Site/Usage_Policy/article.asp

    Gruß Elmar

    Mittwoch, 1. August 2012 13:35
    Beantworter