Exemple #1
0
 protected override void OnPaint(PaintEventArgs e)
 {
     if (DesignMode == false && TargetForm.ShowShadowForm && TargetForm.MostraBordo)
     {
         DrawManager.DrawMetroWindowShadow(e.Graphics, TargetForm.VisualManager(), ref MetroShadow, this.Bounds, this);
     }
 }
        /// <summary>
        /// if <see cref="CreatedForm"/> is true, then destroys created form. Resets <see cref="CreatedForm"/>, <see cref="TargetForm"/> and <see cref="TargetRichTextBox"/> to default values
        /// </summary>
        private void DetachFromControl()
        {
            if (CreatedForm)
            {
                try
                {
                    if (!TargetForm.IsDisposed)
                    {
                        if (TargetForm.InvokeRequired)
                        {
                            TargetForm.BeginInvoke((FormCloseDelegate)TargetForm.Close);
                        }
                        else
                        {
                            TargetForm.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    InternalLogger.Warn(ex.ToString());

                    if (LogManager.ThrowExceptions)
                    {
                        throw;
                    }
                }
                CreatedForm = false;
            }
            TargetForm        = null;
            TargetRichTextBox = null;
        }
Exemple #3
0
        private void target_Tools_Click(object sender, EventArgs e)
        {
            TargetForm manage = new TargetForm(this);

            this.Hide();
            manage.StartPosition = FormStartPosition.CenterScreen;
            manage.Show();
        }
Exemple #4
0
 protected override void CloseTarget()
 {
     if (CreatedForm)
     {
         TargetForm.Invoke((FormCloseDelegate)TargetForm.Close);
         TargetForm = null;
     }
 }
Exemple #5
0
        protected override void InitializeTarget()
        {
            TargetRichTextBox = System.Windows.Application.Current.MainWindow.FindName(ControlName) as System.Windows.Controls.RichTextBox;

            if (TargetRichTextBox != null)
            {
                return;
            }
            //this.TargetForm = FormHelper.CreateForm(this.FormName, this.Width, this.Height, false, this.ShowMinimized, this.ToolWindow);
            //this.CreatedForm = true;

            var openFormByName = System.Windows.Application.Current.Windows.Cast <Window>().FirstOrDefault(x => x.GetType().Name == FormName);

            if (openFormByName != null)
            {
                TargetForm = openFormByName;
                if (string.IsNullOrEmpty(this.ControlName))
                {
                    // throw new NLogConfigurationException("Rich text box control name must be specified for " + GetType().Name + ".");
                    Trace.WriteLine("Rich text box control name must be specified for " + GetType().Name + ".");
                }

                CreatedForm       = false;
                TargetRichTextBox = TargetForm.FindName(ControlName) as System.Windows.Controls.RichTextBox;

                if (this.TargetRichTextBox == null)
                {
                    // throw new NLogConfigurationException("Rich text box control '" + ControlName + "' cannot be found on form '" + FormName + "'.");
                    Trace.WriteLine("Rich text box control '" + ControlName + "' cannot be found on form '" + FormName + "'.");
                }
            }

            if (TargetRichTextBox == null)
            {
                TargetForm = new Window
                {
                    Name        = FormName,
                    Width       = Width,
                    Height      = Height,
                    WindowStyle = ToolWindow ? WindowStyle.ToolWindow : WindowStyle.None,
                    WindowState = ShowMinimized ? WindowState.Minimized : WindowState.Normal,
                    Title       = "NLog Messages"
                };
                TargetForm.Show();

                TargetRichTextBox = new System.Windows.Controls.RichTextBox {
                    Name = ControlName
                };
                var style = new Style(typeof(Paragraph));
                TargetRichTextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
                style.Setters.Add(new Setter(Block.MarginProperty, new Thickness(0, 0, 0, 0)));
                TargetRichTextBox.Resources.Add(typeof(Paragraph), style);
                TargetForm.Content = TargetRichTextBox;

                CreatedForm = true;
            }
        }
        public void UpdateTargetdeckNode(TargetdeckComponent targetdeck, TreeNode scenarioNode)
        {
            // Check to see if node exists with given targetdeck component and for corresponding targets
            TreeNode targetdeckNode = null;

            foreach (TreeNode node in scenarioNode.Nodes)
            {
                try
                {
                    if (((TargetdeckForm)node.Tag).Targetdeck == targetdeck)
                    {
                        targetdeckNode = node;
                    }
                }
                catch (NullReferenceException)
                {
                    // This node doesn't have a tag
                }
                catch (InvalidCastException)
                {
                    // Ignore; we just happened to check a node that wasn't a targetdeck node
                }
            }

            if (targetdeckNode == null)
            {
                // Create if it doesn't exist
                targetdeckNode = new TreeNode("Target Deck");
                TargetdeckForm newTgForm = new TargetdeckForm(targetdeck, this, targetdeckNode);
                targetdeckNode.Tag = newTgForm;
                scenarioNode.Nodes.Add(targetdeckNode);
            }

            // Check for target nodes
            foreach (TargetElement t in targetdeck.Targets)
            {
                TreeNode targetNode = null;
                foreach (TreeNode node in targetdeckNode.Nodes)
                {
                    if (((TargetForm)node.Tag).Target == t)
                    {
                        targetNode = node;
                        break;
                    }
                }

                if (targetNode == null)
                {
                    // No node exists for this target (meaning no form is known, as well); create a node and form
                    targetNode = new TreeNode(t.TargetName);
                    TargetForm newTForm = new TargetForm(t, this, targetNode);
                    targetNode.Tag = newTForm;
                    targetdeckNode.Nodes.Add(targetNode);
                }
            }
        }
Exemple #7
0
        public bool ProcessFormMessage(ref Message message)
        {
            if (!AllowToResize || message.Msg != WM_NCHITTEST)
            {
                return(false);
            }

            int x      = (int)(message.LParam.ToInt64() & 0xFFFF);
            int y      = (int)(message.LParam.ToInt64() >> 16);
            var cursor = TargetForm.PointToClient(new Point(x, y));

            if (TopLeft.Contains(cursor))
            {
                message.Result = (IntPtr)HTTOPLEFT;
                return(true);
            }
            else if (TopRight.Contains(cursor))
            {
                message.Result = (IntPtr)HTTOPRIGHT;
                return(true);
            }
            else if (BottomLeft.Contains(cursor))
            {
                message.Result = (IntPtr)HTBOTTOMLEFT;
                return(true);
            }
            else if (BottomRight.Contains(cursor))
            {
                message.Result = (IntPtr)HTBOTTOMRIGHT;
                return(true);
            }
            else if (Top.Contains(cursor))
            {
                message.Result = (IntPtr)HTTOP;
                return(true);
            }
            else if (Left.Contains(cursor))
            {
                message.Result = (IntPtr)HTLEFT;
                return(true);
            }
            else if (Right.Contains(cursor))
            {
                message.Result = (IntPtr)HTRIGHT;
                return(true);
            }
            else if (Bottom.Contains(cursor))
            {
                message.Result = (IntPtr)HTBOTTOM;
                return(true);
            }

            return(false);
        }
        public void OnMouseMove(MouseEventArgs e)
        {
            if (_mouseDown && AllowToMove)
            {
                var newPosition = new Point((TargetForm.Location.X - _lastLocation.X) + e.X, (TargetForm.Location.Y - _lastLocation.Y) + e.Y);

                if (!_noficiationSent)
                {
                    _noficiationSent = true;
                    FormMove?.Invoke(e, new FormMoveEventArgs(newPosition, TargetForm));
                }

                TargetForm.Location = newPosition;
                TargetForm.Update();
            }
        }
Exemple #9
0
 protected override void CloseTarget()
 {
     if (CreatedForm)
     {
         try
         {
             TargetForm.Dispatcher.Invoke(() =>
             {
                 TargetForm.Close();
                 TargetForm = null;
             });
         }
         catch
         {
         }
     }
 }
Exemple #10
0
        private int  IdentifyForms()
        {
            Type[] classes      = m_testDll.GetTypes();
            int    processCount = 0;

            foreach (Type type in classes)
            {
                object[] attributes = type.GetCustomAttributes(typeof(TargetForm), true);
                if (attributes.Length == 0)
                {
                    continue;
                }
                TargetForm formAttr = attributes[0] as TargetForm;
                if (formAttr != null)
                {
                    string formName = formAttr.FormName;
                    if (formName != null && formName.Length > 0)
                    {
                        int  handle;
                        uint procId = GetProcId(formName, out handle);
                        if (procId <= 0)
                        {
                            continue;
                        }
                        if (m_procIdToTypes.Contains(procId))
                        {
                            List <string> forms = (List <string>)m_procIdToTypes[procId];
                            forms.Add(type.FullName);
                            m_procIdToTypes[procId] = forms;
                        }
                        else
                        {
                            List <string> types = new List <string>();
                            types.Add(type.FullName);
                            m_procIdToTypes[procId] = types;
                            processCount++;
                        }
                        if (!m_FormsToHook.Contains(formName))
                        {
                            m_FormsToHook.Add(formName);
                        }
                    }
                }
            }
            return(processCount);
        }
Exemple #11
0
            protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                case (int)WinApi.Messages.WM_NCHITTEST:

                    WinApi.HitTest ht = HitTestNCA(m.HWnd, m.WParam, m.LParam);
                    if (ht != WinApi.HitTest.HTCLIENT)
                    {
                        m.Result = (IntPtr)ht;
                        return;
                    }
                    break;

                case (int)WinApi.Messages.WM_NCLBUTTONUP:
                    TargetForm.Activate();
                    break;
                }

                base.WndProc(ref m);
            }
 static void SetText(string text, TargetForm form)
 {
     form.Text = text;
 }
        private void RunTask()
        {
            Action action = () => EnsureTopMost();

            TargetForm.Invoke(action);
        }