0

I am trying to adjust the height of the custom task pane to the height of the usercontrol. My usercontrol is changing its height depending on some circumstances, so how can make custom task pane to automatically adjust to the height of the usercontrol?

I have subscribed to the usercontrol size changed event and i check if the height has changed. if so the I try to modify the custom task pane height to that value. The problem here is that the height of the usercontrol is as double and the height of the task pane is in points. So how to convert double to points?

I have set task pane height to a fixed value that is fine for my screen resolution but when showing it in another screen resolution, the custom task pane height gets bigger.

Below the code:

int maxHeight = this.ctp.Height;

foreach (System.Windows.Forms.Control c in this.ctp.Control.Controls)
{
    if (c.Height > maxHeight)
    {
        maxHeight = c.Height;
    }
}

this.ctp.Height = maxHeight;
Willy
  • 9,848
  • 22
  • 141
  • 284
  • What is your code? Could you be more specific? – Eugene Astafiev Jul 25 '22 at 20:08
  • @EugeneAstafiev What I finally end up doing is to change the height of the custom task pane by basically modifying the property height with a fixed value, let's say, a double value of 120. There are two problems which I don't know how to solve: First, the height that comes from the usercontrol is of type SizeChangedEventArgs and I get the height from that by doing SizeChangedEventArgs.NewSize.Height which is a double and then I convert to int and assign to myCustomTaskPane.Height (which is in points). So how to convert from int to points? – Willy Jul 25 '22 at 21:26
  • @EugeneAstafiev The second problem is that height depends on the screen resolution. For example, in my development computer the height is the correct (I am using a high resolution) however if i move to another computer with lower resolution, then the custom task pane height is shown bigger. – Willy Jul 25 '22 at 21:28
  • @EugeneAstafiev Basically what I want to do is adjust the task pane height in order to fit with the usercontrol height. For example, if usercontrol height changes, then i want to update the custom task pane height to the same value. – Willy Jul 25 '22 at 21:29
  • @EugeneAstafiev I have update my post and put the code snippet. That code snippet is not working. Custom task pane height is not adjusted to the usercontrol height. Why? – Willy Jul 26 '22 at 11:43
  • @EugeneAstafiev See all my code here: https://learn.microsoft.com/en-us/answers/questions/943174/vsto-outlook-autosize-custom-task-pane-height-to-t.html – Willy Jul 26 '22 at 17:46

0 Answers0