开发者

Resize problem when hosting ocx control within wpf

I am hosting an ocx control ( a graph control for plotting) in my wpf application. The problem is that it is not getting resized when the main window is resized. The control te开发者_C百科nds to maintain its original size and when mainwindow is resized, the ocx control gets clipped and not resized. Is there any solution for this problem.


It is my understanding that the ocx control will not go through the usual Arrange/Measure cycle that a normal WPF control would. Perhaps the best that you can do is to handle the SizeChanged event for the window or panel (whatever is containing the control), and resize the ocx control appropriately. For example, if the control is being hosted in a Grid called gridGraph:

public Window1()
{
    InitializeComponent();
    gridGraph.SizeChanged += 
        new SizeChangedEventHandler(gridGraph_SizeChanged);
}

void gridGraph_SizeChanged(object sender, SizeChangedEventArgs e)
{
    Size size = e.NewSize;
    myOcx.Width = size.Width;
    myOcx.Height = size.Height;
}

Your mileage may vary - you will have to adjust the control to your particular container and settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜