Moduler>GUI-komponenter>Farger
Farger
Vi lager det nytt "project" av typen "Windows Application". Så bruker vi GUI-editoren til å lage en enkel form. Vi får igjen tre kildefiler:
- Program.cs
- Form1.cs
- Form1.Designer.cs
Vi konsentrerer oss om den ene fila som inneholder vår handskrevne kode
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace control6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if(colorDialog1.ShowDialog()==DialogResult.OK)
panel1.BackColor=colorDialog1.Color;
}
private void button2_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
label1.ForeColor = colorDialog1.Color;
}
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
if (fontDialog1.ShowDialog() == DialogResult.OK)
label1.Font = fontDialog1.Font;
}
}
}












