如何将文本框绑定到表单区域的自定义属性?



c#, VSTO, Outlook 2016

我创建了一个前景Formregion文本框。
我想把TextBox控件绑定到一个自定义属性。

我已经找到SetControlItemProperty方法:
https://learn.microsoft.com/en-us/office/vba/api/outlook.formregion.setcontrolitemproperty

在c#中是否有类似的方法,我如何使用这个方法
以及应该在哪里调用这个方法?

对于托管外接程序,您需要以编程方式设置该属性。在VSTO外接程序的情况下没有自动绑定。

您可以在运行时使用任何标准的Outlook机制(如UserPropertiesCustomProperties)读取属性值,并以编程方式设置控件的Text属性。

好的,谢谢你,Eugene。



using Outlook = Microsoft.Office.Interop.Outlook;
using MSForms = Microsoft.Vbe.Interop.Forms;
namespace myHumbleAddin
{
partial class frmDataTable
{
private void frmDataTable_FormRegionShowing(object s, EventArgs e) {
Outlook.FormRegion mRegion = this.OutlookFormRegion;
mRegion.SetControlItemProperty(mRegion.Form.mTextBox, "userField");
}
}
}

但是智能感知功能显示了SetControlItemProperty方法。
没有机会使用这个吗?

智能感知

wrg,谢谢你Eugene。如果Micro' %-&%"?…

目前为止我的解决方案(只针对约会):

using Outlook = Microsoft.Office.Interop.Outlook;
namespace myHumbleAddin
{
partial class frmDataTable
{
private void frmDataTable_FormRegionShowing(object sender, System.EventArgs e) {
Outlook.FormRegion currentRegion = this.OutlookFormRegion;
Outlook.AppointmentItem currentItem = OutlookItem as Outlook.AppointmentItem;
// Bind a control on the form to a UserPropertyField
void bindControl (System.Windows.Forms.Control control, string customProperty) {
string _value = currentItem.UserProperties[customProperty].Value.ToString();
if (!string.IsNullOrEmpty(_value)) {
control.Text = _value;
}
}
if ( (currentItem != null) && (currentItem is Outlook.AppointmentItem) ) { 
bindControl(tbBez, "Bezeichnung");
}
}
private void frmDataTable_FormRegionClosed(object sender, System.EventArgs e) {
Outlook.AppointmentItem currentItem = OutlookItem as Outlook.AppointmentItem;

void setControlContents(System.Windows.Forms.Control control, string customProperty) {
string _value = currentItem.UserProperties[customProperty].Value.ToString();
if (control.Text.Length != 0 && control.Text != _value) {
currentItem.UserProperties[customProperty].Value = control.Text;
}
}
setControlContents(tbBez, "Bezeichnung");
}
}
}

任何改进都是值得赞赏的,因为我是Outlook世界的初学者。

最新更新