PIC_Simulator_Simon/PIC_Simulator/Form1.cs

174 lines
5.3 KiB
C#
Raw Normal View History

2017-05-08 18:33:16 +02:00
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;
using System.IO;
using PIC_Simulator;
namespace PIC_Simulator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Globale Variablen
public int ArrayLaenge =0;
public int PCounter = -1;
public int time;
public int timeIntervall;
Einlesen instEinlesen = new Einlesen();
private void label1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
box_CodeView.Font = new Font("Consolas", 8);
timeIntervall = 1000;
}
private void cmd_Start_Click(object sender, EventArgs e)
{
timer1.Interval = timeIntervall; // 1 Sekunde
timer1.Enabled = true;
}
private void cmd_next_Click(object sender, EventArgs e)
{
// MessageBox.Show("Array laenge übergeben:" + ArrayLaenge);
if (PCounter == ArrayLaenge) { MessageBox.Show("Programm ist komplett durchlaufen!"); }
else {
PCounter = PCounter + 1;
try
{
//Zeilenmarkierung aufheben
highLightALine(box_CodeView, PCounter - 1, Color.White);
}
catch { }
//Counter im Label inkrementieren
int shownCounter = PCounter;
shownCounter++;
label3.Text = shownCounter.ToString();
}
//Aktuelle Zeile markieren
highLightALine(box_CodeView, PCounter, Color.Green);
instEinlesen.readExecCode(PCounter);
}
private int getPCounter() {
return PCounter;
}
private void programmÖffnenToolStripMenuItem_Click(object sender, EventArgs e)
{
// Datei über openFileDialog1 Auswählen und in Anzeige öffnen
FileStream fs;
StreamReader sr;
string zeile;
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
sr = new
StreamReader(openFileDialog1.FileName);
DialogResult = MessageBox.Show(sr.ReadToEnd(), "Programm Vorschau", MessageBoxButtons.OKCancel);
sr.Close();
// Abfrage von Ergebnis des Dialogs, wenn ja Datei laden
if (DialogResult == DialogResult.OK)
{
fs = new FileStream(openFileDialog1.FileName, FileMode.Open);
sr = new StreamReader(fs);
while (sr.Peek() != -1)
{
zeile = sr.ReadLine();
box_CodeView.Text += zeile + "\n";
}
sr.Close();
lbl_path.Text = openFileDialog1.FileName;
// StreamReader jede Zeile in Listenelement schreiben über Funktionsaufruf in der Klasse Einlesen
ArrayLaenge = instEinlesen.writeToArray(sr = new StreamReader(openFileDialog1.FileName));
}
}
}
private void cmdOpenDoc_Click(object sender, EventArgs e)
{
string path = Application.StartupPath;
MessageBox.Show( path);
System.Diagnostics.Process.Start(@"C:\Users\nicol\Desktop\Projekte\PIC_Simulator\Projektinformationen\DataSheet.pdf");
}
//Funktion um Zeile aktuell ausgeführte Zeile zu markieren
void highLightALine(RichTextBox rtb, int line, Color hiLight)
{
int i1 = rtb.GetFirstCharIndexFromLine(line);
int i2 = rtb.GetFirstCharIndexFromLine(line + 1);
if (i2 < 0) i2 = rtb.Text.Length;
rtb.SelectionStart = i1;
rtb.SelectionLength = i2 - i1;
rtb.SelectionBackColor = hiLight;
}
private void cmdSetClock_Click(object sender, EventArgs e)
{
timeIntervall = Convert.ToInt32(insertTime.Text);
}
private void cmd_reset_Click(object sender, EventArgs e)
{ //######################### Muss ergänzt und getestet werden !!!
// Hier müssen alle Werte wieder auf den Standard gesetzt werden!
highLightALine(box_CodeView, PCounter, Color.White);
PCounter = -1;
label3.Text = PCounter.ToString();
//######################### Muss ergänzt und getestet werden !!!
}
private void buildtbl_Register() {
}
private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void timer1_Tick(object sender, EventArgs e)
{
Einlesen QuarzExec = new Einlesen();
PCounter = PCounter + 1;
label3.Text = PCounter.ToString();
}
private void cmd_Stop_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
}
}