Form Üzerindeki Grafik Rengini Değiştirme (Graphics) VB.Net

Bu dersimizde form üzerine oluşturduğumuz karenin Radiobutton ile kendi istediğimiz renge çevirmeyi göreceğiz. Bunun için formumuzun ara yüzünü 1 button ve kaç tane renk seçmek istiyorsak renk sayısı kadarda Radiobutton koyarak programımıza başlıyoruz.
Daha sonra kod yazma işlemine başlıyoruz. İlk olarak “a” değişkenini tanımlıyoruz.

arayuz4

Public Class Form1
Dim a As Graphics

Kodlarımızı Button1 in click ine yazarak devam ediyoruz.

[code language=”vb”]  If RadioButton1.Checked = True Then ‘eğer radiobutton1 seçilirse
a = Me.CreateGraphics()
a.DrawRectangle(New Pen(Color.Yellow, 4), 130, 150, 100, 100) ‘forma kare çizdirmek ve çizilen karenin rengini ve boyutunu ayarlamak için
End If[/code]

Aynı işlemleri bütün radiobutonlar için aktif hale getiriyoruz ve rengini değiştiriyoruz.

[code language=”vb”] If RadioButton2.Checked = True Then
a = Me.CreateGraphics()
a.DrawRectangle(New Pen(Color.Red, 4), 130, 150, 100, 100)
End If
If RadioButton3.Checked = True Then
a = Me.CreateGraphics()
a.DrawRectangle(New Pen(Color.Blue, 4), 130, 150, 100, 100)
End If
If RadioButton4.Checked = True Then
a = Me.CreateGraphics()
a.DrawRectangle(New Pen(Color.White, 4), 130, 150, 100, 100)
End If
If RadioButton5.Checked = True Then
a = Me.CreateGraphics()
a.DrawRectangle(New Pen(Color.Pink, 4), 130, 150, 100, 100)
End If
If RadioButton6.Checked = True Then
a = Me.CreateGraphics()
a.DrawRectangle(New Pen(Color.Green, 4), 130, 150, 100, 100)
End If
If RadioButton7.Checked = True Then
a = Me.CreateGraphics()
a.DrawRectangle(New Pen(Color.Aqua, 4), 130, 150, 100, 100)
End If
If RadioButton8.Checked = True Then
a = Me.CreateGraphics()
a.DrawRectangle(New Pen(Color.Orange, 4), 130, 150, 100, 100)
End If
If RadioButton9.Checked = True Then
a = Me.CreateGraphics()
a.DrawRectangle(New Pen(Color.Black, 4), 130, 150, 100, 100)
End If[/code]

Kod yazma işlemimiz bittikten sonra programımızı çalıştırıyoruz. Resimde görüldüğü gibi seçeneklerden turkuaz ı seçtik ve kare oluştur butonuna tıkladığımızda turkuaz renginde kare oluştu.

program

Programı İndir:Grafik Rengi Değiştirme (Graphics)

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir