F
Fruber Malcome
After some additional research into my previously mentioned problem about
Clipboard.SetDataObject.
I found that the handler I am calling that calls this function is derived
from reflection.
I do this because I have an array of buttons etc on a commandbar, I then
have an onAction property of this array of commandbar buttons, when I create
each button I keep them in an array of custom button classes that contain
this string which is really the name of the function handler.
So I wrap all clicks in the following function: - if I call
Clipboard.SetDataObject in any of my button handlers, I get the mentioned
exception that states that I need to ensure my main function has the
STAThread attribute. Is there a better way to perform this type of task?
(without creating the buttons design time and/or making them members of the
class as button objects and then maually adding the events)
How can I get rid of this exception.
private void _onButtonClick( Office.CommandBarButton btn, ref bool
bHandled )
{
string strMessage = "";
try
{
if ( btn.OnAction == null || bHandled == true )
return;
bHandled = true;
Type type = this.GetType();
MethodInfo mi = type.GetMethod( btn.OnAction, (BindingFlags.Instance
| BindingFlags.NonPublic | BindingFlags.Public) );
if ( mi != null )
mi.Invoke( this, new object[]{} );
else
{
strMessage = String.Format( "Control:\t{0}\nFunc:\t{1}\n",
btn.Tag, btn.OnAction );
_showMessage( strMessage, Types.MSG_APP_UNLISTED_FUNC );
}
}
catch( COMException e )
{
showCOMException( e );
}
catch( Exception e )
{
showException( e );
}
}
Clipboard.SetDataObject.
I found that the handler I am calling that calls this function is derived
from reflection.
I do this because I have an array of buttons etc on a commandbar, I then
have an onAction property of this array of commandbar buttons, when I create
each button I keep them in an array of custom button classes that contain
this string which is really the name of the function handler.
So I wrap all clicks in the following function: - if I call
Clipboard.SetDataObject in any of my button handlers, I get the mentioned
exception that states that I need to ensure my main function has the
STAThread attribute. Is there a better way to perform this type of task?
(without creating the buttons design time and/or making them members of the
class as button objects and then maually adding the events)
How can I get rid of this exception.
private void _onButtonClick( Office.CommandBarButton btn, ref bool
bHandled )
{
string strMessage = "";
try
{
if ( btn.OnAction == null || bHandled == true )
return;
bHandled = true;
Type type = this.GetType();
MethodInfo mi = type.GetMethod( btn.OnAction, (BindingFlags.Instance
| BindingFlags.NonPublic | BindingFlags.Public) );
if ( mi != null )
mi.Invoke( this, new object[]{} );
else
{
strMessage = String.Format( "Control:\t{0}\nFunc:\t{1}\n",
btn.Tag, btn.OnAction );
_showMessage( strMessage, Types.MSG_APP_UNLISTED_FUNC );
}
}
catch( COMException e )
{
showCOMException( e );
}
catch( Exception e )
{
showException( e );
}
}