How can I initialise a form region when the assign task button is clicked? - vsto

I have a custom form region defined for Tasks and TaskRequestItems. When I create a task the Form Region is initialised correctly but when I click the "Assign Task" button, the item is updated to a TaskRequestItem and my form region disappears. If in Outlook I click New Items > More Items > Task Request then the form region appears correctly on the TaskRequestItem.
Does anyone know why the form region disappears on conversion of Task to TaskRequestItem or whether there is a way to trigger the form region initialisation when the "Assign Task" button is clicked?
Thanks in advance

You need to check the message class of the item shown and then add it to the list of supported items of your form region. You can do that by adding a new attribute to the form region class with the message class you are interested in.
Every item contains a Message Class field; this field contains the name of the form that Outlook provides to view and edit the item. For example, a contact item has a default message class of "IPM.Contact". If you create a custom form called "Customer", the Message Class field of items using that form will contain "IPM.Contact.Customer". The message class of all Outlook items always begins with "IPM". The second part of the message class denotes the type of Outlook form that the form is based on. The third portion of the message class is present only if the form is a customized version of a standard Outlook form.
There are two ways to associate a form region with a message class:
Use the New Outlook Form Region wizard.
On the final page of the New Outlook Form Region wizard, you can select standard message classes and type the names of custom message classes that you want to associate with the form region.
To include one or more custom message classes, type their names in the Which custom message classes will display this form region? box.
Apply class attributes
The first attribute associates the form region with a standard message class for a mail message form. The second attribute associates the form region with a custom message class named IPM.Task.Contoso.
[Microsoft.Office.Tools.Outlook.FormRegionMessageClass
(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Note)]
[Microsoft.Office.Tools.Outlook.FormRegionMessageClass
("IPM.Task.Contoso")]
You may find the following pages helpful:
Associate a form region with an Outlook message class
Create Outlook form regions

You'be better off using a Task Pane instead of a form region (which is shown by Outlook itself based on the message class). A task pane can be explicitly shown or hidden by your code.
Start at https://learn.microsoft.com/en-us/visualstudio/vsto/walkthrough-displaying-custom-task-panes-with-e-mail-messages-in-outlook?view=vs-2022&tabs=csharp

Related

Outlook Forms: Recipient does not receive form, only message body //How to store form's data in an email?

I am currently trying to create a form in Outlook. I want to be able to send this form to different people so that they can make changes to the form and send those changes back to me as a response.
I have a published form in the meantime. My current problem: The recipient does not see the form until he "undocks" the email from the Outlook app and the changes made there are not transmitted to me; I just get an empty form. How or where can I save this data that the recipients enter? I am grateful for any help!
The form definition includes all the fields and the code that you add to the form. As a general rule, publish the form definition to a forms library instead of sending the form definition with the item. If you cannot publish your form to a forms library, you can select the Send form definition with item check box on the Properties page so that other users can see the form pages when they receive items that are composed by using the form.
Forms that you only intend to use once and not publish are referred to as one-off forms. Because of security concerns with one-off forms, users might not see the form correctly when they open items sent to them with a one-off form. In this case, sending the form definition with the one-off form provides the necessary information required to display the form correctly for the users.
To change how users reply to your form, click the Actions page. The Actions page lists the default Reply forms that are available. You can also add your own custom Reply forms. For example, forms based on a new email message have built-in Reply, Reply to All, Forward, and Reply to Folder forms. When users receive your form, the form contains buttons and menu commands so that users can respond to the form. You can disable some or all of these default forms and set attributes that define how these Reply forms appear.
Read more about that in the Create an Outlook Form section of MSDN.

How to change TextAlign of the From/To field in outlook custom form?

When i am creating the From/To field from Field Chooser, there is no property to text alignment.
I tried to change with vba in Function Item_Open() :
Item.GetInspector.ModifiedFormPages("Message").Controls("From").TextAlign = 3
but I failed. An Error that there is no such property as the TextAlign
I tried to do the mapping of the sender and the recipient through labels, but when i do double-click on the label, there does not display information about the sender/recipient.
There is no such property for standard controls. Instead, consider developing an add-in with a form region where you can use any controls. See Creating Outlook Form Regions for more information. For example, you may use the Replacement layout which adds the form region as a new page that replaces the default page of an Outlook form. Or the Replace-All one which replaces the whole Outlook form with the form region.

How to create click event for dynamically created custom control?

Let say that I'm creating thousands of custom controls, each control has own data assigned to it (like name, id, etc.), now I would like to add
click event for each of these custom controls
access from software any of these dynamically created controls
So I would like to show MsgBox if user click control #452, which will be returning values assigned to object in custom control class (passed during creation of new control on user form)
Second thing is that I would like to access at any time any of these objects and read values assigned to object in control....
How to do it ? Each control has name assigned like "Example1", "Example2", "Example3" but I don't know how to access it from code as any of these exists during writing...
Also I were trying to find how to create and rise events but it seems that all solutions are for statically created controls and I need to rise events for dynamically crated custom controls....
Thanks in advance for any tips/help how to solve it.
I'm using VB.NET
Ok I figured it out !
It is very simple actually.
If any one will be looking for an answer :
To access dynamically created control first we are going to name it :
Dim Control as new CustomControl
Control.Name = "Name" & Counter
Next after we've created new controls we are going to access it using:
Dim _Control as new CustomControl
_Control = Ctype(Me.Panel1.Controls("Name1"), CustomControl)
MsgBox(_Control.Name.ToString)
Viola
I still not sure about custom events for all controls on custom control (so where ever user click, there should be override event which returns something back, now I can only either click panel container (not labels/pictureboxes) from code inside user class, or event per control on custom control (but issue is that I want to pass data from custom control to user class).

Visual Basic 2010 - Referencing objects in different user controls

For an app that uses user controls instead of forms and the first user control has a listview, where the user clicks or selects "Create New" Or Delete, what is the best way to transfer the data selected in the listview to the detail screen (separate User Control) where the data can be edited?
Can I just reference the list view in the first UC in the Details UC? something like:
ucHeader.lvSetups.FocusedItem.SubItems.Count = 0
from the ucDetail user control?
Saying which way is the best would produce a heated discussion with every ones opinion. However, here are a few ways I would tackle this. While there are more options, these are what I would do:
You should expose any information you want to read from a user control in the form of a property, readonly if you must. Just an example because I don't know what your object types are:
Public ReadOnly Property SelectedItem as object
get
Return Listview1.SelectedValue
end get
End Property
You can also use events to tell the parent of your user control that a selection was made. You can pass whatever you want in this event, even the selected object. If you don't want to pass the selected object, grab it from the property you created (like #1) in the event handler.

VB.net User Control Issues

I've created one user control which have textBox & DatabGridView etc. When any user start typing in textbox then the filter is applied in DatabGridView. Now I want to add following features in this control how can I add these?
I want to use same control for supplier, customer, vendors on a single form, so I've placed it 3 times from toolbar. But for each control I want to fill different data from database. So what will be the best way to bind the control?
As we knew each table (customer,supplier & vendor) can have different columns, so I also need properties to set them. I've added property to my control but how can I ensure user has assign value in it? I.e. if user run the form and X property is not assigned to control then it should show message.
Note: I've tried it on control load event but didn't get any success because control's load event is occurred prior to form load and I'm assigning property on form load.
Please help....