Huhu
Ich hab ein Problem und kann es nicht lösen weil ich noch nicht all zu viel von C# verstehe.
Mein bisheriger Code sieht so aus:
Code
namespace WindowsFormsApplication1
{
partial class Form1
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.BackColor = System.Drawing.Color.Transparent;
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.ForeColor = System.Drawing.SystemColors.MenuHighlight;
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(298, 152);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Shutdown System";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.ForeColor = System.Drawing.Color.Orange;
this.label3.Location = new System.Drawing.Point(11, 123);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(143, 12);
this.label3.TabIndex = 6;
this.label3.Text = "Shutdown System - Reza © 2008 ";
//
// button3
//
this.button3.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button3.Location = new System.Drawing.Point(201, 113);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 5;
this.button3.Text = "OK";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(176, 69);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(100, 23);
this.button2.TabIndex = 4;
this.button2.Text = "Process Beenden";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(31, 69);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(106, 23);
this.button1.TabIndex = 3;
this.button1.Text = "Process Ausführen";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(217, 36);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(59, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Sekunden.";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(143, 29);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(68, 20);
this.textBox1.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(11, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(126, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Computer ausschalten in ";
//
// Form1
//
this.AcceptButton = this.button3;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.CancelButton = this.button3;
this.ClientSize = new System.Drawing.Size(325, 177);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "Form1";
this.Text = "Shutdown System - Reza";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label3;
}
}
Alles anzeigen
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.button2.Enabled = false;
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Bevor Sie diesen Process ausführen können, müssen Sie vorerst die entsprechende Zeit in dem Textfeld eingeben.", "Info:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
System.Diagnostics.Process.Start("shutdown.exe ", "-f -s -t " + textBox1.Text);
this.button2.Enabled = true;
this.button1.Enabled = false;
}
}
private void button2_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("shutdown.exe ", "-a");
this.button2.Enabled = false;
this.button1.Enabled = true;
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Alles anzeigen
Ich möchte dass das nur Zahlen akzeptiert werden wenn ich auf "Process Ausführen" klicke.
In manch anderen Sprachen gibt es die bezeichnung "isnum". In C# scheint das aber viel komplizierter zu sein. Ich hab bereits nen Code dazu bekommen aber um ganz ehrlich zu sein, hab ich nicht all zu viel davon verstanden. Es geht mir auch nicht um das Programm, sondern viel mehr um's Lernen.
Kennt jemand von euch villeicht eine einfache Methode sowas zu machen oder könnte mir erklären wie so was funktioniert?
Ich beschäftige mich erst seit einer Woche mit C#. Wäre also für jede Hilfe dankbar.