Nazwa forum

Opis forum

  • Nie jesteś zalogowany.
  • Polecamy: Moda

#1 2009-08-13 21:47:56

kowal

Administrator

Zarejestrowany: 2009-08-13
Posty: 9
Punktów :   -1 

zaznaczalny obrazek

wydziedziczyć się z picturebox i napisać klaskę obrazka, której można ustawić ramkę o zadanym kolorze.

napisać demo ładujące obrazek + 3 przyciski ustawiające 2 kolory ramki + usuwające ramkę.

priorytet mały, żeby się czegoś nauczyć, ale przyda się na przysżłość.

jarmur?


edit:

Kod:

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 logotrial
{
    public partial class Form1 : Form
    {
        List<BorderedImage> m_imgList;

        public Form1()
        {
            InitializeComponent();

            m_imgList = new List<BorderedImage>();
            BorderedImage img;
            Bitmap b = new Bitmap(100, 100);
            Graphics g = Graphics.FromImage(b);
            g.Clear(Color.Yellow);

            img = new BorderedImage();
            img.Size = new System.Drawing.Size(100, 100);
            img.Location = new System.Drawing.Point(100, 100);
            img.Image = new Bitmap(b);
            m_imgList.Add(img);

            img = new BorderedImage();
            img.Size = new System.Drawing.Size(100, 100);
            img.Location = new System.Drawing.Point(300, 100);
            img.Image = new Bitmap(b);
            m_imgList.Add(img);

            img = new BorderedImage();
            img.Size = new System.Drawing.Size(100, 100);
            img.Location = new System.Drawing.Point(100, 300);
            img.Image = new Bitmap(b);
            m_imgList.Add(img);

            img = new BorderedImage();
            img.Size = new System.Drawing.Size(100, 100);
            img.Location = new System.Drawing.Point(300, 300);
            img.Image = new Bitmap(b);
            m_imgList.Add(img);

            for (int i = 0; i < m_imgList.Count; ++i) this.Controls.Add(m_imgList[i]);
        }
    }
}

Kod:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace logotrial
{
    public class BorderedImage : PictureBox
    {
        private bool m_border;
        private Color m_borderColor;

        public BorderedImage()
        {
            m_border = false;
            m_borderColor = Color.Red;

            this.Image = new Bitmap(Width, Height);

            //this.Click += new System.EventHandler(BorderedImageClick);
            //this.Paint += new System.Windows.Forms.PaintEventHandler(BorderedImagePaint);
        }

        private void BorderedImagePaint(object sender, PaintEventArgs e)
        {
            if (m_border)
            {
                Pen pen = new Pen(Color.Red, 3.0f);
                e.Graphics.DrawRectangle(pen, 10, 10, e.ClipRectangle.Width - 20, e.ClipRectangle.Height - 20);
            }
        }

        private void BorderedImageClick(object sender, EventArgs e)
        {
            Border = !Border;
        }

        public Color Color
        {
            get
            {
                return m_borderColor;
            }
            set
            {
                m_borderColor = value;
                this.Refresh();
            }
        }
        public bool Border
        {
            get
            {
                return m_border;
            }
            set
            {
                m_border = value;
                this.Refresh();
            }
        }
    }
}

Offline

 

Stopka forum

RSS
Powered by PunBB
© Copyright 2002–2008 PunBB
Polityka cookies - Wersja Lo-Fi


Darmowe Forum | Ciekawe Fora | Darmowe Fora
www.wkpf.pun.pl www.bleachheroes.pun.pl www.umpoznan.pun.pl www.harrypottersite.pun.pl www.valhalla-pwi.pun.pl