Hey Leute,
ich bin noch C# Neuling, also nicht allzu hart sein :P
Ein Teil meines Programms besteht aus einem Prozess selector.
Das ist quasi eine Listview wo alle Prozesse gelistet werden.
Jetzt wollte ich eine Methode "InitProcesslist" zur Form class hinzufügen.
Gesagt, getan.
Wenn ich jetzt den Designer aufrufe (Visual Studio), dann bekomme ich den Fehler, die Funktion würde nicht gefunden werden.
Mache ich das falsch?
Macht man sowas eigentlich anders?
(Ps: Ich habe auch schon probiert die Funktion weiter oben zu deklarieren.)
Hier der Kot:
PHP Code:
using System.Diagnostics;
using System.Windows.Forms;
namespace TestPE
{
partial class ProcessSelector
{
/// <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.ps_processlist = new System.Windows.Forms.ListView();
this.ps_pid_col = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ps_process_col = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ps_window_col = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.SuspendLayout();
//
// ps_processlist
//
this.ps_processlist.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.ps_pid_col,
this.ps_process_col,
this.ps_window_col});
this.ps_processlist.FullRowSelect = true;
this.ps_processlist.Location = new System.Drawing.Point(12, 12);
this.ps_processlist.MultiSelect = false;
this.ps_processlist.Name = "ps_processlist";
this.ps_processlist.Size = new System.Drawing.Size(435, 181);
this.ps_processlist.TabIndex = 0;
this.ps_processlist.UseCompatibleStateImageBehavior = false;
this.ps_processlist.View = System.Windows.Forms.View.Details;
this.ps_processlist.ColumnWidthChanging += new System.Windows.Forms.ColumnWidthChangingEventHandler(this.ps_processlist_ColumnWidthChanging);
//
// ps_pid_col
//
this.ps_pid_col.Text = "PID";
//
// ps_process_col
//
this.ps_process_col.Text = "Process";
this.ps_process_col.Width = 150;
//
// ps_window_col
//
this.ps_window_col.Text = "Window";
this.ps_window_col.Width = 221;
//
// ProcessSelector
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(459, 262);
this.Controls.Add(this.ps_processlist);
this.Name = "ProcessSelector";
this.Text = "Process select";
this.ResumeLayout(false);
// Call Initializators
this.InitProcesslist();
}
#endregion
#region OwnFunctions
public void InitProcesslist()
{
ps_processlist.Items.Clear(); //Remove all previous items
Process[] processes = Process.GetProcesses();
foreach (Process process in processes)
{
ListViewItem lvi = new ListViewItem(process.Id.ToString());
lvi.SubItems.Add(process.ProcessName);
lvi.SubItems.Add(process.MainWindowTitle);
ps_processlist.Items.Add(lvi);
}
}
#endregion OwnFunctions
private System.Windows.Forms.ListView ps_processlist;
private System.Windows.Forms.ColumnHeader ps_pid_col;
private System.Windows.Forms.ColumnHeader ps_process_col;
private System.Windows.Forms.ColumnHeader ps_window_col;
}
}
Edit:
Ok, ich glaube ich war einfach falsch in der Designer class.
Denke der Code gehört in die Klasse die von Form erbt.