Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Collections; using System.IO; using System.Windows.Forms; namespace Hexconverter { class Program { static void Main(string[] args) { //int i = 1; { string path = Console.ReadLine(); if (File.Exists(path)==true) { // Open the file to read from. string readText = File.ReadAllText(path); char[] values = readText.ToCharArray(); foreach (char letter in values) { // Get the integral value of the character. int value = Convert.ToInt32(letter); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:X}", value); //Console.WriteLine(i++); MyForm form = new MyForm(); form.lblText1.Text = path; form.Show(); Console.Write("{1} ", letter, hexOutput, readText); } } else { Environment.Exit(0); } Console.WriteLine(""); string path1 = Console.ReadLine(); if (File.Exists(path1) == true) { { // Open the file to read from. string readText1 = File.ReadAllText(path1); char[] values1 = readText1.ToCharArray(); foreach (char letter1 in values1) { // Get the integral value of the character. int value1 = Convert.ToInt32(letter1); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:X}", value1); //Console.WriteLine(i++); { MyForm form = new MyForm(); form.lblText2.Text = path1; form.Show(); Console.Write("{1} ", letter1, hexOutput, readText1); } } } } else { Environment.Exit(0); } string MyString = path; Console.WriteLine(String.Compare(MyString, path1)); if (MyString == path1) { Console.WriteLine("Gleich!"); } else { { Console.WriteLine("Nicht Gleich!"); } } Console.ReadKey(); } } } } |
naja, schau dir doch mal genau an, wann dein Fenster geöffnet wird. Oder noch besser: Schau mit dem Debugger, wie oft er in Zeile 33 landet .
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Collections; using System.IO; using System.Windows.Forms; namespace Hexconverter { class Program { static void Main(string[] args) { //int i = 1; { string path = Console.ReadLine(); if (File.Exists(path) == true) { // Open the file to read from. string readText = File.ReadAllText(path); char[] values = readText.ToCharArray(); foreach (char letter in values) { // Get the integral value of the character. int value = Convert.ToInt32(letter); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:X}", value); //Console.WriteLine(i++); Console.Write("{1} ", letter, hexOutput, readText); } } else { Environment.Exit(0); } Console.WriteLine(""); string path1 = Console.ReadLine(); if (File.Exists(path1) == true) { { // Open the file to read from. string readText1 = File.ReadAllText(path1); char[] values1 = readText1.ToCharArray(); foreach (char letter1 in values1) { // Get the integral value of the character. int value1 = Convert.ToInt32(letter1); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:X}", value1); //Console.WriteLine(i++); { Console.Write("{1} ", letter1, hexOutput, readText1); } } } } else { Environment.Exit(0); } { MyForm form = new MyForm(); form.lblText1.Text = path; form.lblText2.Text = path1; form.Show(); } string MyString = path; Console.WriteLine(String.Compare(MyString, path1)); if (MyString == path1) { Console.WriteLine("Gleich!"); } else { { Console.WriteLine("Nicht Gleich!"); } } Console.ReadKey(); } } } } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »layle« (03.05.2014, 10:07)
C#-Quelltext |
|
1 2 3 4 5 6 7 |
string values = "This is a long text" foreach (char letter in values) { MyForm form = new MyForm(); form.Show(); } |
Ich glaube du verstehst deinen Programmcode nicht. Was würdest du denn von folgendem Code erwarten, was er tut?
C#-Quelltext
1 2 3 4 5 6 7 string values = "This is a long text" foreach (char letter in values) { MyForm form = new MyForm(); form.Show(); }
Jetzt ist der Aufruf weg, der vorhin noch stand
Naja, was ist denn die Ausnahme? Visual Studio sagt dir genau, was nicht stimmt!
C#-Quelltext |
|
1 2 3 4 5 6 7 8 |
while (true) { if (Console.KeyAvailable) { break; } Application.DoEvents(); } |
Ich habe deinen Programmcode kurz mal angeschaut. Bei mir hängt bei der Anzeige des Fensters, was nicht verwunderlich ist:
Du öffnest ein Fenster mit Show(), blockierst aber den aufrufenden Thread mit einem Console.ReadKey(). Dadurch kann das Fenster gar nicht reagieren. Entweder, du erstellst und zeigst das Fenster aus einem anderem Thread heraus, oder gibst dem Hauptthread Zeit. Ich würde dir ja zu letzterem raten. Einfach an Stelle von Console.ReadKey() folgendes machen:
C#-Quelltext
1 2 3 4 5 6 7 8 while (true) { if (Console.KeyAvailable) { break; } Application.DoEvents(); }
Da man merkt, dass du quasi keine Erfahrung mit Windows-Programmierung hast, solltest du dir dringend Literatur zulegen! Schlage alle hier aufgeführten Befehle nach und verstehe, was sie tun.
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Collections; using System.IO; using System.Windows.Forms; namespace Hexconverter { class Program { static void Main(string[] args) { //int i = 1; { string path = Console.ReadLine(); if (File.Exists(path) == true) { // Open the file to read from. string readText = File.ReadAllText(path); char[] values = readText.ToCharArray(); foreach (char letter in values) { // Get the integral value of the character. int value = Convert.ToInt32(letter); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:X}", value); //Console.WriteLine(i++); Console.Write("{1} ", letter, hexOutput, readText); } } else { Environment.Exit(0); } Console.WriteLine(""); string path1 = Console.ReadLine(); if (File.Exists(path1) == true) { { // Open the file to read from. string readText1 = File.ReadAllText(path1); char[] values1 = readText1.ToCharArray(); foreach (char letter1 in values1) { // Get the integral value of the character. int value1 = Convert.ToInt32(letter1); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:X}", value1); //Console.WriteLine(i++); { Console.Write("{1} ", letter1, hexOutput, readText1); } } } } else { Environment.Exit(0); } { MyForm form = new MyForm(); form.lblText1.Text = path; //Hier müsste glaub ich readText form.lblText2.Text = path1; //und hier readText1 stehen? Leider kommt hier die Meldung:Fehler 1 Der Name "readText(1)" ist im aktuellen Kontext nicht vorhanden. form.Show(); } string MyString = path; Console.WriteLine(String.Compare(MyString, path1)); if (MyString == path1) { Console.WriteLine("Gleich!"); } else { { Console.WriteLine("Nicht Gleich!"); } } while (true) { if (Console.KeyAvailable) { break; } Application.DoEvents(); } } } } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 |
{ string readText1 = path1; string readText = path; MyForm form = new MyForm(); form.lblText1.Text = path; form.lblText2.Text = path1; form.Show(); } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; namespace HexConverter { class Program { static void Main(string[] args) { var path = Console.ReadLine(); if (!ReadFileAndPrintHexaDecimalContent(path)) return; Console.WriteLine(); var path1 = Console.ReadLine(); if (!ReadFileAndPrintHexaDecimalContent(path1)) return; ShowWindowWithFileNames(path, path1); CompareFiles(path, path1); WaitForQuit(); } private static bool ReadFileAndPrintHexaDecimalContent(string path) { if (!File.Exists(path)) return false; var readText = File.ReadAllText(path); var values = readText.ToCharArray(); foreach (var letter in values) { var value = Convert.ToInt32(letter); var hexOutput = String.Format("{0:X}", value); Console.Write("{1} ", letter, hexOutput, readText); } return true; } private static void ShowWindowWithFileNames(string path1, string path2) { MyForm form = new MyForm(); form.lblText1.Text = path; form.lblText2.Text = path1; form.Show(); } private static void CompareFiles(string filePath1, string filePath2) { Console.WriteLine(String.Compare(filePath1, filePath2)); if (filePath1 == filePath2) { Console.WriteLine("Gleich!"); } else { Console.WriteLine("Nicht Gleich!"); } } private static void WaitForQuit() { while (true) { if (Console.KeyAvailable) break; Application.DoEvents(); } } } } |
Naja du gibst nur die Pfade rein, wie soll er denn den Inhalt darstellen? Dann musst du dir die Inhalte von File.ReadAllText() + dessen Konvertierung merken und dem Formular übergeben. Ich war mal so frei und hab deinen Code aufgeräumt, der ist ziemlich schlampig:
C#-Quelltext
1 2 3 4 5 6 7 private static void ShowWindowWithFileNames(string path1, string path2) { MyForm form = new MyForm(); form.lblText1.Text = path; form.lblText2.Text = path1; form.Show(); }
private static void ShowWindowWithFileNames(string path1, string path2) { MyForm form = new MyForm(); form.lblText1.Text = path; form.lblText2.Text = path1; form.Show(); }
C#-Quelltext |
|
1 2 3 4 5 6 7 |
private static void ShowWindowWithFileNames(string path, string path1) { MyForm form = new MyForm(); form.lblText1.Text = path; // oder hier eifach path1 form.lblText2.Text = path1; //und hier path2 form.Show(); } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
private static void CompareFiles(string filePath1, string filePath2) //Muss ich hier filePath1 und filePath2 durch den Befehl für den Pfad eingeben? Oder vielleich nur den Pfad? { Console.WriteLine(String.Compare(filePath1, filePath2)); //Hier dassselbe if (filePath1 == filePath2) //Hier dasselbe { Console.WriteLine("Gleich!"); } else { Console.WriteLine("Nicht Gleich!"); } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
private static void ShowWindowWithFileNames(string path, string path1) { MyForm form = new MyForm(); var hex1 = File.ReadAllText(path); var values = hex1.ToCharArray(); foreach (var letter in values) { var value = Convert.ToInt32(letter); var hexOutput = String.Format("{0:X}", value); //Console.Write("{1} ", letter, hexOutput, hex1); Der benötigte Teil ist ja: ("{1} ", letter, hexOutput, readText). //form.lblText.Text("{1} ", letter, hexOutput, hex1); verursacht Fehlermeldung form.lblText1.Text = hex1; } var hex2 = File.ReadAllText(path1); values = hex2.ToCharArray(); foreach (var letter in values) { var value = Convert.ToInt32(letter); var hexOutput = String.Format("{0:X}", value); form.lblText2.Text = hex2; //form.lblText.Text("{1} ", letter, hexOutput, hex2); verursacht Fehlermeldung form.Show(); } } |
Werbeanzeige