a to z buttons at runtime

N

Nicholas Paldino [.NET/C# MVP]

freddy,

All you have to do is get the char value for "a" or "A" and then loop
from that value to that value plus 25. For each iteration of the loop,
create a button, and label it with the current loop index, cast to a
character.

Hope this helps.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You asked yesterday the same question, with more details even !

This was the answer I gave you yesterday, it's still valid today ;)

Hi,

Do this :

Create a new class ButtonEx : Button
{
char letter;
ButtonEx( char whatLetter){ letter = whatLetter; }
}

then create as many controls as you need :
// CODE TAKEN FROM cody's post
for (char l = 'A'; l<='Z'; l++)
{
ButtonEx b = new ButtonEx( l);
b.Text = l.ToString();
b.OnClick = new EventHandler( letterButton_Clicked); /// <<=== the real
thing
myForm.Controls.Add(b);
}

void letterButton_Clicked( object sender ... )
{
//cast the sender to the new button
ButtonEx clicked = ( ButtonEx) sender;
//access the char
clicked.Letter;
//do as needed
}


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


freddy said:
I am creating an inventory program, I would like to know how to create A to
Z
buttons on runtime and than save data to the letter. Like if I hit F I
will
get all the names that start with F
 
G

Guest

I have the code to creat the buttons - thanks, but it only creates the a
button and not b,c .. and so on I am using
b.location = new point (x,y);
b.size = new size (x,y);
I forgot the x and y numbers but it is displying just the letter A. I would
like to display them one after the other
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi

the code I just sent you create all the buttons, jst remember to change the
location as you desire

cheers,
 
G

Guest

so if I have a button like
b.location = new point (10,25); and I want another one created next to it
so would it be
b.location = new point(10,35);
or can I do someting like
x = 10
y = 25 ++
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

you would do

y += 25;

Point p = new point(10,35);

for (char l = 'A'; l<='Z'; l++)
{
ButtonEx b = new ButtonEx( l);
b.Text = l.ToString();
b.Location = p;
p.Y+=25;
b.OnClick = new EventHandler( letterButton_Clicked); /// <<=== the real
thing
myForm.Controls.Add(b);
}


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top