Live Chat Software
Emre CIRIK | C# ve VB.NET ile Runtime'da Buton Ekleme ve Buton'a event Bağlama

C# ve VB.NET ile Runtime'da Buton Ekleme ve Buton'a event Bağlama

by EMRCRK 14. May 2011 12:50

Arkadaşlar VB.NET ile C#Arasında  bir takım farklılıklar vardır. Bunlardan biriside Form kontrollerine bağlanan evetlerdir. Şimdi aşağıda 2 Örnek kod yazacağım ve ikisininde yaptığı iş aynıdır.

C# :

 

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 CSharpAddRuntimeObject
{
    public partial class FrmMain : Form
    {

        public FrmMain()
        {
            InitializeComponent();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            Button btn;
            int x = 10, y = 0;
            int sizeH=25, sizeW=25;
            for (int i = 0; i < 10; i++)
            {
                y = 0;
                for (int j = 0; j < 5; j++)
                {
                    btn = new Button();
                    btn.Location = new Point(x, y);
                    btn.Size = new Size(sizeW, sizeW);
                    btn.Name = "btn" + i.ToString()+j.ToString();
                    btn.Text = "Buton " + i.ToString() +"-"+ j.ToString();
                    btn.Click += new EventHandler(btn_Click);
                    this.Controls.Add(btn);
                    y += 30;
                }
               
                x += 30;
            }
        }

        void btn_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            MessageBox.Show(btn.Text);
        }
    }
}

 

 

VB.NET : 

 

 

Public Class FrmMain

    Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim btn As Button
        Dim x, y As Integer : Dim sizeW, sizeH As Integer
        x = 10 : y = 0 : sizeW = 25 : sizeH = 25

        For i = 1 To 10
            y = 0

            For j = 1 To 5
                btn = New Button()
                btn.Location = New Point(x, y)
                btn.Size = New Size(sizeW, sizeH)
                btn.Name = "btn" + i.ToString() + j.ToString()
                btn.Text = "Buton " + i.ToString() + "-" + j.ToString()
                AddHandler btn.Click, AddressOf Me.btn_Click
                Me.Controls.Add(btn)
                y = y + 30
            Next

            x = x + 30
        Next

    End Sub



    Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim btn As Button = sender
        MsgBox(btn.Text)
    End Sub

End Class

 

AddRuntimeObject.rar (96,76 kb)

Tags: , , , ,

CSharp | VB.NET

Comments (1) -

sevda
sevda Turkey
7/1/2013 12:04:45 PM #

bana windows ce programlamada personel ekleme,çıkarma güncelleme nasıl yaparm atar mısınız??????

Reply

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading






Month List

Calendar

<<  December 2016  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar