Beispiel #1
0
        private void fToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string FilePath;
            HImage Img = new HImage();

            //Open Dialog to let user select image
            if (openImg.ShowDialog() == DialogResult.OK)
            {
                HGraphics.allObj.Clear();
                Control.CheckForIllegalCrossThreadCalls = false;
                //Display the file path on the title
                this.Text = openImg.FileName;
                FilePath  = openImg.FileName.Replace("\\", "/");
                Img.ReadImage(FilePath);
                hWindowControl.SetFullImagePart(Img);
                //Display the image on HALCON window
                HGraphics.allObj["pic"] = new HObject(Img);
                HGraphics.display();
                Img.Dispose();
                LogTextBox.Text += FilePath + "\n";
                //Scroll log to the bottom
                LogTextBox.SelectionStart = LogTextBox.Text.Length;
                LogTextBox.ScrollToCaret();
            }
        }
Beispiel #2
0
 public void Log(string text)
 {
     if (LogTextBox.InvokeRequired)
     {
         SafeCallDelegate del = new SafeCallDelegate(Log);
         LogTextBox.Invoke(del, new object[] { text });
     }
     else
     {
         string currentTime = string.Format("[{0:HH}:{0:mm}:{0:ss}]", DateTime.Now);
         LogTextBox.Text          += currentTime + text + Environment.NewLine;
         toolStripStatusLabel.Text = text.StartsWith(">> ") ? text.Substring(3) : text;
         LogTextBox.SelectionStart = LogTextBox.TextLength;
         LogTextBox.ScrollToCaret();
         if (text == ">> state: Disconnected")
         {
             ServerTextBox.BackColor = Color.LightCoral;
             Icon = notifyIcon.Icon = Resource.RedIcon;
         }
         else if (text == ">> state: Connected")
         {
             ServerTextBox.BackColor = Color.LightGreen;
             Icon = notifyIcon.Icon = Resource.GreenIcon;
         }
         else if (text.StartsWith(">> error:"))
         {
             MessageBox.Show(text.Substring(3));
         }
     }
 }
 private void AppendLog(string text)
 {
     if (this.Disposing || this.IsDisposed)
     {
         return;
     }
     if (LogTextBox.InvokeRequired)
     {
         LogTextBox.Invoke(new EventHandler((s, e) =>
         {
             lock (LogTextBox)
             {
                 LogTextBox.AppendText(text);
             }
             LogTextBox.ScrollToCaret();
         }), this, null);
     }
     else
     {
         lock (LogTextBox)
         {
             LogTextBox.AppendText(text);
         }
         LogTextBox.ScrollToCaret();
     }
 }
Beispiel #4
0
        private void UpdateContent()
        {
            if (string.IsNullOrEmpty(Logging.LogFilePath))
            {
                return;
            }
            try
            {
                using (StreamReader reader = new StreamReader(new FileStream(Logging.LogFilePath,
                                                                             FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                {
                    reader.BaseStream.Seek(lastOffset, SeekOrigin.Begin);

                    string line    = "";
                    bool   changed = false;
                    while ((line = reader.ReadLine()) != null)
                    {
                        changed = true;
                        LogTextBox.AppendText(line + Environment.NewLine);
                    }

                    if (changed)
                    {
                        LogTextBox.ScrollToCaret();
                    }

                    lastOffset = reader.BaseStream.Position;
                }
            }
            catch (FileNotFoundException)
            {
            }
        }
Beispiel #5
0
        private void InitContent()
        {
            if (string.IsNullOrEmpty(Logging.LogFilePath))
            {
                return;
            }
            using (StreamReader reader = new StreamReader(new FileStream(Logging.LogFilePath,
                                                                         FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                if (reader.BaseStream.Length > BACK_OFFSET)
                {
                    reader.BaseStream.Seek(-BACK_OFFSET, SeekOrigin.End);
                    reader.ReadLine();
                }

                string line = "";
                while ((line = reader.ReadLine()) != null)
                {
                    LogTextBox.AppendText(line + Environment.NewLine);
                }

                LogTextBox.ScrollToCaret();

                lastOffset = reader.BaseStream.Position;
            }
        }
Beispiel #6
0
 void Log(string text)
 {
     if (LogTextBox.Text != "")
     {
         LogTextBox.Text += Environment.NewLine;
     }
     LogTextBox.Text          += DateTime.Now.ToString() + "\t" + text;
     LogTextBox.SelectionStart = LogTextBox.Text.Length;
     LogTextBox.ScrollToCaret();
 }
Beispiel #7
0
 public void AppendTextBox(string value)
 {
     if (InvokeRequired)
     {
         this.Invoke(new Action <string>(AppendTextBox), new object[] { value });
         return;
     }
     LogTextBox.ScrollToCaret();
     LogTextBox.Text = value;
 }
Beispiel #8
0
        void TrayNotifyIcon_MouseClick(object sender, MouseEventArgs e)
        {
            WindowState   = FormWindowState.Normal;
            ShowInTaskbar = true;

            TrayNotifyIcon.Visible = false;

            LogTextBox.SelectionStart = LogTextBox.Text.Length;
            LogTextBox.ScrollToCaret();
        }
Beispiel #9
0
        public void LogWrite(string msg)
        {
            if (InvokeRequired)
            {
                Invoke((MethodInvoker)(() => { LogWrite("(*)" + msg); }));
                return;
            }

            LogTextBox.AppendText(msg);
            LogTextBox.SelectionStart = LogTextBox.TextLength - 1;
            LogTextBox.ScrollToCaret();
        }
 private void AppendLog(string line)
 {
     if (LogTextBox.InvokeRequired)
     {
         LogTextBox.Invoke(new EventHandler((s, e) => {
             LogTextBox.AppendText(line);
             LogTextBox.ScrollToCaret();
         }), this, null);
     }
     else
     {
         LogTextBox.AppendText(line);
         LogTextBox.ScrollToCaret();
     }
 }
Beispiel #11
0
 //----------------------------------------------------------------------
 public void AppendAndScrollText(string text)
 {
     if (InvokeRequired)
     {
         Invoke(new Action <string>(AppendAndScrollText), new[] { text });
     }
     else
     {
         var startIndex = LogTextBox.TextLength;
         LogTextBox.AppendText(text + Environment.NewLine);
         var endIndex = LogTextBox.TextLength;
         LogTextBox.Select(startIndex, endIndex - startIndex);
         LogTextBox.ScrollToCaret();
     }
 }
Beispiel #12
0
 // Add a line to the activity log text box
 void WriteLog(string message, bool clear)
 {
     // Replace content
     if(clear)
     {
         LogTextBox.Text = string.Format("{0}: {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), message);
     }
     // Add new line
     else
     {
         LogTextBox.Text += Environment.NewLine + string.Format("{0}: {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), message);
     }
     // Scroll to bottom
     LogTextBox.SelectionStart = LogTextBox.Text.Length;
     LogTextBox.ScrollToCaret();
 }
Beispiel #13
0
 private void LogMessage(string text)
 {
     if (!LogTextBox.IsDisposed)
     {
         if (LogTextBox.InvokeRequired)
         {
             Action d = new Action(() => LogMessage(text));
             LogTextBox.BeginInvoke(d);
         }
         else
         {
             LogTextBox.AppendText(text + "\r\n");
             LogTextBox.SelectionStart = LogTextBox.Text.Length;
             LogTextBox.ScrollToCaret();
         }
     }
 }
Beispiel #14
0
        //   MainWindow mw = new MainWindow();

        // to do:
        //fix loggin in lofg window fi possible
        //continue online solve in scopefus not to use the data ....



        public void Log(string text)
        {
            if (LogTextBox.InvokeRequired)
            {
                Invoke(new Action <string>(Log), new object[] { text });
                return;
            }


            if (LogTextBox.Text != "")
            {
                LogTextBox.Text += Environment.NewLine;
            }
            LogTextBox.Text          += DateTime.Now.ToLongTimeString() + "  " + text;
            LogTextBox.SelectionStart = LogTextBox.Text.Length;
            LogTextBox.ScrollToCaret();
        }
Beispiel #15
0
            public void WriteLog(string Message, bool Prefix = true, InfoType InfoType = Form1.InfoType.None)
            {
            string LocalDate = MakeMenuLib.MiscFunc.GetLocalDate();
            string LocalTime = MakeMenuLib.MiscFunc.GetLocalTime();
                string LogDate = " [ " + LocalTime + " ]  ";
                string MessageType = string.Empty;

                switch (InfoType)
                {
                    case InfoType.Information:
                        {
                            MessageType = "Information: ";
                            break;
                        }

                    case InfoType.Exception:
                        {
                            MessageType = "Error: ";
                            break;
                        }

                    case InfoType.Critical:
                        {
                            MessageType = "Critical: ";
                            break;
                        }

                    case InfoType.None:
                        {
                            MessageType = "";
                            break;
                        }
                }
          
            if (Prefix == true)
                    LogTextBox.Text += @".\\" + UserName + ">" + LogDate + MessageType + Message + Environment.NewLine;
                else
                    LogTextBox.Text += MessageType + Message + Environment.NewLine;

                if ((LogTextBox.Text.Split(Environment.NewLine.ToCharArray()).Count() - 1) >= 12)
                {
                    LogTextBox.ScrollBars = ScrollBars.Vertical;
                    LogTextBox.SelectionStart = LogTextBox.Text.Length;
                    LogTextBox.ScrollToCaret();
                }
            }
Beispiel #16
0
 /// <summary>
 /// Clear log window contents
 /// </summary>
 public void Clear()
 {
     if (LogTextBox != null)
     {
         Utilities.CallActionSafelyAndWait(LogTextBox, new Action(() =>
         {
             LogTextBox.Clear();
             LogTextBox.ScrollToCaret();
         }));
     }
     if (DebugLogTextBox != null)
     {
         Utilities.CallActionSafelyAndWait(DebugLogTextBox, new Action(() =>
         {
             DebugLogTextBox.Clear();
             DebugLogTextBox.ScrollToCaret();
         }));
     }
 }
Beispiel #17
0
 private void Logbox_Update(object sender, LogboxEventArgs e)
 {
     if (LogTextBox.InvokeRequired)
     {
         var deleg = new SetLogboxMessage(Logbox_Update);
         try // to catch ObjectDisposedException if there are still events outstanding when the MainGUI is already gone
         {
             Invoke(deleg, sender, e);
         }
         catch
         {
         }
     }
     else
     {
         LogTextBox.Text          += e.message + Environment.NewLine;
         LogTextBox.SelectionStart = LogTextBox.Text.Length;
         LogTextBox.ScrollToCaret();
         LogTextBox.Refresh();
     }
 }
Beispiel #18
0
 private void LogMessage(string text, Color color)
 {
     if (!LogTextBox.IsDisposed)
     {
         if (LogTextBox.InvokeRequired)
         {
             Action d = new Action(() => LogMessage(text, color));
             LogTextBox.BeginInvoke(d);
         }
         else
         {
             // Apply color and apped text.
             LogTextBox.SelectionStart  = LogTextBox.TextLength;
             LogTextBox.SelectionLength = 0;
             LogTextBox.SelectionColor  = color;
             LogTextBox.AppendText(text + "\r\n");
             LogTextBox.SelectionColor = LogTextBox.ForeColor;
             LogTextBox.SelectionStart = LogTextBox.Text.Length;
             LogTextBox.ScrollToCaret();
         }
     }
 }
Beispiel #19
0
 private void Board_Log(Object sender, LogEventArgs e)
 {
     LogTextBox.AppendText(String.Format("[{0:MM/dd/yy hh:mm:ss.ff tt}] {1}{2}", DateTime.Now, e.Message, Environment.NewLine));
     LogTextBox.SelectionStart = LogTextBox.TextLength;
     LogTextBox.ScrollToCaret();
 }
Beispiel #20
0
        private void LogReader()
        {
            try
            {
                Invoke((MethodInvoker) delegate
                {
                    for (; lastidx < LOG.Logger.Logs.Count; lastidx++)
                    {
                        var line = LOG.Logger.Logs[lastidx];
                        LogTextBox.SelectionColor = Color.Yellow;
                        LogTextBox.AppendText("[");
                        LogTextBox.SelectionColor = Color.Cyan;
                        LogTextBox.AppendText(line.Time.ToString("yyyy-MM-dd HH:mm:ss"));
                        LogTextBox.SelectionColor = Color.Yellow;
                        LogTextBox.AppendText("]");
                        LogTextBox.SelectionColor = LogTextBox.ForeColor;

                        switch (line.Level)
                        {
                        case LogLevel.Debug:
                        case LogLevel.Trace:
                            LogTextBox.SelectionColor = Color.Gray;
                            LogTextBox.AppendText(" [");
                            LogTextBox.AppendText(line.Level.ToString().ToUpper());
                            LogTextBox.AppendText("] ");
                            LogTextBox.SelectionFont = LogTextBox.Font;
                            LogTextBox.AppendText(line.Message);
                            LogTextBox.SelectionFont = LogTextBox.Font;
                            break;

                        case LogLevel.Browser:
                            LogTextBox.SelectionColor = Color.LightGreen;
                            LogTextBox.AppendText(" ");
                            LogTextBox.AppendText(line.Message);
                            LogTextBox.SelectionFont = LogTextBox.Font;
                            break;

                        case LogLevel.Info:
                            LogTextBox.SelectionColor = Color.LightGray;
                            LogTextBox.AppendText("  [");
                            LogTextBox.AppendText(line.Level.ToString().ToUpper());
                            LogTextBox.AppendText("] ");
                            LogTextBox.SelectionFont = LogTextBox.Font;
                            LogTextBox.AppendText(line.Message);
                            LogTextBox.SelectionFont = LogTextBox.Font;
                            break;

                        case LogLevel.Warning:
                            LogTextBox.SelectionColor = Color.Yellow;
                            LogTextBox.AppendText("  [");
                            LogTextBox.AppendText(line.Level.ToString().ToUpper().Substring(0, 4));
                            LogTextBox.AppendText("] ");
                            LogTextBox.SelectionColor = LogTextBox.ForeColor;
                            LogTextBox.SelectionColor = Color.FromArgb(255, 233, 127);
                            LogTextBox.SelectionFont  = LogTextBox.Font;
                            LogTextBox.AppendText(line.Message);
                            LogTextBox.SelectionFont = LogTextBox.Font;
                            break;

                        case LogLevel.Error:
                            LogTextBox.SelectionColor = Color.Red;
                            LogTextBox.AppendText(" [");
                            LogTextBox.AppendText(line.Level.ToString().ToUpper());
                            LogTextBox.AppendText("] ");
                            LogTextBox.SelectionColor = Color.MistyRose;
                            LogTextBox.SelectionFont  = LogTextBox.Font;
                            LogTextBox.AppendText(line.Message);
                            LogTextBox.SelectionFont = LogTextBox.Font;
                            break;
                        }

                        LogTextBox.SelectionColor = LogTextBox.ForeColor;
                        LogTextBox.AppendText("\n");
                        if (checkBox1.Checked)
                        {
                            LogTextBox.ScrollToCaret();
                        }
                    }
                });
            }
            catch { }
        }
Beispiel #21
0
        private void Logger_OnLog(string log, LogMessageType logType)
        {
            Console.WriteLine(log);

            void LogCallback()
            {
                LogTextBox.SelectionStart  = LogTextBox.Text.Length;
                LogTextBox.SelectionLength = 0;

                switch (logType)
                {
                case LogMessageType.Global:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E9E9E9");
                    break;

                case LogMessageType.Team:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FF006C");
                    break;

                case LogMessageType.Guild:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#975FFF");
                    break;

                case LogMessageType.Alliance:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FFAD42");
                    break;

                case LogMessageType.Party:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#00E4FF");
                    break;

                case LogMessageType.Sales:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#B3783E");
                    break;

                case LogMessageType.Seek:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E4A0D5");
                    break;

                case LogMessageType.Noob:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#D3AA07");
                    break;

                case LogMessageType.Admin:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FF00FF");
                    break;

                case LogMessageType.Private:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#7EC3FF");
                    break;

                case LogMessageType.Info:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#46A324");
                    break;

                case LogMessageType.FightLog:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#9DFF00");
                    break;

                case LogMessageType.Public:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#EF3A3E");
                    break;

                case LogMessageType.Arena:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#F16392");
                    break;

                case LogMessageType.Community:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#9EC79D");
                    break;

                case LogMessageType.Sender:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#1B96FF");
                    break;

                case LogMessageType.Default:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E8890D");
                    break;

                case LogMessageType.Divers:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#3498db");
                    break;

                case LogMessageType.Error:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FF0033");
                    break;

                default:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E8890D");
                    break;
                }

                var text = $"[{DateTime.Now.ToLongTimeString()}] {log}";

                LogTextBox.SelectedText   = text + "\r\n";
                LogTextBox.SelectionColor = LogTextBox.ForeColor;
                LogTextBox.ScrollToCaret();
            }

            LogTextBox.Invoke((Action)LogCallback);
        }
Beispiel #22
0
        private void WriteLineSafe(LogType type, string format, params object[] arg)
        {
            string text = String.Format(format, arg);
            string zoneText = "";
            string frontText, backText;

            if (text[0] == '[' && text[3] == ']' && text[4] == ' ')
            {
                zoneText = text.Substring(0, 5);
                text     = text.Substring(5);
            }
            int index = text.IndexOf(':');

            if (index >= 0)
            {
                frontText = text.Substring(0, index + 1);
                backText  = text.Substring(index + 1) + "\r\n";
            }
            else
            {
                frontText = string.Empty;
                backText  = text + "\r\n";
            }
            Color textColor = Color.Black;

            switch (type)
            {
            case LogType.Player:
                textColor = Color.Blue;
                break;

            case LogType.Opponent:
                textColor = Color.Red;
                break;

            case LogType.Debug:
            case LogType.DebugVerbose:
                textColor = Color.Gray;
                break;

            default:
                break;
            }

            if (DebugLogTextBox != null)
            {
                Utilities.CallActionSafelyAndWait(DebugLogTextBox, new Action(() =>
                {
                    if (!string.IsNullOrEmpty(frontText))
                    {
                        DebugLogTextBox.AppendText(zoneText + frontText, textColor, true);
                    }
                    DebugLogTextBox.AppendText(backText, textColor, false);
                    DebugLogTextBox.ScrollToCaret();
                }));
            }

            if (LogTextBox != null && type != LogType.Debug)
            {
                Utilities.CallActionSafelyAndWait(LogTextBox, new Action(() =>
                {
                    if (!string.IsNullOrEmpty(frontText))
                    {
                        LogTextBox.AppendText(frontText, textColor, true);
                    }
                    LogTextBox.AppendText(backText, textColor, false);
                    LogTextBox.ScrollToCaret();
                }));
            }
        }
 private void LogTextBox_TextChanged(object sender, EventArgs e)
 {
     // scroll to end
     LogTextBox.SelectionStart = LogTextBox.TextLength;
     LogTextBox.ScrollToCaret();
 }
Beispiel #24
0
 private void UpdateLog()
 {
     LogTextBox.Text           = Observer.Log;
     LogTextBox.SelectionStart = LogTextBox.TextLength;
     LogTextBox.ScrollToCaret();
 }
Beispiel #25
0
 public bool TriggerWrapText()
 {
     LogTextBox.WordWrap = !LogTextBox.WordWrap;
     LogTextBox.ScrollToCaret();
     return(LogTextBox.WordWrap);
 }
Beispiel #26
0
 public void ScrollToCaret()
 {
     LogTextBox.ScrollToCaret();
 }
Beispiel #27
0
        private void Logger_OnLog(string log, LogMessageType logType)
        {
            Console.WriteLine(log);

            void LogCallback()
            {
                LogTextBox.SelectionStart  = LogTextBox.Text.Length;
                LogTextBox.SelectionLength = 0;

                switch (logType)
                {
                case LogMessageType.Global:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E9E9E9");
                    break;

                case LogMessageType.Team:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FF006C");
                    break;

                case LogMessageType.Guild:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#975FFF");
                    break;

                case LogMessageType.Alliance:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FFAD42");
                    break;

                case LogMessageType.Party:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#00E4FF");
                    break;

                case LogMessageType.Sales:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#B3783E");
                    break;

                case LogMessageType.Seek:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E4A0D5");
                    break;

                case LogMessageType.Noob:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#D3AA07");
                    break;

                case LogMessageType.Admin:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FF00FF");
                    break;

                case LogMessageType.Private:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#7EC3FF");
                    break;

                case LogMessageType.Info:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#46A324");
                    break;

                case LogMessageType.FightLog:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#9DFF00");
                    break;

                case LogMessageType.Public:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#EF3A3E");
                    break;

                case LogMessageType.Arena:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#F16392");
                    break;

                case LogMessageType.Community:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#9EC79D");
                    break;

                case LogMessageType.Sender:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#1B96FF");
                    break;

                case LogMessageType.Default:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E8890D");
                    break;

                case LogMessageType.Divers:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#3498db");
                    break;

                default:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E8890D");
                    break;
                }
                var valueOrig = string.Empty;

                if (log.Contains("Received:") || log.Contains("Send"))
                {
                    switch (log.Split(':')[0])
                    {
                    case "Received":
                        valueOrig = "Serveur";
                        break;

                    case "Send":
                        valueOrig = "Client";
                        break;
                    }
                    string[] row1         = { DateTime.Now.ToLongTimeString(), valueOrig, log.Split('(')[1].Split(')')[0], log.Split('-')[1].Replace(" ", "") };
                    var      listViewItem = new ListViewItem(row1);
                    PacketsListView.Items.Add(listViewItem);

                    if (log.Contains("Send"))
                    {
                        PacketsListView.Items[PacketsListView.Items.Count - 1].ForeColor = ColorTranslator.FromHtml("#F16392");
                    }
                    if (log.Contains("Received"))
                    {
                        PacketsListView.Items[PacketsListView.Items.Count - 1].ForeColor = ColorTranslator.FromHtml("#9EC79D");
                    }
                }
                else if (log.Contains("NO HANDLER"))
                {
                    NoHandlersListBox.Items.Add(log.Split(':')[1].Replace(" ", ""));
                }
                else
                {
                    var text = $"[{DateTime.Now.ToLongTimeString()}] {log}";
                    LogTextBox.SelectedText   = text + "\r\n";
                    LogTextBox.SelectionColor = LogTextBox.ForeColor;
                    LogTextBox.ScrollToCaret();
                }
            }

            LogTextBox.Invoke((Action)LogCallback);
        }
Beispiel #28
0
 private void Log(string logString)
 {
     LogTextBox.Text          += logString + "\n";
     LogTextBox.SelectionStart = LogTextBox.Text.Length;
     LogTextBox.ScrollToCaret();
 }
Beispiel #29
0
 private void Logger_OnWriteException(string timestamp, Exception ex)
 {
     StatusBarLogValue.Text = ex.Message;
     LogTextBox.Text       += timestamp + ex.Message + "\r\n" + ex.StackTrace + "\r\n";
     LogTextBox.ScrollToCaret();
 }
Beispiel #30
0
        private void hWindowControl_HMouseDown(object sender, HMouseEventArgs e)
        {
            //Display click button
            if (e.Button == MouseButtons.Left)
            {
                this.LastMouseClickX = e.X;
                this.LastMouseClickY = e.Y;
                LogTextBox.Text     += "Left Click: ";
            }
            else if (e.Button == MouseButtons.Right)
            {
                LogTextBox.Text += "Right Click: ";
                //if needed, you can use this code to display context menu by right click on the HALCON window
                contextMenuStrip1.Show(this,
                                       new System.Drawing.Point(Form.MousePosition.X - this.Location.X - 6, Form.MousePosition.Y - this.Location.Y - 28));
                Log(HGraphics.ListKeys());
            }
            else if (e.Button == MouseButtons.Middle)
            {
                LogTextBox.Text += "Middle Click: ";
                for (int i = 0; i < HGraphics.allObj.Count; i++)
                {
                    Log(HGraphics.allObj.ElementAt(i).Key);
                }
            }
            //Display click position
            LogTextBox.Text += "(" + Math.Round(e.Y, 3).ToString() + ", " + Math.Round(e.X, 3).ToString() + ")\n";
            //Scroll the textbox automatically to the bottom
            LogTextBox.SelectionStart = LogTextBox.Text.Length;
            LogTextBox.ScrollToCaret();


            //XML file Test
            using (XmlWriter writer = XmlWriter.Create("Config.xml"))
            {
                writer.WriteStartElement("Configuration");
                writer.WriteStartElement("Configuration");
                writer.WriteElementString("ID", "0983");
                writer.WriteEndElement();
                writer.WriteStartElement("Configuration");
                writer.WriteElementString("ID", "0984");
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndDocument();

                /*String directoryName = "C:\\Consolidated";
                 * DirectoryInfo dirInfo = new DirectoryInfo(directoryName);
                 * if (dirInfo.Exists == false)
                 * Directory.CreateDirectory(directoryName);
                 *
                 * List<String> MyMusicFiles = Directory
                 * .GetFiles("C:\\Music", "*.*", SearchOption.AllDirectories).ToList();
                 *
                 * foreach (string file in MyMusicFiles)
                 * {
                 * FileInfo mFile = new FileInfo(file);
                 * // to remove name collusion
                 * if (new FileInfo(dirInfo + "\\" + mFile.Name).Exists == false)
                 * mFile.MoveTo(dirInfo + "\\" + mFile.Name);
                 * }
                 *
                 *
                 *
                 * string source = @"C:\Music";
                 * string[] directories = Directory.GetDirectories(source);
                 * string consolidated = Path.Combine(source, "Consolidated")
                 * Directory.CreateDirectory(consolidated);
                 * foreach(var directory in directories) {
                 * Directory.Move(directory, consolidated);
                 * }*/
            }
        }