PDA

View Full Version : MDI Child handles not working (.NET)


Unregistered
November 11, 2002, 01:05:30
I am currently working on an application that utilizes the .NET Framework's windows forms, and it's written in C#. I can add a TextControl, ruler, and buttons to my form, and it all works correctly; however, when I set the MdiParent property of my form, then I lose the handles to my button and ruler controls.

If I step through the code, I see the values for the RulerControl.hWnd and the ButtonControl.hWnd, but as soon as I set the MdiParent then they both go to 0. Then, I'm unable to use the controls correctly.

I'm getting this error if I set the MdiChild property before or after I set the axControl.ButtonHandle or .RulerHandle.

Is there anything that I can do to work around this? My code is attached below.

Thanks,

Sean

public frmTemplateManager(UIController uiController, EnumMode enumMode)
{
InitializeComponent();

myController = uiController;
this.MdiParent = myController.MdiParent;

axRTFControl.ButtonBarHandle = axRTFButtons.hWnd;
axRTFControl.RulerHandle = axRTFRuler.hWnd;

axRTFControl.ScrollBars = (short)ScrollBars.Both; // both

formMode = (int)enumMode;
}


This message was originally posted by Sean Baughman in the old TX Text Control Support Forum.

Unregistered
November 11, 2002, 16:25:24
I'm wondering if Handle would reveal it:

axRTFControl.ButtonBarHandle = axRTFButtons.Handle.ToInt32;
axRTFControl.RulerHandle = axRTFRuler.Handle.ToInt32;


This message was originally posted by Vann Joe in the old TX Text Control Support Forum.

Unregistered
November 11, 2002, 21:00:23
I tried the above code (using handles) and it doesn't work either. I have valid handle numbers, and my code doesn't throw any exceptions -- it just doesn't enable the ruler or button controls.

It's as if once I set that property then I can no longer access those handles. Then I have no access to my ruler or buttons anymore.

Any ideas?


This message was originally posted by Sean Baughman in the old TX Text Control Support Forum.

Unregistered
November 12, 2002, 17:08:17
I think the problem you're having is passing an unmanaged control (the TX ActiveX controls) between classes (ie forms). When you do so, you can only pass them as a generic Control, and you have to use boxing/unboxing to reconstitute the control in usable form. From a design standpoint, this makes sense, for there is no way in advance for the CLR to know about the structure of an ActiveX object.

I spent 5 minutes creating a hasty project with TX that properly links the button bar to the control itself. I know the code snippet below isn't pretty or elegant, but I think it'll get you on the right track:
Private Sub NewDoc(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MenuNewFile.Select
Dim f As New Form2()
f.MdiParent = Me
f.Show()
Dim TX As AxTx4oleLib.AxTXTextControl
Dim ButBar As AxTx4oleLib.AxTXButtonBar
ButBar = CType(Me.AxTXButtonBar1, AxTx4oleLib.AxTXButtonBar)
TX = CType(f.Controls(0), AxTx4oleLib.AxTXTextControl)
TX.ButtonBarHandle = ButBar.Handle.ToInt32
End Sub

This message was originally posted by Vann Joe in the old TX Text Control Support Forum.