KONU : C Sharp Uygulamalar - C Sharp form da dinamik üçgen buton oluşturma, forma dinamik buton ekleme, çalışma anında forma dinamik buton ekleme.
UYGULAMAYI İNDİR
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;
using System.Drawing.Drawing2D;
namespace C_Sharp_Form_Ucgen_Buton_Olusturma
{
public partial class Ucgen_Buton_Olusturma : Form
{
public Ucgen_Buton_Olusturma()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// mavi renkli bir üçgen buton oluşturalım
ShapedButton ucgenbuton = new ShapedButton();
// Kare veya dikdörtgen butonun size özelliği değiştiği an
//şekli üçgen olacak
ucgenbuton.Size = new Size(200, 100);
// üçgen butona diğer özellikleri dinamik olarak verebiliriz
ucgenbuton.Location = new System.Drawing.Point(60, 60);
ucgenbuton.BackColor = Color.Blue;
ucgenbuton.FlatAppearance.BorderSize = 0;
ucgenbuton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
ucgenbuton.FlatAppearance.BorderColor = Color.Blue;
ucgenbuton.TabStop = false;
ucgenbuton.Click += new EventHandler(ucgenbuton_Click);
// oluşan üçgen butonu ana forma ekleme
this.Controls.Add(ucgenbuton);
// yeşil renkli bir üçgen buton oluşturalım
ucgenbuton = new ShapedButton();
// Kare veya dikdörtgen butonun size özelliği değiştiği an
//şekli üçgen olacak
ucgenbuton.Size = new Size(200, 100);
// üçgen butona diğer özellikleri dinamik olarak verebiliriz
ucgenbuton.Location = new System.Drawing.Point(150, 60);
ucgenbuton.BackColor = Color.Green;
ucgenbuton.FlatAppearance.BorderSize = 0;
ucgenbuton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
ucgenbuton.FlatAppearance.BorderColor = Color.Blue;
ucgenbuton.TabStop = false;
ucgenbuton.Click += new EventHandler(ucgenbuton_Click);
// oluşan üçgen butonu ana forma ekleme
this.Controls.Add(ucgenbuton);
// sarı renkli bir üçgen buton oluşturalım
ucgenbuton = new ShapedButton();
// Kare veya dikdörtgen butonun size özelliği değiştiği an
//şekli üçgen olacak
ucgenbuton.Size = new Size(200, 100);
// üçgen butona diğer özellikleri dinamik olarak verebiliriz
ucgenbuton.Location = new System.Drawing.Point(240, 60);
ucgenbuton.BackColor = Color.Yellow;
ucgenbuton.FlatAppearance.BorderSize = 0;
ucgenbuton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
ucgenbuton.FlatAppearance.BorderColor = Color.Blue;
ucgenbuton.TabStop = false;
ucgenbuton.Click += new EventHandler(ucgenbuton_Click);
// oluşan üçgen butonu ana forma ekleme
this.Controls.Add(ucgenbuton);
}
void ucgenbuton_Click(object sender, EventArgs e)
{
// üçgen buton un arka plan rengini değiştirme işlemi
if (((ShapedButton)sender).BackColor == Color.Blue)
((ShapedButton)sender).BackColor = Color.Red;
else
if (((ShapedButton)sender).BackColor == Color.Red)
((ShapedButton)sender).BackColor = Color.Blue;
}
}
// Üçgen butonu oluşturmak için kullanılacak olan Class
public class ShapedButton : Button
{
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
GraphicsPath gp = new GraphicsPath();
Point[] point = new Point[3];
point[0] = new Point(50, 0);
point[1] = new Point(100, 50);
point[2] = new Point(50, 100);
gp.AddPolygon(point);
// oluşan yeni üçgen şekli, oluşturulan butona atama
this.Region = new Region(gp);
// Butonun yeni şekli üçgen oldu
}
}
}

çok boyutlu butona tıklandığı zaman [x,y] değerlerini nasıl alabiliriz??
YanıtlaSilbutonun mouse_click olayını oluştur. bu metodun içinde
Sile.X ve e.Y ile x y koardinatlarına ulaşabilirsin