예제 #1
0
        //---------------------------------------------------------------------------
        public void SetImage
        (
            Bitmap[] images,
            Alignment align,
            int leftMargin, int topMargin, int rightMargin, int bottomMargin
        )
        {
            if (ComCtlMajorVersion < 0)
            {
                DLLVERSIONINFO dllVersion = new DLLVERSIONINFO();
                dllVersion.cbSize = Marshal.SizeOf(typeof(DLLVERSIONINFO));
                GetCommonControlDLLVersion(ref dllVersion);
                ComCtlMajorVersion = dllVersion.dwMajorVersion;
            }

            if (ComCtlMajorVersion >= 6 && FlatStyle == FlatStyle.System)
            {
                RECT rect = new RECT();
                rect.left   = leftMargin;
                rect.top    = topMargin;
                rect.right  = rightMargin;
                rect.bottom = bottomMargin;

                BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST();
                buttonImageList.margin = rect;
                buttonImageList.uAlign = (int)align;

                ImageList            = GenerateImageList(images);
                buttonImageList.himl = ImageList.Handle;

                SendMessage(this.Handle, BCM_SETIMAGELIST, 0, ref buttonImageList);
            }
            else
            {
                FlatStyle = FlatStyle.Standard;

                if (images.Length > 0)
                {
                    Image = images[0];
                }
            }
        }
예제 #2
0
 public static extern IntPtr SendMessage(HWND hWnd, ButtonMessage Msg, int wParam, ref BUTTON_IMAGELIST imageList);
예제 #3
0
 /// <summary>
 /// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return
 /// until the window procedure has processed the message.
 /// </summary>
 /// <param name="hWnd">
 /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST ((HWND)0xffff), the message is sent to
 /// all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not
 /// sent to child windows.
 /// </param>
 /// <param name="Msg">The message to be sent.</param>
 /// <param name="wParam">Additional message-specific information.</param>
 /// <param name="imageList">Additional message-specific information.</param>
 /// <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
 public static IntPtr SendMessage(HandleRef hWnd, ButtonMessage Msg, int wParam, ref BUTTON_IMAGELIST imageList) => User32_Gdi.SendMessage(hWnd, Msg, wParam, ref imageList);
예제 #4
0
 private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref BUTTON_IMAGELIST lParam);
예제 #5
0
        /// <summary>
        /// Sets the images of the button to the specified value with the specified alignment and margins.
        /// </summary>
        /// <param name="images">The images for the button.</param>
        /// <param name="align">The alignment of the image</param>
        /// <param name="leftMargin">The left margin of the image in pixels</param>
        /// <param name="topMargin">The top margin of the image in pixels</param>
        /// <param name="rightMargin">The right margin of the image in pixels</param>
        /// <param name="bottomMargin">The bottom margin of the image in pixels</param>
        public void SetImage(Bitmap[] images,
                             Alignment align, int leftMargin, int topMargin, int rightMargin,
                             int bottomMargin)
        {
            if (GenerateDisabledImage)
            {
                if (images.Length == 1)
                {
                    Bitmap image = images[0];
                    images = new Bitmap[] { image, image, image, image, image };
                }

                images[3] = DrawImageDisabled(images[3]);
            }

            if (ComCtlMajorVersion < 0)
            {
                DLLVERSIONINFO dllVersion = new DLLVERSIONINFO();
                dllVersion.cbSize = Marshal.SizeOf(typeof(DLLVERSIONINFO));
                GetCommonControlDLLVersion(ref dllVersion);
                ComCtlMajorVersion = dllVersion.dwMajorVersion;
            }

            if (ComCtlMajorVersion >= 6 && FlatStyle == FlatStyle.System)
            {
                RECT rect = new RECT();
                rect.left   = leftMargin;
                rect.top    = topMargin;
                rect.right  = rightMargin;
                rect.bottom = bottomMargin;

                BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST();
                buttonImageList.margin = rect;
                buttonImageList.uAlign = (int)align;

                ImageList            = GenerateImageList(images);
                buttonImageList.himl = ImageList.Handle;

                SendMessage(this.Handle, BCM_SETIMAGELIST, 0, ref buttonImageList);
            }
            else
            {
                FlatStyle = FlatStyle.Standard;

                if (images.Length > 0)
                {
                    Image = images[0];
                }

                switch (align)
                {
                case Alignment.Bottom:
                    ImageAlign = ContentAlignment.BottomCenter;
                    break;

                case Alignment.Left:
                    ImageAlign = ContentAlignment.MiddleLeft;
                    break;

                case Alignment.Right:
                    ImageAlign = ContentAlignment.MiddleRight;
                    break;

                case Alignment.Top:
                    ImageAlign = ContentAlignment.TopCenter;
                    break;

                case Alignment.Center:
                    ImageAlign = ContentAlignment.MiddleCenter;
                    break;
                }
            }
        }
예제 #6
0
 private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref BUTTON_IMAGELIST lParam);