Strona 1 z 1

Automatyczne przewijanie textBox-a

: wtorek 16 lut 2016, 14:18
autor: StaryAnoda
Cześć !

Zacząłem pisać prosty terminal, czy mógłby mi ktoś podpowiedzieć jak zrobić przewijanie textBox-a tak aby nowe dane miał na wierzchu bez konieczności przewijania.

Kod: Zaznacz cały

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{

    public partial class Terminal : Form
    {
        string InputData = String.Empty;
        delegate void SetTextCallback(string text);

        public Terminal()
        {
            InitializeComponent();
            serialPort1.PortName = "COM3";
            serialPort1.BaudRate = 9600;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
            {
                serialPort1.WriteLine("1");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
         if (serialPort1.IsOpen)
            {
                serialPort1.WriteLine("0");
            }           
        }

        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            InputData = serialPort1.ReadExisting();
            if (InputData != String.Empty)
            {
                SetText(InputData);
            }
        }

        private void SetText(string text)
        {
            if (this.textBox1.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(SetText);
                this.Invoke(d, new object[] { text });
            }
            else this.textBox1.Text += text;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            serialPort1.Close();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            serialPort1.Open();
        }
 }


Pozdrawiam !

Re: Automatyczne przewijanie textBox-a

: wtorek 16 lut 2016, 14:38
autor: mokrowski
TextBox.AppendText(string text)

Re: Automatyczne przewijanie textBox-a

: wtorek 16 lut 2016, 15:15
autor: StaryAnoda
Cześć !

Bardzo dziękuję za pomoc.

Pozdrawiam !