Jump to content

Cut/copy/Paste in forms

- - - - -

  • Please log in to reply
19 replies to this topic

#1
kemnet

kemnet

    Newbie

  • Members
  • PipPip
  • 13 posts
Hello. All
I have this menu on my form that has the normal edit functions.

so i can cut from my text box using the code

  private void mnuCut_Click(object sender, EventArgs e)

        {

                 textBox1.Cut();

}

in the "Cut" of my menu.
but if I have more than one textbox how do I go about this, do i have to put all their names in the click event of the cut menu?




Thank You

Edited by kemnet, 10 August 2011 - 07:41 AM.


#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Easiest way is to just use the code over again
textBox1.Cut();
textBox2.Cut();
textBox3.Cut();


Ect, which really wouldn't be that bad if you only have a few textBox's. What you should do though is create a control array.
Something like this.
public Control[] txtBoxArray = new Control[3]{textBox1, textBox2, textBox3};
Then in your menu button, loop though the array cutting, copying, or pasting for each textBox in the array.

Hope that helps, good luck ~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
kemnet

kemnet

    Newbie

  • Members
  • PipPip
  • 13 posts
Kinda having a little trouble adding the name of objects to arrays

#4
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Post what you got so far and I'll try and help. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#5
kemnet

kemnet

    Newbie

  • Members
  • PipPip
  • 13 posts


namespace menuapp

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

public Control[] txtBoxArray = new Control[3] { Form1.fir_name, Form1.mid_nameTextBox, las_nameTextBox };

   




its not letting me say the textbox names it says
a field initializer cannot reference the non-static Field,Method or property 'menuapp.form1.fir_name'

#6
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Sorry, my bad. Try this.

 public Form1()
        {
            InitializeComponent();
txtBoxArray = new Control[3] { fir_name, mid_nameTextBox, las_nameTextBox };
        }
public Control[] txtBoxArray;

A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#7
kemnet

kemnet

    Newbie

  • Members
  • PipPip
  • 13 posts
Thanks for that it worked:But i was still wondering how you go about looping thru each one in the array


private void cutToolStripButton_Click(object sender, EventArgs e)

        {

            Control[] txtBoxArray;

          //  int o = txtBoxArray.Length;

            txtBoxArray = new Control[10];

            for (int i = 0; i != txtBoxArray.Length; i++)

            {

               

            }

        }


#8
kemnet

kemnet

    Newbie

  • Members
  • PipPip
  • 13 posts
Hi thanks it worked but I was still kind of wondering how i was too loop thru the array and cut them.thanks


  private void cutToolStripButton_Click(object sender, EventArgs e)

        {

            Control[] txtBoxArray;

          //  int o = txtBoxArray.Length;

            txtBoxArray = new Control[10];

            for (int i = 0; i != txtBoxArray.Length; i++)

            {

          //      txtBoxArray.Cut();

            }

        }




#9
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
You almost got it there, but the loop should look more like this.
for(int i = 0; i < txtBoxArray.Length; i++)
{
txtBoxArray[i].Cut();
}

This tutorial may help you a bit if you dont understand that. :)
http://forum.codecal...ial-arrays.html

~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#10
kemnet

kemnet

    Newbie

  • Members
  • PipPip
  • 13 posts
Thats what i was thinking. but its not accepting Cut.System .control doesnt contain a defination for cut

#11
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 243 posts
Change the "Control[] txtBoxArray" to "TextBox[] txtBoxArray".

#12
kemnet

kemnet

    Newbie

  • Members
  • PipPip
  • 13 posts
ok so my code should be
txtBoxArray = new control[3] etc etc etc


TextBox[]txtBoxArray;

txtBoxArray=new TextBox[5]

for (int i=0; i < txtBoxArray.length;i++)

{

txtBoxArray[i].Cut();

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users