using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace Corp3s.Controls
{
    public partial class CustomRadioControl : RadioButton
    {
        private const int GWL_EXSTYLE = -20;
        private const int WS_EX_WINDOWEDGE = 0x00000100;
        private const int WS_EX_CLIENTEDGE = 0x00000200;
        private const int SWP_NOSIZE = 0x0001;
        private const int SWP_NOMOVE = 0x0002;
        private const int SWP_NOZORDER = 0x0004;
        private const int SWP_NOACTIVATE = 0x0010;
        private const int SWP_FRAMECHANGED = 0x0020;

        public CustomRadioControl()
            : base()
        {            
            InitializeComponent();
#if !DESIGN
            SetRadioControlStyle();
#endif
        }

#if !DESIGN
        private void SetRadioControlStyle()
        {
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                return;

            IntPtr hwnd = this.Handle;
            this.Capture = true;
            hwnd = GetCapture();
            this.Capture = false;
            int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
            SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_WINDOWEDGE);
            SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE
                            | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
        }        

        [DllImport("coredll")]
        private static extern IntPtr GetCapture();

        [DllImport("coredll")]
        private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("coredll")]
        private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        [DllImport("coredll")]
        private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
#endif
    }
}
