Finding the screen location of the command button icon

Add-in Express™ Support Service
That's what is more important than anything else

Finding the screen location of the command button icon
Or How do I align a WinForm with my Icon 
George Kierstein




Posts: 47
Joined: 2013-05-04
Hi,

I'm trying to align a WinForm with my Command Item Icon button but don't see any way to do so. Is there a way to get out the screen coordinates of the icon so that I can position my WinForm relative to it ?

Barring that is there a way to know the location of the Command area itself so that the WinForm can float over the page ?

Is having a Command Item the best choice to attempt this or should I be using a different project type ?

Thoughts ?

G
Posted 12 Jul, 2013 17:26:44 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi George,

Did you add the command to the 'Command bar' toolbar of IE or a custom toolbar?
Posted 15 Jul, 2013 06:01:16 Top
George Kierstein




Posts: 47
Joined: 2013-05-04
I did add an icon. I used the 'ADX IE Add On' project option in visual studio 2010 and added a Command Item in the designer. That's the Icon I'm referring to and it would be ideal if I could get my WinForm to be aligned when I receive the click callback.

If that's not possible it would be great if I could align it with the interior of the page itself
Posted 17 Jul, 2013 00:16:46 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi George,

I am afraid that it is not possible. The Command Bar works in the main process in IE. Moreover the command can be hidden. I will publish the code that align a window with the top right corner of the web page.
Posted 17 Jul, 2013 07:13:23 Top
George Kierstein




Posts: 47
Joined: 2013-05-04
Thanks!
Posted 17 Jul, 2013 11:16:48 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi George,

Please try the code below. To enable visual styles the constructor of the custom form should call the 'Application.EnableVisualStyles()' method before the InitializeComponent method.


        [DllImport("user32")]
        public extern static int GetWindowRect(IntPtr hWnd, out RECT lpRect);

        [ComVisible(false), StructLayout(LayoutKind.Sequential, Pack = 4)]
        public struct RECT
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;

            public RECT(Rectangle rect)
            {
                Left = rect.Left;
                Top = rect.Top;
                Right = rect.Right;
                Bottom = rect.Bottom;
            }

            public RECT(int left, int top, int right, int bottom)
            {
                this.Left = left;
                this.Top = top;
                this.Right = right;
                this.Bottom = bottom;
            }

            public Rectangle Rect { get { return new Rectangle(this.Left, this.Top, this.Right - this.Left, this.Bottom - this.Top); } }

            public static RECT FromXYWH(int x, int y, int width, int height)
            {
                return new RECT(x,
                                y,
                                x + width,
                                y + height);
            }

            public static RECT FromRectangle(Rectangle rect)
            {
                return new RECT(rect.Left,
                                 rect.Top,
                                 rect.Right,
                                 rect.Bottom);
            }

            public Rectangle ToRectangle()
            {
                return new Rectangle(Left, Top, Right - Left, Bottom - Top);
            }
        }

        private void adxieCommandItem1_OnClick(object sender, object htmlDoc)
        {
            Form1 f = new Form1();

            RECT wndRect;

            GetWindowRect(this.ParentHandle, out wndRect);
            f.Location = new Point(wndRect.Right - f.Width, wndRect.Top);

            f.ShowDialog(this);
            f.Dispose();
        }
Posted 19 Jul, 2013 06:10:50 Top