Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
ChingYen  
#1 Posted : Thursday, July 17, 2008 4:34:43 AM(UTC)
ChingYen

Rank: Advanced Member

Groups: Member
Joined: 3/3/2008(UTC)
Posts: 185

Thanks: 8 times
Hi,

We let the user to add text to the multilayer viewer by using textVobject and TextVObjectCreateDesigner

What we would like to do is select the newly added textBObject once it's added to the MLV.

We tried the code
_mlvMain_LayerChanged
If TypeOf e.VObject Is Aurigma.GraphicsMill.WinControls.TextVObject Then
If e.ChangeType = Aurigma.GraphicsMill.WinControls.LayerChangeType.ObjectAdded And ManualAddText Then
_mlvMain.CurrentDesigner = _mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1).Designer

But, we will have error by doing this...Please advice.
Alex Kon  
#2 Posted : Friday, July 18, 2008 7:30:00 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hi,

You code looks good - it should work if there are no mistakes with "ManualAddText" and "Layer_Design" variables or properties. Could you provide us with more detailed information about error? For now I can just recommend you to use e.VObject.Designer property directly - something like that:

Code:
If ManualAddText Then
     _mlvMain.CurrentDesigner = e.VObject.Designer
End If
ChingYen  
#3 Posted : Sunday, July 20, 2008 3:40:23 PM(UTC)
ChingYen

Rank: Advanced Member

Groups: Member
Joined: 3/3/2008(UTC)
Posts: 185

Thanks: 8 times
Hi,

Here is the full code.

Even this line won't help. This will lead me to error.
Quote:
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Aurigma.GraphicsMill.WinControls.VectorObjects"
StackTrace:
at Aurigma.GraphicsMill.WinControls.ClickDragCreateDesigner.NotifyMouseUp(MouseEventArgs e)
at Aurigma.GraphicsMill.WinControls.MultiLayerViewer.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at Aurigma.GraphicsMill.WinControls.MultiLayerViewer.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Stories.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:



Code:

    Private Sub _mlvMain_LayerChanged(ByVal sender As Object, ByVal e As Aurigma.GraphicsMill.WinControls.LayerChangedEventArgs) Handles _mlvMain.LayerChanged
        Const ProcedureName = "_mlvMain_LayerChanged"

        If _ChangingObj Then
            Exit Sub
        End If

1:      Try
2:          If Not ((e.Layer.Name = "Indicator") Or (e.Layer.Name = "Frame")) Then
3:              If TypeOf e.VObject Is Aurigma.GraphicsMill.WinControls.TextVObject Then
4:                  If e.ChangeType = Aurigma.GraphicsMill.WinControls.LayerChangeType.ObjectAdded And ManualAddText Then
11:                     If (_mlvMain.Layers(Layer_Design).VObjects.Count - 1) >= 0 Then
12:                         If TypeOf _mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1) Is Aurigma.GraphicsMill.WinControls.TextVObject Then
13:                             _mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1).SupportedActions(Aurigma.GraphicsMill.WinControls.VObjectAction.ChangeTextArea).Enabled = True
14:                             _mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1).SupportedActions(Aurigma.GraphicsMill.WinControls.VObjectAction.Resize).Enabled = False
15:                             _mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1).SupportedActions(Aurigma.GraphicsMill.WinControls.VObjectAction.Rotate).Enabled = False
16:                             frmMain.UpdateFontCbo(DirectCast(_mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1), Aurigma.GraphicsMill.WinControls.TextVObject).Font.Name, DirectCast(_mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1), Aurigma.GraphicsMill.WinControls.TextVObject).Font.Size)
17:                             frmMain.UpdateFontAlignment(DirectCast(_mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1), Aurigma.GraphicsMill.WinControls.TextVObject).Format.Alignment)
18:                             frmMain.UpdateFontLineAlignment(DirectCast(_mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1), Aurigma.GraphicsMill.WinControls.TextVObject).Format.LineAlignment)
19:                             frmMain.UpdateFontStyle(DirectCast(_mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1), Aurigma.GraphicsMill.WinControls.TextVObject).Font)
20:                             _mlvMain.Layers(Layer_Design).VObjects(_mlvMain.Layers(Layer_Design).VObjects.Count - 1).Tag = pzObj
21:                         End If
22:                     End If
                        _ChangingObj = True
                        ManualAddText = False
                        _mlvMain.CurrentDesigner = e.VObject.Designer
23:                 Else
24:                 End If
25:             End If

26:             PageEdited = True
27:             ManualAddText = False
                _ChangingObj = False
28:         End If

29:     Catch ex As Exception
30:         WriteErrLog(Err.Number, Err.Source, Err.Description, gstrModule, ProcedureName, Err.Erl)
31:     Finally
32:     End Try
    End Sub


Edited by user Sunday, July 20, 2008 3:48:05 PM(UTC)  | Reason: Not specified

Alex Kon  
#4 Posted : Sunday, July 20, 2008 7:52:13 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello,

I have found the reason. TextVObject designer cannot be detached from the host control before finishing work. So the code should delay designer switching a little. Here is small code in the attachment which demonstrates the idea.
File Attachment(s):
MLV_TextSelection_VB.zip (12kb) downloaded 8 time(s).
tcrosbie  
#5 Posted : Wednesday, July 23, 2008 6:19:13 PM(UTC)
tcrosbie

Rank: Advanced Member

Groups: Member
Joined: 6/22/2008(UTC)
Posts: 27

I'm doing exactly this in my app, here's my code that works, it's not complicated, (I run very much on the KISS principle).

Set the currentdesigner to the objects designer immediately after you add it to the layer.


Code:

void MLV_Click(object sender, EventArgs e)
{
    if (this.CreateText)
    {
        MouseEventArgs m = (MouseEventArgs)e;
        Aurigma.GraphicsMill.WinControls.TextVObject textObject = new Aurigma.GraphicsMill.WinControls.TextVObject();
        textObject.Text = "Double click to edit";

        textObject.TextArea = new RectangleF((float)m.X, (float)m.Y, (float)200, (float)100);
        this.CurrentLayer.VObjects.Add(textObject);
        this.CurrentDesigner = textObject.Designer;
        this.CreateText = false;
    }
}


I've found using the vObjectCreateDesigner functions don't really give me the desired effect, and this method just works.

The user clicks a toolbar button which sets the createtext flag on the MLV, then when they click on the MLV this code places a Textbox there, selected ready for them to do whatever they like.

HTH.

Edited by user Wednesday, July 23, 2008 6:19:47 PM(UTC)  | Reason: Not specified

Alex Kon  
#6 Posted : Thursday, July 24, 2008 5:06:21 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello,

I have to confirm that your solution conforms more with KISS rule. ;) I can recommend to use it in cases when there is no need in the setting text bounds first.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.