|
Hi.
I'd like to know how to generate/create a specific number of components - buttons. The user would give out the number of buttons.
Every button should have its own working onclick code. And i could manipulate with every one of them whenever i want.
The creating part is partly know to me... but dont know how to control and rename them to get control for example ...
Button1 and button2 when i have buttons from 1-10.
Button1.Text="blah blah";
Button2.Text="the second butt.";
button3.Text="smthn";
etc.
Im really sorry if i have so many newbie questions but its just he way i am. Stil learning.
If there are any answers - i thank you for them
Have a nice day,
Matjaž
Força Barça!
|
|
|
|
|
hi,
Use for loop to create the button and add eventhandler for each button you create.Below is a sample:
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}
private void Form1_Load(object sender, EventArgs e)
{
Button[] b = new Button[3];
for (int i = 0; i < 3; i++)
{
b[i] = new Button();
b[i].Name = i.ToString();
b[i].Click +=new EventHandler(Form1_Click);
b[i].Location = new Point(i * 10, i * 10);
}
this.Controls.AddRange(b);
}
private void Form1_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
Console.WriteLine(b.Name);
}
Hope this help
|
|
|
|
|
max00slo wrote: The user would give out the number of buttons.
void CreateButtons(int num)
{
Button[] button = new Button[num];
for (int i = 0; i < num; i++)
{
button[i].Click += new EventHandler(Buttons_Click);
this.Controls.Add(button[i]);
}
}
max00slo wrote: Every button should have its own working onclick code
void Buttons_Click (object sender, EventArgs e)
{
Button b = sender as Button;
switch (b.Name)
{
}
}
Hope I could understand you and could help
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
Nice explain
|
|
|
|
|
Thank you
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
|
dear all,
I would like to know how can i detect the arrows key (left and right) when key press event handler in window application?
thanks in advance.
regards
cocoonwls
|
|
|
|
|
The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events.
in KeyDown or KeyUp events you can detect arrows by e.KeyCode.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
Simple. With ASCII Code.
lets take an example of pressing the keys in just form1:
if(e.KeyChar==37)<br />
txtStatus.Text = "You've pressed the left arrow key.";<br />
if(e.KeyChar==38)<br />
txtStatus.Text = "You've pressed the up arrow key.";<br />
if(e.KeyChar==39)<br />
txtStatus.Text = "You've pressed the right arrow key.";
This is just a small example to get you started and so that u get to know the use of ASCII char tables.
Edit: Well it would be, if it would work... kinda forgot how i used this stuff.
Heres a good link on explanating the keypress control:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(VS.71).aspx[^]
Greets,
Matjaž
Força Barça!
modified on Wednesday, November 5, 2008 1:54 AM
|
|
|
|
|
Hi Pedram Behroozi and max00slo,
I have tried it before, for other char is OK, but i just can't detect the arrows key.It never fire the keydown event. What i am do in my application is, i create the keydown event handler in one of my custom UI control, and it will pass the event args to one of my class via a abstract class.
any ideas are welcome.
thanks in advance
cocoonwls
modified on Wednesday, November 5, 2008 2:16 AM
|
|
|
|
|
cocoonwls wrote: i just can't detect the arrows key
Didn't this work?
if (e.KeyCode == Keys.Right)
{
...
}
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
Thanks for reply.
yes, i also try it .keycode, but still can't fix it..
|
|
|
|
|
You will need to override ProcessCmdKey method to catch the arrow key press.
|
|
|
|
|
Hi d@nish,
Can you please give me a simple explain on it, where should i put the override code, and should i add the virtual method on it(for override)?
thanks in advance
cocoonwls
|
|
|
|
|
You just need to override the method in your class. This VB.Net[^] code should get you going with it.
|
|
|
|
|
Thanks i got it!
|
|
|
|
|
you must derive a new class that is based on the class of the control that you want, and you override the ProcessCmdKey().
Syntax:
C#:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
}
Full source code..C# Arrow Key Press
Vayne
|
|
|
|
|
I've got the following code that attaches a thumbnail image coming from an ImageList to a PictureBox. However, it is causing my application to not close once the code block gets executed. I suspect this has got to do with the resource(the photo file) not being released properly, I may be wrong though. Any experts advice would be greatly appreciated. All the best!
<br />
Image.GetThumbnailImageAbort myCallback =<br />
new Image.GetThumbnailImageAbort(ThumbnailCallback);<br />
Image myThumbnail = this.imageList1.Images[0].GetThumbnailImage(this.pictureBox1.Size.Width-5, this.pictureBox1.Size.Height-5, myCallback, IntPtr.Zero);<br />
<br />
this.pictureBox1.Image = myThumbnail;<br />
this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
----------------------------------------------------------
"unzip; strip; touch; finger; mount; fsck; more; yes; unmount; sleep" - my daily unix command list
|
|
|
|
|
The code works fine for me.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Image myThumbnail = this.imageList1.Images[0].GetThumbnailImage(this.pictureBox1.Size.Width - 5, this.pictureBox1.Size.Height - 5, myCallback, IntPtr.Zero);
this.pictureBox1.Image = myThumbnail;
this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
}
private bool ThumbnailCallback()
{
return true;
}
}
And the app exits fine.
Failure to exit is usually caused by a thread not terminating correctly. Does your abort callback get triggered? Does it correctly return?
You don't need to release the Image. This is handled by the Imagelist for you provided that you have added your image list via the designer or correctly disposed of it manually, either way though, this wouldn't prevent your app from closing.
After you have closed your app, and it's stuck without terminating, try hitting the pause button and looking at the call stack to see where it is stuck.
Simon
|
|
|
|
|
hello all,
i am new in window apllication c#. when i load rtf file in richtextbox control with every new paragraph with and <\p>.
i have done this..but can't remove whitespace.
he show with blankspace <\p>.
like..there is five paragraph in file.
aaaaaaaaaaaaaaaaaaaaaaaaaa<\p>
<\p>
<\p>
aaaaaaaaaaaaaaaaaaaaaaaaaa<\p>
aaaaaaaaaaaaaaaaaaaaaaaaaa<\p>
here, i want to remove two blanckspaces..
|
|
|
|
|
what is <\p> ?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
|
how To Add Product key Setup please help me
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
We cant help if we dont know your specific problem.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
I want to modify this RegisterHotKey func to allow me to set it using HashKey instead of a shortcut key but I'm not exactly sure how to do this.
this is the code for registering the hotkey in the object
protected bool RegisterHotkey(Shortcut key)
{
int mod=0;
Keys k2=Keys.None;
if (((int)key & (int)Keys.Alt)==(int)Keys.Alt) {mod+=(int)Win32.Modifiers.MOD_ALT;k2=Keys.Alt;}
if (((int)key & (int)Keys.Shift)==(int)Keys.Shift) {mod+=(int)Win32.Modifiers.MOD_SHIFT;k2=Keys.Shift;}
if (((int)key & (int)Keys.Control)==(int)Keys.Control) {mod+=(int)Win32.Modifiers.MOD_CONTROL;k2=Keys.Control;}
System.Diagnostics.Debug.Write(mod.ToString()+" ");
System.Diagnostics.Debug.WriteLine((((int)key)-((int)k2)).ToString());
return Win32.User32.RegisterHotKey(m_Window.Handle, this.GetType().GetHashCode(), (int)mod, ((int)key) - ((int)k2));
}
|
|
|
|