locked
Draw in and out for custom pane RRS feed

  • Question

  • Hi all,

     

           I have created a custom pane using VSTO(VB.Net) i want to give it the draw in and draw motion like what a task pane has in outlook... how do i do it...

     

    Regards

    Archana Muralidhar

    Thursday, July 10, 2008 1:42 PM

Answers

  • Hi Achu,

     

    Custom Task Pane is different type of window from To-Do Bar built in Outlook. We cannot apply exact the same draw in/draw out motion to Custom Task Pane. But we can try to mimic the behavior using some native Windows API.

    I put a button in my Custom Task Pane. When this button is clicked, a Windows Form will be shown. Of course, before it is shown or hidden to user, I call native Windows API AnimateWindow to grant Animation to the Window.

    Codes look like:

    Code Snippet

            private void button1_Click(object sender, EventArgs e)

            {

                if (f1 == null)

                {

                    f1 = new Form1();

     

                    tagRECT rect = new tagRECT();

     

                    NativeMethods.GetClientRect(this.Handle, out rect);

                    NativeMethods.MapWindowPoints(this.Handle, new IntPtr(0), out rect, 2);

                    f1.Location = new Point(rect.left - f1.Width - 10, rect.top);

                    f1.Size = new Size(200, rect.bottom - rect.top);

                    f1.StartPosition = FormStartPosition.Manual;

     

                    NativeMethods.AnimateWindow(f1.Handle, 1000, (uint)AnimateWindowFlags.AW_HOR_NEGATIVE |

                        (uint)AnimateWindowFlags.AW_SLIDE);

     

                    f1.Show();

                }

                else

                {

                    NativeMethods.AnimateWindow(f1.Handle, 1000, (uint)AnimateWindowFlags.AW_BLEND |

                        (uint)AnimateWindowFlags.AW_HIDE);

                    NativeMethods.DestroyWindow(f1.Handle);

                    f1 = null;

                }

            }

     

     

    You can download sample I wrote from here:

    http://cid-c2e0d62e8a095a30.skydrive.live.com/self.aspx/Pictures/OutlookAddIn.zip

    It is very simple just for illustration objective. Hope it can help you get a start.

     

    Thanks,

    Ji

     

    Thursday, July 17, 2008 5:24 AM

All replies

  • Hi Achu,

     

    I intend to help on this. But I am not aware of what you mean about “draw in and draw motion”. Could you please clarify about it?

     

     

    Thanks,

    Ji

     

    Wednesday, July 16, 2008 6:11 AM
  • Hi Ji,

     

               When i say Draw in and draw out it is movement similar to what the task bar in uot look has

     

    Regards

    Archana Muralidhar

     

    Wednesday, July 16, 2008 7:06 AM
  • Hi Achu,

     

    Sorry, we need more clarification. I still do not understand what you refer about draw in and draw out.

    I am using Outlook 2007, I have Menu bar, tool bar, navigation pane, To-Do bar, Reading Pane, what do you mean about task bar?

    If you can attach some screen shot in the forum to describe what you want to customize, it will be helpful.

     

     

    Thanks,

    Ji

     

    Wednesday, July 16, 2008 9:03 AM
  • i mean the To -Do bar

     

    Wednesday, July 16, 2008 9:41 AM
  • Hi Ji

     

     Ji Zhou – MSFT wrote:

    Sorry, we need more clarification. I still do not understand what you refer about draw in and draw out.

    I think I follow what is wanted, but have no idea how to make it happen (indeed, I doubt it's possible, but then, what do I know )

     

    Imagine you're looking at the application window. You want to display a pane (To-Do in Outlook, according to the OP). You click a toolbar button that will display the pane. Rather than it just all of sudden being there, on the screen, it "grows" from the right edge of the application window towards the center, until it reaches its full width.

     

    Think of it like a sliding door: you pull it across. The pane should "draw across" from right-to-left.

     

    Or think of it like a transition in a PowerPoint presentation (in 2007 it's labelled "wipe left").

    Wednesday, July 16, 2008 11:03 AM
  • HI CINDY...

     

           your exactly right of what i am trying to do.....is it possible to do that.....

     

    Regards

    Archana Muralidhar

     

     

     

    Wednesday, July 16, 2008 11:41 AM
  • Hi Achu,

     

    Custom Task Pane is different type of window from To-Do Bar built in Outlook. We cannot apply exact the same draw in/draw out motion to Custom Task Pane. But we can try to mimic the behavior using some native Windows API.

    I put a button in my Custom Task Pane. When this button is clicked, a Windows Form will be shown. Of course, before it is shown or hidden to user, I call native Windows API AnimateWindow to grant Animation to the Window.

    Codes look like:

    Code Snippet

            private void button1_Click(object sender, EventArgs e)

            {

                if (f1 == null)

                {

                    f1 = new Form1();

     

                    tagRECT rect = new tagRECT();

     

                    NativeMethods.GetClientRect(this.Handle, out rect);

                    NativeMethods.MapWindowPoints(this.Handle, new IntPtr(0), out rect, 2);

                    f1.Location = new Point(rect.left - f1.Width - 10, rect.top);

                    f1.Size = new Size(200, rect.bottom - rect.top);

                    f1.StartPosition = FormStartPosition.Manual;

     

                    NativeMethods.AnimateWindow(f1.Handle, 1000, (uint)AnimateWindowFlags.AW_HOR_NEGATIVE |

                        (uint)AnimateWindowFlags.AW_SLIDE);

     

                    f1.Show();

                }

                else

                {

                    NativeMethods.AnimateWindow(f1.Handle, 1000, (uint)AnimateWindowFlags.AW_BLEND |

                        (uint)AnimateWindowFlags.AW_HIDE);

                    NativeMethods.DestroyWindow(f1.Handle);

                    f1 = null;

                }

            }

     

     

    You can download sample I wrote from here:

    http://cid-c2e0d62e8a095a30.skydrive.live.com/self.aspx/Pictures/OutlookAddIn.zip

    It is very simple just for illustration objective. Hope it can help you get a start.

     

    Thanks,

    Ji

     

    Thursday, July 17, 2008 5:24 AM
  • hi Ji

     

            this code is in C# and i work on VB.net there are few things i cant convert to VB.net and i recreated the application in C# it works fine but when we close the form and click on the button the application throws a exception

     

    System.ObjectDisposedException was unhandled by user code
      Message="Cannot access a disposed object.\r\nObject name: 'Form1'."
      Source="System.Windows.Forms"
      ObjectName="Form1"
     

    Thursday, July 17, 2008 10:05 AM
  • Hi Achu,

     

    I designed that the form can only be closed by the button, so, I set form1’s ShowInTaskbar to false and FormBorderStyle to None.

    If you did not set these properties and close the form from “X” option, when you click the button, DestroyWindow() API will throw the exception you are facing!

    OK. I will write a better version in VB.NET and post it here later. J

     

     

    Thanks,

    Ji

     

    Thursday, July 17, 2008 10:29 AM
  • Hi Ji,

     

           Sorry if i said something wrong.... i tired to convet the code to VB.net but i am unable to in the following places

     

    C#

     

    Code Snippet

    public partial class NativeMethods

    {

    /// Return Type: BOOL->int

    ///hWnd: HWND->HWND__*

    ///lpRect: LPRECT->tagRECT*

    [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "GetClientRect")]

    [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]

    public static extern bool GetClientRect([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWnd, [System.Runtime.InteropServices.OutAttribute()] out tagRECT lpRect);

    }

     

     

    VB.Net

     

    Code Snippet

    Partial Public Class NativeMethods

    <System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint := "GetClientRect")> ''Error at the end ">"

    <[return]: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> '' Error at the <[return]: System position

    Public Shared Function GetClientRect(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, <System.Runtime.InteropServices.OutAttribute()> ByRef lpRect As tagRECT) As Boolean

    End Function

    End Class

     

     

    and sorry once again
    Thursday, July 17, 2008 10:53 AM
  • hi Ji

     

       That link did help me a lot with what i want to do.... Ji is there any book or link which will give details about these native API's i want to learn more about this and any book or link which will help me to learn complete VSTO no matter how long it might take

     

     

    Regards

    Archana Muralidhar

     

    Thursday, July 17, 2008 1:58 PM
  • Hi Achu

     

    Native Windows API is provided to call windows system service directly. Windows API functions are typically implemented in user32.dll, kernel32.dll, Gdi32.dll. They can be called by different languages, C++, C#, VB. With C++, we can call Windows API directly. But as C# and VB.NET are managed language, to interact with native code in these dlls, we need to use Platform Invoke (PInvoke).

    To know more about Windows API, you have a read of “Programming Windows, Fifth Edtion” written by Charles Petzold. You can also get API functions in MSDN:

    http://msdn.microsoft.com/en-us/library/aa383749(VS.85).aspx

    To know more about PInvoke, the following site and article may help a lot:

    http://www.microsoft.com/indonesia/msdn/pinvoke.aspx

    http://www.pinvoke.net/

    http://msdn.microsoft.com/en-us/magazine/cc164193.aspx (The tool PInvoke Interop Assistant is very helpful)

     

    In fact, these topics are not Office specified, of course not related to VSTO. But many times we may encounter scenarios that Office Object Model APIs does not provide any functions to achieve. We may call native Windows API to see if it can help. Calling Windows API in VSTO is totally same with calling it from other C#/VB applications, like Windows Form, WPF and so on.

     

     

    Thanks

    Ji

    Friday, July 18, 2008 6:43 AM
  • Hi Ji,

     

             Thanks for the links i will definatelly go through all of it.... and Ji anything that will help me learn more about VSTO development, infact in depth about VSTO development.....

     

    Regards

    Archana Muralidhar

     

    Friday, July 18, 2008 6:55 AM
  • Hi Achu,

     

    All most every VSTO specified knowledge point is covered in Eric Carter’s book

    “Visual Studio Tools for Office: Using C# with Excel, Word, Outlook, and InfoPath”.

    And you can also subscribes VSTO team’s blog and some other office dev guys’ blogs:

    http://blogs.msdn.com/vsto/default.aspx

    http://blogs.msdn.com/eric_carter/default.aspx

    http://blogs.msdn.com/andreww/default.aspx

     

     

    Thanks,

    Ji

     

    Friday, July 18, 2008 10:25 AM