//----------------
//Klasse MainForm
//----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Recoding_Calendar
{
public partial class MainForm : Form
{
//Konstruktor
public MainForm()
{
InitializeComponent();
}
//der MainForm den Kalender hinzufügen (Aggregation)
public void addKalender(CListView listview, CComboBox combobox)
{
this.Controls.Add(listview);
this.Controls.Add(combobox);
}
}
}
//---------------
//Klasse Kalender
//---------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Recoding_Calendar
{
public class CKalender
{
public CKalender()
{
}
//ListView erzeugen und der MainForm hinzufügen (Komposition)
public void addListview(MainForm form)
{
form.Controls.Add(new CListView());
}
//ComboBox erzeugen und der MainForm hinzufügen (Komposition)
public void addComboBox(MainForm form)
{
form.Controls.Add(new CComboBox());
}
}
}
//----------------
//Klasse CListView
//----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Globalization; //Using Direktive für Datumsformate
using System.Windows.Forms;
namespace Recoding_Calendar
{
public class CListView : ListView
{
private ListViewItem item;
//Konstruktor
public CListView()
{
this.Location = new Point(12, 71);
this.Size = new Size(756, 555);
this.View = View.Details;
this.GridLines = true;
this.Columns.Add("Tag", 52, HorizontalAlignment.Center);
//this.Items.Add("test");
}
public void addDaysInMonth(int selectedIndex)
{
int anzahlTageimMonat = DateTime.DaysInMonth(DateTime.Now.Year, selectedIndex + 1);
//Kalendertage einfügen
for (int x = 1; x <= (anzahlTageimMonat); x++)
{
DateTime dt = new DateTime(DateTime.Now.Year, selectedIndex + 1, x);
item = new ListViewItem(x.ToString() + " " + "(" + CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedDayName(dt.DayOfWeek) + ")");
this.Items.Add(item);
if (dt.DayOfWeek == DayOfWeek.Sunday)
{
item.UseItemStyleForSubItems = false;
item.BackColor = Color.DarkOrange;
}
}
}
}
}
//-------------------
//Klasse CComboBox
//-------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Globalization; //Using Direktive für Datumsformate
namespace Recoding_Calendar
{
public class CComboBox : ComboBox
{
private CListView listview;
//Konstruktor
public CComboBox()
{
this.FormattingEnabled = true;
this.Location = new Point(13, 28);
this.Size = new Size(121, 21);
this.TabIndex = 7;
this.SelectedIndexChanged += new EventHandler (this_SelectedIndexChanged);
listview = new CListView();
Init();
}
//ComboBox mit Einträgen/Monaten füllen
public void Init()
{
String str;
for (int x = 1; x < 13; x++)
{
//Monatsanzeige formatieren (Januar, Februar, März etc...)
str = CultureInfo.CurrentUICulture.DateTimeFormat.GetMonthName(x);
this.Items.Add(str);
}
//Einen Eintrag/Monat in der Combobox markieren
this.SelectedIndex = DateTime.Now.Month - 1;
}
public void this_SelectedIndexChanged(object sender, EventArgs e)
{
listview.addDaysInMonth(this.SelectedIndex);
}
}
}
//--------------
//Klasse Program
//--------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Recoding_Calendar
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MainForm form = new MainForm();
CKalender kalender = new CKalender();
kalender.addListview(form);
kalender.addComboBox(form);
Application.Run(form);
}
}
}