Felhasználói eszközök

Eszközök a webhelyen


oktatas:programozas:csharp:gui_kepek

< CSharp

CSharp GUI képek

Háttérkép beillesztése

kep.cs
using System;
using System.Drawing;
using System.Windows.Forms;
 
public class Form1 : Form
{
        public Form1()
        {
                Image kep = Image.FromFile("kep.jpg");
                this.BackgroundImage = kep;
        }
 
        static public void Main()
        {
                Application.Run(new Form1());
        }
}

Egy kép beillesztése

Kép adott helyre

Program.cs
using System;
using System.Drawing;
using System.Windows.Forms;
 
public class Form1 : Form
{
 
        public Form1()
        {
                this.Paint += new PaintEventHandler(Form1_Paint);
        }
 
        static public void Main()
        {
                Application.Run(new Form1());
        }
 
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
 
                Graphics g = this.CreateGraphics();
 
		Image image = Image.FromFile("kep.jpg");
 
		g.DrawImage(image, 0, 0);
 
        }
}

A DrawImage metódus bemenő paraméterei:

g.DrawImage(kep, x, y, szélesség, magasság);

Kép másként

Program.cs
using System.Windows.Forms;
using System.Drawing;
 
class Program : Form
{
    Image kep;
    Program()
    {
        Width = 800;
        Height = 600;
        Show();
 
        kep = Image.FromFile("kep.png");
    }
 
    protected override void OnPaint(PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        if (kep != null)
            g.DrawImage(kep, 400, 200, 100, 100);
        base.OnPaint(e);
    }
 
    static void Main()
    {
        Application.Run(new Program());
    }
}

Képdoboz

Program.cs
using System.Windows.Forms;
using System.Drawing;
 
class Program : Form
{
    PictureBox kep;
    Program()
    {
        kep = new PictureBox();
 
        kep.Image = Image.FromFile("kep.png");
        kep.Location = new Point(100, 100);
        kep.Size = new Size(100, 100);
 
        Controls.Add(kep);
 
        Width = 800;
        Height = 600;
    }
 
    static void Main()
    {
        Application.Run(new Program());
    }
}
oktatas/programozas/csharp/gui_kepek.txt · Utolsó módosítás: 2019/08/21 22:26 szerkesztette: admin