PDA

View Full Version : dotNet Form problem


Tesctassa
03-28-2008, 06:49 PM
Hi again!

I'm developing a dotNet component for 3DSMax 2008, but I'm encountering several problems. This component is a Form-based application, a sort of text editor. It is loaded with the method dotNet.LoadAssembly() function and then fired up with the .show() predefined method.
What's happening is that once the application is running none of the keyboard shorcuts set works, such as ctrl+N for new file, ctrl+O for open etc. Furthermore when a "text file" is opened and the focus is on the text area (NOTE: the text area is extended from the textBoxBase control from the .NET 2.0), some of the keys don't work at all, such as backspace and return.


But what is really frustrating is the behavior of the application. When launching the application using the showDialog() method (which gives exclusive focus to the form) it works perfectly, but obviously there is the side effect that I have to close it to come back to Max.

Any help here??

NOTE: before setting the Max global variable enableAccelerators to false also the keys associated to common Max shortcuts, such as 'w' or 'e', didn't work.


Thanks in advance!
Regards,
Adriano

ypuech
03-28-2008, 10:01 PM
Hi Adriano,

If you are under Max 2008, I think it would be a good idea to use the MaxForm class from the new .NET SDK added in this version. In your managed code, add MaxCustomControls.dll as dependency and subclass your Application Form class from MaxCustomControls.MaxForm and not System.Windows.Forms.Form. To display the form in Max, use the special method from MaxForm class : ShowModeless(). It displays this form modelessly and sets the main Max window as the parent.

Here is a code snippet to show you how to use a MaxForm in MAXScript. In your case, you'll have to create your application form (subclassed from MaxForm) and not directly a MaxForm:

(
-- Load MaxCustomControls assembly
-- This assembly contains UI components built on the .NET Framework for special use in 3ds Max
dotNet.loadAssembly "MaxCustomControls.dll"

-- Create TextBox
hTextBox = dotNetObject "System.Windows.Forms.TextBox"
hTextBox.Location = dotNetObject "System.Drawing.Point" 10 10
hTextBox.Width = 280
hTextBox.Height = 280
hTextBox.Visible = true
hTextBox.MultiLine = true
ScrollBars = dotNetClass "System.Windows.Forms.ScrollBars"
hTextBox.ScrollBars = ScrollBars.Vertical
hTextBox.AcceptsReturn = true
hTextBox.AcceptsTab = true
hTextBox.WordWrap = true

-- Create Max Form
hMaxForm = dotNetObject "MaxCustomControls.MaxForm"
hMaxForm.Size = dotNetObject "System.Drawing.Size" 310 335
hMaxForm.Text = "Max Form with TextBox"
hMaxForm.Controls.Add(hTextBox)
hMaxForm.TopMost = true
FormBorderStyle = dotNetClass "System.Windows.Forms.FormBorderStyle"
hMaxForm.FormBorderStyle = FormBorderStyle.FixedDialog
hMaxForm.ShowInTaskbar = false
hMaxForm.MinimizeBox = false
hMaxForm.MaximizeBox = false

-- Show MaxForm
hMaxForm.ShowModeless()
)

The keyboard inputs will work as expected now and the form will be modeless.

Tesctassa
03-31-2008, 11:35 AM
Hi! I've tried the solution you suggested, but I figured out that the problem is not with the form. Actually I'm using a custom textArea, called "TextEditorControl", which is implemented in a dll called "ICSharpCode.TextEditor.dll".
When using this control the mentioned problem occours, while using the default textArea control from the .Net library it does not.

I'll try searching something about this custom control I'm using. I chose it because it had all the feature I needed already implemented... Having to drop it could be quite a hassle.

Anyway, thanks for your help!

Regards,
Adriano

ypuech
03-31-2008, 11:55 AM
Have you tried to set the focus to this custom control ?
if not control.Focused then control.Focus()

Put this code in the open rollout event handler and in the MouseMove control event handler.
I'm not sure this code will resolve your problem but rollouts and dotNetControl have sometimes problems with focuses and input entries.

CGTalk Moderation
03-31-2008, 11:55 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.