| C# Açılır Menülere Nasıl Koşul Eklerim | 16 Mesajlar | 3.710 Okunma | ||
PorFavorDama adlı üyeden alıntı
http://prntscr.com/35ey47using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace String_İslemleri
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }
       
        private void tekStrinÜzerindeİşlemlerToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
        }
        private void çıkışToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void ikiYazıAynıMıToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string b = textBoxikinciString.Text;
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b))
            {
                MessageBox.Show("Lütfen önce ilk string ve ikinci string kısımlarının ikisini de doldurunuz");
            }
            else
            {
                int c = string.Compare(textBoxilkString.Text, textBoxikinciString.Text);
                if (c == 0)
                {
                    MessageBox.Show("1. kutu ve 2. kutuya yazılanlar aynıdır.");
                }
                else
                {
                    MessageBox.Show("Yazılanlar tam olarak aynı değildir.");
                }
            }
            
        }
        private void uuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                MessageBox.Show(textBoxilkString.Text.Length.ToString());
            }
            
        }
        private void herHarfiTekTekGösterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                
                char[] b = a.ToCharArray();
                for (int i = 0; i < a.Length; i++)
                {
                    MessageBox.Show((i + 1).ToString() + " . karakter : " + b[i].ToString());
                }
            }
           
        }
        private void herKelimeyiTekTekGösterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                string[] b = textBoxilkString.Text.Split(' ');
                for (int i = 0; i < b.Length; i++)
                {
                    MessageBox.Show((i + 1).ToString() + " . kelime : " + b[i].ToString());
                }
            }
        }
        private void büyükHarfeÇevirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                textBoxilkString.Text = textBoxilkString.Text.ToUpper();
            }
        }
        private void küçükHarfeÇevirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                textBoxilkString.Text = textBoxilkString.Text.ToLower();
            }
        }
        private void boşluklarıSilToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                string ca = textBoxilkString.Text.Trim();
                textBoxilkString.Text = ca;
            }
        }
        private void yazınınİlk3KarakteriniSilToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                // başlayacagımız index sayısı ve silinecek karakter sayısı.
                textBoxilkString.Text = textBoxilkString.Text.Remove(0, 3);
            }
        }
        private void sayıMıYazıMıToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /* --- ACIKLAMA ----
             * 1. YOL
             *
            string str = textBoxilkString.Text;
int val; 
if (int.TryParse(str, out val)) 
{
    MessageBox.Show("Girilen veri tipi sayıdır."); 
}else
{ 
   MessageBox.Show("Girilen veri tipi yazıdır");
}  
            */
            /* ----- ACIKLAMA ---------
             * 2. YOL
            string str = textBoxilkString.Text;
            bool isNumber = Regex.IsMatch(str, @"^\d+$");
            if (isNumber)
            {
                MessageBox.Show("Sayısal değer");
            }
            else if (isNumber==false)
            {
                MessageBox.Show("Yazısal değer");
            }
            else
            {
                MessageBox.Show("Girdiğiniz veride hem sayı hem yazı vardır.");
            }
            */
            /* ----- ACIKLAMA ----
             * 3.YOL
            try
            {
                Convert.ToInt32(textBoxilkString.Text);
                MessageBox.Show("Girilen veri sayıdır.","Bilgi",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
            }
            catch
            {
                MessageBox.Show("Girilen veri yazıdır.","Bilgi",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
            }
             */
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                int sayac = 0;
                for (int j = 0; j < textBoxilkString.Text.Length; j++)
                {
                    //true ise textboxilkstring.text[j] değeri 0 dan 9 a kadar bir değerdir.
                    //rakam olup olmadıgını kontrol eder.
                    if (char.IsDigit(textBoxilkString.Text[j]))
                        sayac++;
                }
                if (sayac == 0)
                    MessageBox.Show("Girilen ifade yazıdır.");
                else if (sayac == textBoxilkString.Text.Length)
                    MessageBox.Show("Girilen ifade sayıdır.");
                else if (sayac > 0 || sayac < textBoxilkString.Text.Length)
                    MessageBox.Show("Girilen ifadede hem yazı hem sayı karakterleri vardır.");
            }
        }
        private void yerDeğiştirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string b = textBoxikinciString.Text;
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b))
            {
                MessageBox.Show("Lütfen önce ilk string ve ikinci string kısımlarının ikisini de doldurunuz");
            }
            else
            {
                textBoxilkString.Text = textBoxikinciString.Text;
                textBoxikinciString.Text = a;
            }
        }
        private void aKarakterininYeriniBulToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }
        private void button1_Click(object sender, EventArgs e)
        {
            /*İf döngüsü ile arama kutucuguna girilen kelimenın
             * ilk string textbox ında bulunup bulunmadıgı kontrol edilmiştir.
             * Eğer var ise kullanıcıya kaçıncı harften ıtıbaren basladıgı gosterılmıs.
             * Eğer yok ise girdiğiniz harf ya da kelime bulunamadı yanıtı verilmiştir.
             */
            if (textBoxilkString.Text.Contains(textBox1.Text))
            {
                MessageBox.Show(textBox1.Text.ToString()+" " + (textBoxilkString.Text.IndexOf(textBox1.Text) + 1) + " . harften itibaren başlamaktadır.");
            }
            else
            {
                MessageBox.Show("Girdiğiniz harf ya da kelime bulunamadı.");
            }
        }
        private void birleştirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string b = textBoxikinciString.Text;
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b))
            {
                MessageBox.Show("Lütfen önce ilk string ve ikinci string kısımlarının ikisini de doldurunuz");
            }
            else
            {
                MessageBox.Show(textBoxilkString.Text + " " + textBoxikinciString.Text, "Birleştirilmiş Text");
            }
        }
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            
        }
        private void tekStrinÜzerindeİşlemlerToolStripMenuItem_DropDownClosed(object sender, EventArgs e)
        {
        
        }
        private void tekStrinÜzerindeİşlemlerToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
        {
         
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void hakkındaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form abc = new Form2();
            abc.Show();
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }
        private void textBoxilkString_TextChanged(object sender, EventArgs e)
        {
            button1.Enabled = true;
        }
    }
}
PorFavorDama adlı üyeden alıntı
Kod ile ne alakası var anlamadım hocam ama buyrun :) Yeniyim onu söyleyeyim. Birde ben orada koşul koyamadıgım ıcın sonra acılan menude her butona aynı kosulu ekleyerek yaptım yanı sımdılık tek care buydu :)using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace String_İslemleri
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }
       
        private void tekStrinÜzerindeİşlemlerToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
        }
        private void çıkışToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void ikiYazıAynıMıToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string b = textBoxikinciString.Text;
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b))
            {
                MessageBox.Show("Lütfen önce ilk string ve ikinci string kısımlarının ikisini de doldurunuz");
            }
            else
            {
                int c = string.Compare(textBoxilkString.Text, textBoxikinciString.Text);
                if (c == 0)
                {
                    MessageBox.Show("1. kutu ve 2. kutuya yazılanlar aynıdır.");
                }
                else
                {
                    MessageBox.Show("Yazılanlar tam olarak aynı değildir.");
                }
            }
            
        }
        private void uuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                MessageBox.Show(textBoxilkString.Text.Length.ToString());
            }
            
        }
        private void herHarfiTekTekGösterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                
                char[] b = a.ToCharArray();
                for (int i = 0; i < a.Length; i++)
                {
                    MessageBox.Show((i + 1).ToString() + " . karakter : " + b[i].ToString());
                }
            }
           
        }
        private void herKelimeyiTekTekGösterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                string[] b = textBoxilkString.Text.Split(' ');
                for (int i = 0; i < b.Length; i++)
                {
                    MessageBox.Show((i + 1).ToString() + " . kelime : " + b[i].ToString());
                }
            }
        }
        private void büyükHarfeÇevirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                textBoxilkString.Text = textBoxilkString.Text.ToUpper();
            }
        }
        private void küçükHarfeÇevirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                textBoxilkString.Text = textBoxilkString.Text.ToLower();
            }
        }
        private void boşluklarıSilToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                string ca = textBoxilkString.Text.Trim();
                textBoxilkString.Text = ca;
            }
        }
        private void yazınınİlk3KarakteriniSilToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                // başlayacagımız index sayısı ve silinecek karakter sayısı.
                textBoxilkString.Text = textBoxilkString.Text.Remove(0, 3);
            }
        }
        private void sayıMıYazıMıToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /* --- ACIKLAMA ----
             * 1. YOL
             *
            string str = textBoxilkString.Text;
int val; 
if (int.TryParse(str, out val)) 
{
    MessageBox.Show("Girilen veri tipi sayıdır."); 
}else
{ 
   MessageBox.Show("Girilen veri tipi yazıdır");
}  
            */
            /* ----- ACIKLAMA ---------
             * 2. YOL
            string str = textBoxilkString.Text;
            bool isNumber = Regex.IsMatch(str, @"^\d+$");
            if (isNumber)
            {
                MessageBox.Show("Sayısal değer");
            }
            else if (isNumber==false)
            {
                MessageBox.Show("Yazısal değer");
            }
            else
            {
                MessageBox.Show("Girdiğiniz veride hem sayı hem yazı vardır.");
            }
            */
            /* ----- ACIKLAMA ----
             * 3.YOL
            try
            {
                Convert.ToInt32(textBoxilkString.Text);
                MessageBox.Show("Girilen veri sayıdır.","Bilgi",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
            }
            catch
            {
                MessageBox.Show("Girilen veri yazıdır.","Bilgi",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
            }
             */
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a))
            {
                MessageBox.Show("Lütfen önce ilk string kısmını doldurunuz");
            }
            else
            {
                int sayac = 0;
                for (int j = 0; j < textBoxilkString.Text.Length; j++)
                {
                    //true ise textboxilkstring.text[j] değeri 0 dan 9 a kadar bir değerdir.
                    //rakam olup olmadıgını kontrol eder.
                    if (char.IsDigit(textBoxilkString.Text[j]))
                        sayac++;
                }
                if (sayac == 0)
                    MessageBox.Show("Girilen ifade yazıdır.");
                else if (sayac == textBoxilkString.Text.Length)
                    MessageBox.Show("Girilen ifade sayıdır.");
                else if (sayac > 0 || sayac < textBoxilkString.Text.Length)
                    MessageBox.Show("Girilen ifadede hem yazı hem sayı karakterleri vardır.");
            }
        }
        private void yerDeğiştirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string b = textBoxikinciString.Text;
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b))
            {
                MessageBox.Show("Lütfen önce ilk string ve ikinci string kısımlarının ikisini de doldurunuz");
            }
            else
            {
                textBoxilkString.Text = textBoxikinciString.Text;
                textBoxikinciString.Text = a;
            }
        }
        private void aKarakterininYeriniBulToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }
        private void button1_Click(object sender, EventArgs e)
        {
            /*İf döngüsü ile arama kutucuguna girilen kelimenın
             * ilk string textbox ında bulunup bulunmadıgı kontrol edilmiştir.
             * Eğer var ise kullanıcıya kaçıncı harften ıtıbaren basladıgı gosterılmıs.
             * Eğer yok ise girdiğiniz harf ya da kelime bulunamadı yanıtı verilmiştir.
             */
            if (textBoxilkString.Text.Contains(textBox1.Text))
            {
                MessageBox.Show(textBox1.Text.ToString()+" " + (textBoxilkString.Text.IndexOf(textBox1.Text) + 1) + " . harften itibaren başlamaktadır.");
            }
            else
            {
                MessageBox.Show("Girdiğiniz harf ya da kelime bulunamadı.");
            }
        }
        private void birleştirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string b = textBoxikinciString.Text;
            string a = textBoxilkString.Text;
            if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b))
            {
                MessageBox.Show("Lütfen önce ilk string ve ikinci string kısımlarının ikisini de doldurunuz");
            }
            else
            {
                MessageBox.Show(textBoxilkString.Text + " " + textBoxikinciString.Text, "Birleştirilmiş Text");
            }
        }
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            
        }
        private void tekStrinÜzerindeİşlemlerToolStripMenuItem_DropDownClosed(object sender, EventArgs e)
        {
        
        }
        private void tekStrinÜzerindeİşlemlerToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
        {
         
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void hakkındaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form abc = new Form2();
            abc.Show();
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }
        private void textBoxilkString_TextChanged(object sender, EventArgs e)
        {
            button1.Enabled = true;
        }
    }
}
 if (textBox1.Text == "2")
            {
                ContextMenuStrip = contextMenuStrip1;
            }