Example #1
0
 /// <summary>
 /// 输出信息
 /// </summary>
 /// <param name="txtbox"></param>
 /// <param name="message"></param>
 /// <param name="type"></param>
 private void WriteToTextBox(System.Windows.Forms.TextBox txtbox, string message, string type, DateTime time)
 {
     try
     {
         if (txtbox.InvokeRequired)
         {
             Action actionDelegate = () =>
             {
                 string info = time + "\t" + type + "\t" + message;
                 txtbox.AppendText(info);
                 txtbox.AppendText(Environment.NewLine);
                 txtbox.AppendText(Environment.NewLine);
                 txtbox.ScrollToCaret();
             };
             txtbox.BeginInvoke(actionDelegate);
         }
         else
         {
             string info = time + "\t" + type + "\t" + message;
             txtbox.AppendText(info);
             txtbox.AppendText(Environment.NewLine);
             txtbox.AppendText(Environment.NewLine);
             txtbox.ScrollToCaret();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("写入内容时发生错误:" + txtbox.Name + ":" + message);
     }
 }
Example #2
0
 public static void AddControlText(System.Windows.Forms.TextBox ctlSelf, string Value)
 {
     if (ctlSelf.InvokeRequired)
     {
         ctlSelf.Invoke(new MethodInvoker(delegate
         {
             if (ctlSelf.Text.Length > 0)
             {
                 ctlSelf.Text += Environment.NewLine;
             }
             ctlSelf.Text          += Value;
             ctlSelf.SelectionStart = ctlSelf.Text.Length;
             ctlSelf.ScrollToCaret();
         }));
     }
     else
     {
         if (ctlSelf.Text.Length > 0)
         {
             ctlSelf.Text += Environment.NewLine;
         }
         ctlSelf.Text          += Value;
         ctlSelf.SelectionStart = ctlSelf.Text.Length;
         ctlSelf.ScrollToCaret();
     }
 }
 void BtExecutaClick(object sender, System.EventArgs e)
 {
     txConsola.Text          += this.cifsconsole.addComand(txComanda.Text);
     txComanda.Text           = "";
     txConsola.SelectionStart = txConsola.Text.Length;
     txConsola.ScrollToCaret();
     txConsola.Refresh();
 }
Example #4
0
 private void fileCopier_AfterStop(object sender)
 {
     txtOutput.Text          += "Copying was aborted...\r\nPartly Copied File was deleted...\r\n";
     txtOutput.SelectionStart = txtOutput.Text.Length;
     txtOutput.ScrollToCaret();
     fileThread.Abort();
     txtOutput.Text += "Thread was aborted...\r\n";
     MessageBox.Show("Copying was cancelled", "Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Example #5
0
        public void AddLogText(string text)
        {
            // logBox.ReadOnly = false;
            string nstr = logBox.Text.Insert(logBox.TextLength, text);

            logBox.Text           = nstr;
            logBox.SelectionStart = logBox.TextLength;
            logBox.ScrollToCaret();
            // logBox.ReadOnly = true;
        }
Example #6
0
        public static void Find1(string strRegex, bool isRegex, bool caseSensive,
                                 System.Windows.Forms.TextBox txtEdit, string ArticleName)
        {
            string ArticleText = txtEdit.Text;

            RegexOptions regOptions;

            if (caseSensive)
            {
                regOptions = RegexOptions.None;
            }
            else
            {
                regOptions = RegexOptions.IgnoreCase;
            }

            strRegex = Tools.ApplyKeyWords(ArticleName, strRegex);

            if (!isRegex)
            {
                strRegex = Regex.Escape(strRegex);
            }

            if (MatchObj == null || RegexObj == null)
            {
                int findStart = txtEdit.SelectionStart;

                RegexObj = new Regex(strRegex, regOptions);
                MatchObj = RegexObj.Match(ArticleText, findStart);
                txtEdit.SelectionStart  = MatchObj.Index;
                txtEdit.SelectionLength = MatchObj.Length;
                txtEdit.Focus();
                txtEdit.ScrollToCaret();
                return;
            }
            else
            {
                if (MatchObj.NextMatch().Success)
                {
                    MatchObj = MatchObj.NextMatch();
                    txtEdit.SelectionStart  = MatchObj.Index;
                    txtEdit.SelectionLength = MatchObj.Length;
                    txtEdit.Focus();
                    txtEdit.ScrollToCaret();
                }
                else
                {
                    txtEdit.SelectionStart  = 0;
                    txtEdit.SelectionLength = 0;
                    txtEdit.Focus();
                    txtEdit.ScrollToCaret();
                    ResetFind();
                }
            }
        }
Example #7
0
        private void XmppCon_OnReadXml(object sender, string xml)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new XmlHandler(XmppCon_OnReadXml), new object[] { sender, xml });
                return;
            }

            txtDebug.SelectionStart = txtDebug.Text.Length;
            txtDebug.Text          += ("RECV:" + xml + "\r\n");
            txtDebug.SelectionStart = txtDebug.Text.Length;
            txtDebug.ScrollToCaret();
        }
Example #8
0
        public void Imprimir(string Texto)
        {
            string Temp = EntradaHistorial.Text + Environment.NewLine + Texto;

            if (Temp.Length > 32000)
            {
                EntradaHistorial.Text = Temp.Substring(0, 32000);
            }
            else
            {
                EntradaHistorial.Text = Temp;
            }
            EntradaHistorial.SelectionStart  = EntradaHistorial.Text.Length;
            EntradaHistorial.SelectionLength = 0;
            EntradaHistorial.ScrollToCaret();
        }
 /// <summary>
 /// 记录
 /// </summary>
 /// <param name="txtInfo"></param>
 /// <param name="info"></param>
 public static void showInfo(string info)
 {
     System.Windows.Forms.TextBox txtInfo = mainForm.textBox13;
     txtInfo.AppendText(info);
     txtInfo.AppendText(Environment.NewLine);
     txtInfo.ScrollToCaret();
 }
Example #10
0
        private void ReportState(ref System.Windows.Forms.TextBox textBox1)
        {
            double currentThrottle = ((AxialAlpha.GetThrottle() + AxialBeta.GetThrottle() + AxialCharlie.GetThrottle()) / 3);

            if (altitude > 0)
            {
                textBox1.Text += "Craft is now at: " + String.Format("{0:N1}", altitude) + " meters, falling at " + String.Format("{0:N1}", velocity) + " meters per second. (Throttle: " +
                                 String.Format("{0:N3}", currentThrottle) + ").\r\n";
                DataRecorderCSV.WriteLine(String.Format("{0:N1}", altitude) + ", " + String.Format("{0:N1}", velocity) + ", " + String.Format("{0:N3}", currentThrottle));
            }
            else
            {
                if (DidVehicleLandSafely(velocity))
                {
                    textBox1.Text += "Craft landed at: " + String.Format("{0:N1}", velocity) + " meters per second.\r\n";
                    DataRecorderCSV.WriteLine("Craft landed at: " + String.Format("{0:N1}", velocity) + " meters per second.");
                }
                else
                {
                    textBox1.Text += "Craft crashed at: " + String.Format("{0:N1}", velocity) + " meters per second.\r\n";
                    DataRecorderCSV.WriteLine("Craft crashed at: " + String.Format("{0:N1}", velocity) + " meters per second.");
                }
                textBox1.SelectionStart = textBox1.Text.Length;
                textBox1.ScrollToCaret();
            }
            textBox1.Refresh();
        }
Example #11
0
        public static int DownloadFile(System.Windows.Forms.TextBox txtStatus, string szSrcFileName, string szDestFileName)
        {
            int    iRetCode = -1;
            string szURLFile, szDestFile;

            szURLFile  = myBaseURL + szSrcFileName;
            szDestFile = myBaseDir + szDestFileName;

            try
            {
                txtStatus.Text += string.Format("Sto scaricando {0}...", szURLFile);
                // txtStatus.Refresh();
                System.Net.WebClient myWebClient = new System.Net.WebClient();
                myWebClient.DownloadFile(szURLFile, szDestFile);
                LogMessage("Scaricato " + szSrcFileName + " in " + szDestFile);
                txtStatus.Text += string.Format(" fatto.\r\n");
                // txtStatus.Refresh();
                try
                {
                    txtStatus.SelectionStart = txtStatus.Text.Length;
                    txtStatus.ScrollToCaret();
                    txtStatus.Refresh();
                }
                finally
                {
                }
                iRetCode = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Impossibile effettuare il download del file " + szURLFile + ":\n" + ex.Message + ". Controllare le impostazioni del proxy.");
            }

            return(iRetCode);
        }
Example #12
0
        public void AddChatMessage(string msg, bool meTalking, bool noTalking)
        {
            if (!noTalking)
            {
                if (meTalking)
                {
                    msg = "<" + parent.gUsername + "> " + msg;
                }
                else
                {
                    msg = "<" + msUser + "> " + msg;
                }
            }

            // Now limit the text to 32k
            if (txtMsg.Text.Length > (txtMsg.MaxLength * 0.95))
            {
                txtMsg.Text = txtMsg.Text.Remove(0, (int)(txtMsg.MaxLength / 2));
            }

            // Update the message window
            txtMsg.Text          += msg + "\r\n";
            txtMsg.SelectionStart = txtMsg.Text.Length;
            txtMsg.ScrollToCaret();
        }
Example #13
0
 private void WriteLine(string text)
 {
     logTextBox.Focus();
     logTextBox.AppendText(text + Environment.NewLine);
     logTextBox.ScrollToCaret();
     System.Windows.Forms.Application.DoEvents();
 }
        /// <summary>
        /// Update the conversation box with the latest version of the conversation
        /// </summary>
        private void updateConversation()
        {
            StringBuilder sb = new StringBuilder();
            Conversation  c  = f.getConversationById(conversationId);

            foreach (DCMessage m in c.Messages)
            {
                sb.Append(m.Owner.Id);
                sb.Append(":\t");
                sb.Append(m.Content);
                sb.Append("\r\n");
            }
            tbConversation.Text = sb.ToString();

            //scroll box to bottom
            if (!tbConversation.IsDisposed)             //important check! (seems like a MS bug to me)
            {
                tbConversation.SelectionStart  = tbConversation.Text.Length;
                tbConversation.SelectionLength = 0;
                tbConversation.ScrollToCaret();
            }

            //see if a message has been added. If so, send an alert to the tray
            if (numMessages < c.Messages.Count)
            {
                if (!parent.Visible)                    //check the app is not running in the foreground
                {
                    DCMessage dcm = (DCMessage)c.Messages[c.Messages.Count - 1];
                    parent.SystemTrayAlert.Title   = "New Message Received.";
                    parent.SystemTrayAlert.Content = "You have received a new message.";
                    parent.SystemTrayAlert.Show();
                }
            }
            numMessages = c.Messages.Count;             //reset numMessages to check for future new messages
        }
Example #15
0
        /// <summary>
        /// add a new line to the status window
        /// </summary>
        /// <param name="s"></param>
        public void AddLine(string s)
        {
            if (txtStatus.Text.Length > 0)
            {
                txtStatus.Text = txtStatus.Text + Environment.NewLine + s;
            }
            else
            {
                txtStatus.Text = s;
            }

            txtStatus.ScrollToCaret();

            if ((s.ToLower().IndexOf("error") != -1) || (s.ToLower().IndexOf("problem") != -1) || (s.ToLower().IndexOf("note:") != -1))
            {
                FHasError     = true;
                btnOK.Enabled = true;
            }

            /* there can be several "success"ful patches, so look out for keyword "finished" */
            if (s.ToLower().IndexOf("finished") != -1)
            {
                btnOK.Enabled = true;
            }
        }
Example #16
0
        private void ClientSocket_OnReceive(object sender, byte[] data, int count)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new agsXMPP.net.ClientSocket.OnSocketDataHandler(ClientSocket_OnReceive), new object[] { sender, data, count });
                return;
            }
            string text = System.Text.Encoding.Default.GetString(data, 0, count);

            txtSocketDebug.SelectionStart = txtSocketDebug.TextLength;
            txtSocketDebug.Text          += ("RECV:" + text + "\r\n");
            txtSocketDebug.SelectionStart = txtSocketDebug.TextLength;
            txtSocketDebug.ScrollToCaret();
        }
Example #17
0
 public void WriteLine(string p_Line)
 {
     txtOutput.Text           += p_Line + "\r\n";
     txtOutput.SelectionLength = 0;
     txtOutput.SelectionStart  = txtOutput.Text.Length;
     txtOutput.ScrollToCaret();
 }
Example #18
0
        private void ViewMessage(string message)
        {
            textReceive.Text += message;

            // Move the cursor to the end of the text box, so the most recent text is visible
            textReceive.SelectionStart = textReceive.MaxLength;
            textReceive.ScrollToCaret();
        }
 private void txtBoxMessage_VisibleChanged(object sender, EventArgs e)
 {
     if (txtBoxMessage.Visible)
     {
         txtBoxMessage.SelectionStart = txtBoxMessage.TextLength;
         txtBoxMessage.ScrollToCaret();
     }
 }
Example #20
0
 private void AppendLog(string pAppend)
 {
     txtLog.AppendText(pAppend);
     txtLog.AppendText("\r\n");
     txtLog.SelectionStart = txtLog.Text.Length;
     txtLog.ScrollToCaret();
     Application.DoEvents();
 }
Example #21
0
        private void ShowMessage(string msg)
        {
            // Update the text
            txtReceive.Text += (msg + Environment.NewLine);

            // Move the cursor to the end of the text box, so the most recent text is visible
            txtReceive.SelectionStart = txtReceive.MaxLength;
            txtReceive.ScrollToCaret();
        }
Example #22
0
        public static void logPrintf(string i_strLog)
        {
            if (staticProcLogText != null)
            {
                staticProcLogText.Text += i_strLog;

                staticProcLogText.SelectionStart = staticProcLogText.TextLength;
                staticProcLogText.ScrollToCaret();
            }
        }
Example #23
0
 public static void add_text(TextBox tb, object s)
 {
     if (tb.InvokeRequired)
         tb.Invoke(new Action<TextBox, object>(add_text), new object[] { tb, s });
     else
     {
         tb.AppendText(s.ToString());
         tb.ScrollToCaret();
     }
 }
Example #24
0
 /// <summary>
 /// Position the carat at the end of the text to keep the last bit into view
 /// </summary>
 public static void PositionTextDisplay(TextBox box)
 {
     int length = box.Text.Length;
      if (Regex.IsMatch(box.Text, "(\r\n)$"))
      {
     length -= 2;
      }
      box.Select(length, 0);
      box.ScrollToCaret();
 }
Example #25
0
 private void ConsoleOut(string lines)
 {
     foreach (string line in lines.Split('|'))
     {
         consoleLines.Add(specialCharMatcher.Replace(line, " "));
     }
     textBoxConsole.Lines          = (string[])consoleLines.ToArray(typeof(string));
     textBoxConsole.SelectionStart = textBoxConsole.Text.Length;
     textBoxConsole.ScrollToCaret();
 }
Example #26
0
 /// <summary>Adds a line of text to the log.</summary>
 /// <param name="line">The text to add.</param>
 public void AddLine(string line)
 {
     try {
         txtLog.Text += line + Environment.NewLine;
         txtLog.Select(txtLog.Text.Length, 0);
         txtLog.ScrollToCaret();
     } catch {
         // On the off chance that we put more than 32k in this log.
     }
 }
Example #27
0
 public void PrintText(TextBox textbox, string text)
 {
     if (textbox.InvokeRequired)
     {
         textbox.Invoke(new PrintTextCallback(PrintText), textbox, text);
     }
     else
     {
         textbox.Text += text;
         textbox.SelectionStart = textbox.Text.Length;
         textbox.ScrollToCaret();
     }
 }
Example #28
0
        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="txtInfo"></param>
        /// <param name="Info"></param>
        public static void ShowInfo(System.Windows.Forms.TextBox txtInfo, string Info)
        {
            string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string info = string.Empty;

            info = time + " :" + Info;

            txtInfo.BeginInvoke((MethodInvoker) delegate() {
                txtInfo.AppendText(info);
                txtInfo.AppendText(Environment.NewLine);
                txtInfo.ScrollToCaret();
            });
        }
 public void PrintText(string txt, TextBox printBox, Form owner)
 {
     if (printBox.InvokeRequired)
     {
         invokeTextBox d = new invokeTextBox(PrintText);
         owner.Invoke(d, txt, printBox, owner);
     }
     else
     {
         printBox.Text += txt;
         printBox.Select(printBox.Text.Length, 0);
         printBox.ScrollToCaret();
     }
 }
Example #30
0
        public static void SetText(System.Windows.Forms.TextBox ctrl, string text)
        {
            if (ctrl.InvokeRequired)
            {
                object[] params_list = new object[] { ctrl, text };

                ctrl.Invoke(new SetTextDelegate(SetText), params_list);
            }
            else
            {
                ctrl.Text = ctrl.Text + text;
                ctrl.Select(ctrl.Text.Length, 0);
                ctrl.ScrollToCaret();
            }
        }
Example #31
0
 public void DisplayData(string msg, TextBox listBox1)
 {
     listBox1.Invoke(new EventHandler(delegate
     {
         //listBox1.Font = new Font("Tahoma", 10, FontStyle.Regular);
         //if (count > 720)
         //{
         //    listBox1.Text = string.Empty;
         //    count = 0;
         //}
         listBox1.Text += msg + "\r\n";
         listBox1.SelectionStart = listBox1.Text.Length;
         listBox1.ScrollToCaret();
     }));
 }
Example #32
0
        //this is invoked by the parser connection, on our own event handling thread.
        protected void ParserUpdateHandler(ParserScheduler parser, TaskReport task)
        {
            if (m_previousTask != task)
            {
                m_log.Text += "\r\n";
                Debug.WriteLine("");
            }

            string pad = "";

            for (int i = task.Depth; i > 0; i--)
            {
                pad += "    ";
            }
            m_log.Text += pad;

            switch (task.Phase)
            {
            case TaskReport.TaskPhase.started:
                m_log.Text += task.Description + " ";                      //+pad + "{\r\n";
                Debug.Write(task.Description + " ");
                break;

            case TaskReport.TaskPhase.finished:
                if (m_previousTask != task)
                {
                    m_log.Text += " ^ ";
                }
                m_log.Text += task.DurationSeconds.ToString() + " seconds";
                Debug.Write(task.DurationSeconds.ToString() + " seconds");
                //m_log.Text += "}\r\n";
                if (task.Details != null)
                {
                    m_log.Text += "Details:" + task.Details;
                }

                break;

            default:
                m_log.Text += task.Description + "    " + task.PhaseDescription;                        //+ "\r\n";
                Debug.Write(task.Description + "    " + task.PhaseDescription);
                break;
            }
            m_log.Select(m_log.Text.Length, 0);
            m_log.ScrollToCaret();

            m_previousTask = task;
        }
Example #33
0
 public void Atak(Postac atakujacy, Postac cel, TextBox komunikaty)
 {
     if(CzyTrafiono(atakujacy,cel))
     {
         Wykonaj(atakujacy,cel);
         komunikaty.Text += string.Format("Atakujący {0} trafił {1}, użył umiejętności {2}\r\n",atakujacy.Nazwa,cel.Nazwa,Nazwa);
     }
     else
     {
         komunikaty.Text += string.Format("Atakujący {0} spudłował\r\n",atakujacy.Nazwa);
     }
     komunikaty.SelectionStart = komunikaty.Text.Length - 1;
     komunikaty.SelectionLength = 0;
     komunikaty.ScrollToCaret();
     ZaplacZaUzycie(atakujacy);
 }
Example #34
0
        public void appendLine(string text,TextBox textBox)
        {
            BeginInvoke((Action)(() =>
            {
                if (textBox.Text.Length > 32000)
                {
                    //新しいファイルに保存

                    textBox.Text = "";
                }

                textBox.AppendText(DateTime.Now.ToLongTimeString() + " " + text + Environment.NewLine);
                textBox.SelectionStart = textBox.Text.Length;
                textBox.ScrollToCaret();
            }));
        }
Example #35
0
        public void LogMessage(string message, bool writeTime)
        {
            StringBuilder sb = new StringBuilder(textBoxLog.Text);

            if (writeTime)
            {
                sb.Append(DateTime.Now.ToString("T"));
                sb.Append(" ");
            }
            sb.Append(message);
            sb.Append("\r\n");

            textBoxLog.Text = sb.ToString();

            textBoxLog.Select(textBoxLog.Text.Length, 0);
            textBoxLog.ScrollToCaret();
        }
Example #36
0
 private void Log(string line)
 {
     if (txtLog.InvokeRequired)
     {
         try
         {
             txtLog.Invoke(new LogDelegate(Log), line);
         }
         catch { }
     }
     else
     {
         txtLog.Text          += line + Environment.NewLine;
         txtLog.SelectionStart = txtLog.Text.Length;
         txtLog.ScrollToCaret();
     }
 }
Example #37
0
        public void AddLogEntry(string message,string thread)
        {
            if (!threadTabs.ContainsKey(thread))
            {

                TabPage tab = new TabPage();
                tab.Location = new System.Drawing.Point(4, 22);
                tab.Name = "tab" + thread.Trim().Replace(' ', '_');
                tab.Padding = new System.Windows.Forms.Padding(3);
                tab.Size = new System.Drawing.Size(859, 226);
                tab.Text = thread;
                tab.UseVisualStyleBackColor = true;
                threadTabs[thread] = tab;
                tabControl1.TabPages.Add(tab);

                TextBox txtLogBox = new TextBox();
                txtLogBox.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                txtLogBox.Location = new System.Drawing.Point(6, 6);
                txtLogBox.Multiline = true;
                txtLogBox.Name = "txtLogBox";
                txtLogBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
                txtLogBox.Size = new System.Drawing.Size(847, 214);
                txtLogBox.TabIndex = 1;
                tab.Controls.Add(txtLogBox);
                txtLogBox.Text += "[" + DateTime.Now.ToLongTimeString() + "] - " + message + Environment.NewLine;
                txtLogBox.SelectionStart = txtLogBox.Text.Length;
                txtLogBox.ScrollToCaret();
                txtLogBox.Refresh();
            }
            else
            {
                TabPage tab = threadTabs[thread];
                TextBox txtLogBox = (TextBox) tab.Controls[0];
                txtLogBox.Text += "[" + DateTime.Now.ToLongTimeString() + "] - " + message + Environment.NewLine;
                txtLogBox.SelectionStart = txtLogBox.Text.Length;
                txtLogBox.ScrollToCaret();
                txtLogBox.Refresh();
            }

            /*
            txtLogBox.Text += "[" + DateTime.Now.ToLongTimeString() + "] - " + message + Environment.NewLine;
            txtLogBox.SelectionStart = txtLogBox.Text.Length;
            txtLogBox.ScrollToCaret();
            txtLogBox.Refresh();
             */
        }
Example #38
0
 private void DisplayText(String data)
 {
     try
     {
         if (this.InvokeRequired)
         {
             object[]     temp = { data };
             IAsyncResult ars  = this.BeginInvoke(new displayMessageDlgt(DisplayText), temp);
             this.EndInvoke(ars);
             return;
         }
         else
         {
             if (data.IndexOf("Username>") != -1)
             {
                 data = data.Substring(0, data.Length - 10);
             }
             String stemp = "";
             if (!data.StartsWith("\r\n"))
             {
                 stemp = "\r\n" + data;
                 data  = stemp;
             }
             if (!data.EndsWith("\r\n"))
             {
                 stemp = data + "\r\n";
                 data  = stemp;
             }
             if (textReaderTalk.TextLength > 32767)
             {
                 textReaderTalk.Text = "... Text removed\r\n";
             }
             textReaderTalk.Text += data;
             this.Cursor          = Cursors.Default;
             textReaderTalk.Focus();
             textReaderTalk.SelectAll();
             textReaderTalk.ScrollToCaret();
             return;
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception in the DiscplayText: " + ex.Message);
     }
 }
Example #39
0
 /*
  * limits input to integers and limits it to 0 to 100 values,
  * rough way, but it works, it would take quite some time to change it to different way
  * (like the ones on bottom that have two events for every textbox,
  *      both keypress and textchanged, maybe I'll change it eventually)
  *
  * `J` removed "LimitTextBoxRMax" and "LimitTextBoxRMin" variants that did the same thing
 */
 private void LimitTextBox(TextBox tbox)
 {
     if (tbox.Text.Length > 0)
     {
         try
         {
             int test = int.Parse(tbox.Text);
         }
         catch
         {
             tbox.Text = tbox.Text.Substring(0, tbox.Text.Length - 1);
             tbox.SelectionStart = tbox.Text.Length;
             tbox.ScrollToCaret();
         }
         if (tbox.Text.Length < 1) { tbox.Text = "0"; }   // `J` added this to prevent crash.
         else if (int.Parse(tbox.Text) > 100) tbox.Text = "100";
     }
 }
 private void UpdateTextBox(TextBox txt, string data)
 {
     if (data == null) return;
     txt.AppendText(data);
     txt.SelectionStart = txt.TextLength;
     txt.ScrollToCaret();
     txt.Invalidate();
     Application.DoEvents();
 }
Example #41
0
 private void buttonHelp_Click(object sender, EventArgs e)
 {
     string file = "";
     //string uri = "file://" + CurrentDirectory + "Readme.htm";
     //if (BufferDrawMode == BufferDrawModeGraph)
     //    uri += "#graph";
     
     //RegistryKey rk = Registry.ClassesRoot.OpenSubKey("htmlfile\\Shell\\Open\\Command");
     //string ie = (string)rk.GetValue("Default");
     bool ok = false;
     string browser = null;
     if (File.Exists("\\Windows\\iexplore.exe"))
         browser = "\\Windows\\iexplore.exe";
     else if (File.Exists("\\Windows\\iesample.exe"))        //some CE devices use iesample
         browser = "\\Windows\\iesample.exe";
     if (browser != null)
     {
         try
         {
             System.Diagnostics.Process proc = new System.Diagnostics.Process();
             //proc.StartInfo.FileName = "\"file://" + CurrentDirectory + "Readme.htm";
             proc.StartInfo.FileName = browser;                //start explicitly IE, because some other brosers (UC Browser) can not display files
             proc.StartInfo.Arguments = CurrentDirectory + "Readme.htm";
             if (BufferDrawMode == BufferDrawModeGraph)
                 proc.StartInfo.Arguments += "#graph";
             proc.StartInfo.UseShellExecute = true;
             proc.Start();
             ok = true;
             
             /*
             file = CurrentDirectory + "Readme.htm";
             StreamReader sr = new StreamReader(file);
             string doc = sr.ReadToEnd();
             if (BufferDrawMode_Save == BufferDrawModeGraph)
                 doc = doc.Remove(0, doc.IndexOf("<a name=\"graph\"></a>"));
             webbrowser = new WebBrowser();
             webbrowser.Parent = this;
             webbrowser.Dock = DockStyle.Fill;
             webbrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(eventHandler_ShowCloseButton);
             //webbrowser.Url = new Uri("http://127.0.0.1");// new Uri("\"file:" + file + "\"");
             //webbrowser.Stop();
             webbrowser.DocumentText = doc;                                          //WinCE gives IOException - can not display doc?
             webbrowser.BringToFront();
             webbrowser.Focus();     //to bring Windows title bar in background
             ok = true;
             */
         }
         catch
         {
             ok = false;
         }
     }
     if (!ok)
     {
         try
         {
             BufferDrawMode_Save = BufferDrawMode;
             BufferDrawMode = BufferDrawModeHelp;
             file = CurrentDirectory + "Readme.txt";         //max 64kB!!
             StreamReader sr = new StreamReader(file);
             string doc = sr.ReadToEnd();
             textbox = new TextBox();
             textbox.Parent = this;
             textbox.Dock = DockStyle.Fill;
             textbox.Multiline = true;
             textbox.ScrollBars = ScrollBars.Vertical;
             textbox.Text = doc;
             if (BufferDrawMode_Save == BufferDrawModeGraph)
             {
                 textbox.SelectionStart = doc.Length - 1;    //scroll to the end, then back to "Graph" to have it at top
                 textbox.ScrollToCaret();
                 textbox.SelectionStart = doc.IndexOf(". Graph\r");
                 textbox.ScrollToCaret();
             }
             textbox.BringToFront();
             textbox.Focus();
             eventHandler_ShowCloseButton(null, null);
         }
         catch (Exception ex)
         {
             MessageBox.Show("Cannot display '" + file + "'\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
             HelpEndClick(null, null);
         }
     }
 }
Example #42
0
 /// <summary>
 /// Scrolls to end.
 /// </summary>
 /// <param name="tb">The tb.</param>
 public static void ScrollToEnd(TextBox tb)
 {
     tb.SelectionStart = tb.TextLength;
     tb.ScrollToCaret();
 }
Example #43
0
        private void AddRecievedData(string data, TextBox textbox)
        {
            try
            {
                data = data.Replace("\n", "\r\n");

                textbox.AppendText(data);
                //textbox.Text += data;
                textbox.SelectionStart = textbox.Text.Length;
                textbox.ScrollToCaret();
            }
            catch (Exception ex)
            {
                Console.WriteLine("AddRecievedDataErroe:" + ex.Message);
            }
        }
Example #44
0
 private void setTextBoxStr(TextBox tb, string info)
 {
     tb.Text = info + "\r\n";
     tb.SelectionStart = tb.Text.Length;
     tb.ScrollToCaret();
 }
Example #45
0
 private static void ShowSearchResult(TextBox tb, int? start, int? length)
 {
     if ((tb != null) && tb.Visible && (tb.Text.Length > 0))
     {
         int nChars = tb.Text.Length;
         if (start.HasValue && (start.Value >= 0) && (start.Value < nChars))
         {
             tb.SelectionStart = start.Value;
             if (length.HasValue && (length.Value >= 0) && ((start.Value + length.Value) <= nChars))
                 tb.SelectionLength = Math.Min(nChars - start.Value, length.Value);
             tb.ScrollToCaret();
         }
         else
             tb.SelectAll();
     }
 }
Example #46
0
 private void ScrollToBottom(TextBox txtBox)
 {
     txtBox.SelectionStart = txtBox.Text.Length - 1;
     txtBox.SelectionLength = 1;
     txtBox.ScrollToCaret();
 }
Example #47
0
 public static void AppendText(TextBox textBox, string text)
 {
     // If the current thread is not the UI thread, InvokeRequired will be true
     if (textBox.InvokeRequired)
     {
         // If so, call Invoke, passing it a lambda expression which calls
         // UpdateText with the same label and text, but on the UI thread instead.
         textBox.Invoke((Action)(() => AppendText(textBox, text)));
         return;
     }
     // If we're running on the UI thread, we'll get here, and can safely update
     // the label's text.
     textBox.AppendText(text);
     textBox.ScrollToCaret();
 }
        private void TextBoxModify(TextBox box, string text, TextBoxChangeMode mode)
        {
            if (box.InvokeRequired)
            {
                box.Invoke(new TextBoxCallback(TextBoxModify), new object[] { box, text, mode, });
            }
            else
            {
                if (ReverseOutput)
                {
                    if (mode == TextBoxChangeMode.Append)
                        mode = TextBoxChangeMode.Prepend;
                    else if (mode == TextBoxChangeMode.AppendNewLine)
                        mode = TextBoxChangeMode.PrependNewLine;
                    else if (mode == TextBoxChangeMode.Prepend)
                        mode = TextBoxChangeMode.Append;
                    else if (mode == TextBoxChangeMode.PrependNewLine)
                        mode = TextBoxChangeMode.AppendNewLine;
                }

                if (mode == TextBoxChangeMode.Append)
                {
                    box.Text += text;
                    box.SelectionStart = box.Text.Length;
                    box.SelectionLength = 0;
                    box.ScrollToCaret();
                }
                else if (mode == TextBoxChangeMode.AppendNewLine)
                {
                    box.Text += Environment.NewLine + text;
                    box.SelectionStart = box.Text.Length;
                    box.SelectionLength = 0;
                    box.ScrollToCaret();
                }
                else if (mode == TextBoxChangeMode.Prepend)
                {
                    box.Text = text + box.Text;
                    box.SelectionStart = 0;
                    box.SelectionLength = 0;
                    box.ScrollToCaret();
                }
                else if (mode == TextBoxChangeMode.PrependNewLine)
                {
                    box.Text = text + Environment.NewLine + box.Text;
                    box.SelectionStart = 0;
                    box.SelectionLength = 0;
                    box.ScrollToCaret();
                }
                else if (mode == TextBoxChangeMode.Set)
                    box.Text = text;
                else if (mode == TextBoxChangeMode.SetNewLine)
                    box.Text = text + Environment.NewLine;
            }
        }
		/// <summary>
		/// Make sure that the end of the text in the given text box is visible.
		/// An (undesired) side effect is to focus the box and put the selection at the end of it.
		/// I cannot find any portable way to achieve the desired scrolling without doing this.
		/// </summary>
		/// <param name="textBox"></param>
		private void MakeEndOfTextVisibleAndFocus(TextBox textBox)
		{
			if (textBox.Text.Length == 0)
				return;
			// It would seem logical that we would not want the -1, so we would be asking for the position of the
			// imaginary character at the very end. However, that just always returns (0,0).
			Point endPosition = textBox.GetPositionFromCharIndex(textBox.Text.Length - 1);
			if (endPosition.X > textBox.Width)
			{
				textBox.Focus();
				textBox.Select(textBox.Text.Length, 0);
				textBox.ScrollToCaret();
			}
		}
Example #50
0
        static void CreateApplication()
        {
            // Initialize Application
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Default font used in all controls
            var font = new Font("Consolas", 12.0f);

            // ----------------------------------------------------------------
            // Create sample Text Box to be placed into the right panel.
            var textView = new TextBox
            {
                Dock = DockStyle.Fill,
                Font = font,
                HideSelection = false,
                Multiline = true,
                ShortcutsEnabled = true,
                ScrollBars = ScrollBars.Both,
                TabIndex = 1,
                Text = LOREM,
                WordWrap = false,
                // Make sure user cannot change content, since there we don't handle
                // effect of such change in the interactions across controls.
                ReadOnly = true,
            };
            
            // Ctrl-A is not implemented in Text Box control for some reason, so lets add it.
            textView.KeyDown += (sender, eArg) =>
            {
                if (eArg.Control && eArg.KeyCode == Keys.A)
                    textView.SelectAll();
            };

            // ----------------------------------------------------------------
            // Status Label to be placed at the bottom of the Form.
            var statusLabel = new Label
            {
                Dock = DockStyle.Fill,
                Font = font,
                Text = "Status",
                Height = font.Height + 20, // font height + 10px margins
            };

            // ----------------------------------------------------------------
            // Create the Tree View to be placed into the left panel.
            var treeView = new TreeView
            {
                Dock = DockStyle.Fill,
                Font = font,
                TabIndex = 0,
            };
            treeView.AfterSelect +=
                (sender, eArgs) =>
                {
                    var obj = (Tuple<int, int>)eArgs.Node.Tag;
                    statusLabel.Text = textView.Text.Substring(obj.Item1, obj.Item2);
                    textView.SelectionStart = obj.Item1;
                    textView.SelectionLength = obj.Item2;
                    textView.ScrollToCaret();
                };

            // ----------------------------------------------------------------
            // Start from vertically split container that hosts tree view and text box.
            var vertical = new SplitContainer
            {
                Orientation = Orientation.Vertical,
                Font = font,
                Dock = DockStyle.Fill,
                SplitterWidth = 10,
                TabIndex = 2,
            };
            vertical.Panel1.Controls.Add(treeView);
            vertical.Panel2.Controls.Add(textView);

            // Change cursor when dragging splitter
            vertical.SplitterMoving += (sender, eArgs) => { Cursor.Current = Cursors.NoMoveHoriz; };
            vertical.SplitterMoved += (sender, eArgs) => { Cursor.Current = Cursors.Default; };

            // ----------------------------------------------------------------
            // Now horizontally split container to host status label at the bottom panel, and
            // the rest of the controls at the top panel.
            var horizontal = new SplitContainer
            {
                Orientation = Orientation.Horizontal,
                Font = font,
                Dock = DockStyle.Fill,
                SplitterWidth = 10,
                FixedPanel = FixedPanel.Panel2, // Force Status bar to not resize
                IsSplitterFixed = true,
            };
            horizontal.Panel1.Controls.Add(vertical);
            horizontal.Panel2.Controls.Add(statusLabel);

            // Change cursor when dragging splitter
            horizontal.SplitterMoving += (sender, eArgs) => { Cursor.Current = Cursors.NoMoveVert; };
            horizontal.SplitterMoved += (sender, eArgs) => { Cursor.Current = Cursors.Default; };

            // ----------------------------------------------------------------
            // Lastly create top level Form and add horizontally split container to it.
            var form = new Form();
            form.Text = "Winforms template";

            // Initial form size.
            form.ClientSize = new Size { Width = 800, Height = 600 };
            form.Controls.Add(horizontal);

            TextToTree(treeView, textView.Text);

            // Finally, start the main event loop of our application.
            Application.Run(form);
        }
Example #51
0
 /// <summary>
 /// Hiển thị Log lên textbox
 /// </summary>
 /// <param name="txt"></param>
 /// <param name="text"></param>
 private void SetLog(TextBox txt, object text)
 {
     if (txt != null && text != null)
     {
         Invoke((MethodInvoker)delegate
         {
             txt.Text += text + Environment.NewLine;
             txt.SelectionStart = txt.Text.Length;
             txt.ScrollToCaret();
         });
     }
 }
Example #52
0
        private void CreateTab(string tabName, string tabData)
        {
            if (tabName != "")
            {
                workflows.Add(tabName);

                tabName = Path.GetFileNameWithoutExtension(tabName);
            }
            else
            {
                workflows.Add("");

                // Get name
                int number = 0;

                for (int i = 0; i < tabControl1.TabPages.Count; i++)
                {
                    // Get number
                    if (tabControl1.TabPages[i].Text.StartsWith("Workflow ") == true)
                    {
                        string txt = tabControl1.TabPages[i].Text.Replace("Workflow ", "");
                        txt = txt.Replace("*", "");
                        txt = txt.Trim();

                        try
                        {
                            number = Convert.ToInt32(txt);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }

                tabName = "Workflow " + (number + 1) + " *";
            }

            //
            // Create tab
            //

            TabPage newTab = new TabPage();
            newTab.Location = new System.Drawing.Point(4, 22);
            newTab.Padding = new System.Windows.Forms.Padding(3);
            newTab.Size = new System.Drawing.Size(459, 328);
            newTab.TabIndex = 0;
            newTab.Text = tabName;
            newTab.UseVisualStyleBackColor = true;

            TextBox textBox = new TextBox();
            textBox.AllowDrop = true;
            textBox.Dock = System.Windows.Forms.DockStyle.Fill;
            textBox.Font = new System.Drawing.Font("Lucida Console", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            textBox.Location = new System.Drawing.Point(3, 3);
            textBox.Multiline = true;
            textBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            textBox.Size = new System.Drawing.Size(453, 322);
            textBox.TabIndex = 0;
            textBox.Text = tabData;
            textBox.SelectionLength = 0;
            textBox.SelectionStart = textBox.TextLength;
            textBox.ScrollToCaret();
            textBox.DragDrop += new System.Windows.Forms.DragEventHandler(this.textBox_DragDrop);
            textBox.DragEnter += new System.Windows.Forms.DragEventHandler(this.textBox_DragEnter);
            textBox.DragOver += new System.Windows.Forms.DragEventHandler(this.textBox_DragOver);
            textBox.MouseHover += new System.EventHandler(this.textBox_MouseHover);
            textBox.TextChanged += new System.EventHandler(this.textBox_TextChanged);

            newTab.Controls.Add(textBox);

            tabControl1.TabPages.Add(newTab);

            tabControl1.SelectedIndex = tabControl1.TabPages.Count - 1;

            WriteStatistics();
        }
        public static void log(TextBox textbox, string input)
        {
            textbox.Text += "sms@launcher: " + input + newLine;
            textbox.Select(textbox.Text.Length, 0);
            textbox.ScrollToCaret();
            textbox.ReadOnly = true;

            System.Threading.Thread.Sleep(10);
            log(input);
        }
Example #54
0
 void AddScenarioSeparator(TextBox textBox)
 {
     textBox.Text += "----------------------------------------------------------" + Environment.NewLine;
     textBox.SelectAll();
     textBox.ScrollToCaret();
 }
Example #55
0
 private void Log(TextBox txt, string str)
 {
     txt.AppendText(str + Environment.NewLine);
     txt.Select(txt.TextLength - 1, 0);
     txt.ScrollToCaret();
 }
Example #56
0
 /// <summary>
 /// Scrolls the view of multiline Textbox to bottom.
 /// </summary>
 /// <param name="tb"></param>
 public static void TextBoxScrollToBottom(TextBox tb)
 {
     // autoscroll to bottom
     tb.SelectionStart = tb.Text.Length;
     tb.ScrollToCaret();
 }
 //Scroll to the end
 private static void ScrollToEndOfTextbox(TextBox textbox)
 {
     textbox.SelectionStart = textbox.Text.Length;
     textbox.ScrollToCaret();
 }
Example #58
0
 /// <summary>
 /// Scroll to the end of TextBox and go back by 1 character.
 /// </summary>
 /// <param name="tbx">TextBox</param>
 private void ScrollToEnd(TextBox tbx)
 {
     tbx.SelectionStart = tbx.Text.Length - 1;
     tbx.Focus();
     tbx.ScrollToCaret();
 }
Example #59
0
        private void SetText(Dictionary<TextBox, StringBuilder> textTmp, TextBox textBox, String str)
        {
            if (textBox.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(SetText);
                form.Invoke(d, new object[] { textTmp, textBox, str });
            }
            else
            {
                StringBuilder strb;
                if (!textTmp.ContainsKey(textBox))
                {
                    strb = new StringBuilder();
                    textTmp.Add(textBox, strb);
                }
                else
                {
                    strb = (StringBuilder)textTmp[textBox];
                }
                strb.Append(str);
                if (strb.Length > 50000)
                {
                    strb.Remove(0, 10000);
                    textBox.Text = strb.ToString();
                }
                else
                {
                    textBox.AppendText(str);
                }

                textBox.SelectionStart = textBox.Text.Length;
                textBox.ScrollToCaret();
            }
        }
 private void CreateReportForm(ReflectorEventList MainReflector)
 {
     Task.Factory.StartNew(() =>
         {
             Form ReportForm = new Form();
             ReportForm.Size = new Size(500, 500);
             ReportForm.Text = "Reports";
             //
             // Add a Docked MultiLine TextBox
             //
             TextBox txtReports = new TextBox();
             txtReports.ReadOnly = true;
             txtReports.Multiline = true;
             txtReports.Location = new Point(0, 0);
             txtReports.Dock = DockStyle.Fill;
             txtReports.Cursor = Cursors.No;
             txtReports.ScrollBars = ScrollBars.Both;
             txtReports.TextChanged += (s, e) =>
             {
                 txtReports.SelectionStart = txtReports.Text.Length;
                 txtReports.ScrollToCaret();
             };
             ReportForm.Controls.Add(txtReports);
             //
             // Reflect this class reports to report form text box
             //
             MainReflector.ReflectedReports += (s, e) => txtReports.Invoke(new Action(delegate { txtReports.Text += e.Message + Environment.NewLine; }));
             //
             ReportForm.ShowDialog();
         });
 }