|
You could expose your buttons via a property as a collection (of buttons). But then you are exposing everything about the buttons.
|
|
|
|
|
Doh! Then again, there is nothing stopping you from accessing the built-in Controls collection of the Panel and attaching an event handler dynamically.
|
|
|
|
|
You can expose event properties on your control; like so...
public EventHandler ButtonA_Click
{
add
{
buttona.Click += new EventHandler(value);
}
remove
{
buttona.Click -= new EventHandler(value);
}
} You wind up with having to name the events something different, but you can control what events are available.
HTH,
James
Simplicity Rules!
|
|
|
|
|
The problem is that I create only one instance of a button and Each I wrote tb.AddItem("Test",Color.Black,Color.White,0); (that's an example)
the control add a button itself to the parent control which is a panel.
so how can I handle all the buttons actions when I have only one Button Instance ??
can I make a function like ItemClick(int index,EventHandler action) ??
if yes can u plz give me some code because I try to use this with a switch statement and I got an error :
"a value constant is expected"
Thanks
|
|
|
|
|
I'm having a hard time making out what you are trying to do so let me know if what I suggest answers a different problem.
What I think you're having a problem with is you only have one real button, but you have multiple click events that need to fire.
Using the event handler I described above works fine; it properly handles firing of chained events (multiple methods to run when one event fires).
I'm unsure what your ItemClick function is meant to do though; can you describe in words or psuedo-code what it would do?
James
Simplicity Rules!
|
|
|
|
|
I found it, I just added Envet Handler to my AddItem declaration
|
|
|
|
|
Hi,
Does anyone know how to retrieve the width of a string if outputted to the screen in a given font, e.g. Arial 12 and the string "Hello World"? In other words, how many pixels wide would that string (or any given string) be on the screen?
Thanks!
--
Andrew.
|
|
|
|
|
The graphics object has a MeasureString method which returns the size of the text.
You pass in the string and the font object to measure with. There are a few other parameters that can be used to adjust how the text will be rendered (the StringFormat class).
James
Simplicity Rules!
|
|
|
|
|
Thanks mate! Just what I needed . Now just what I need is some sleep !
Thanks again,
--
Andrew.
|
|
|
|
|
hello james..thanks for ur help.
but saddly it didn't work.
the method Add() must take a string or a ListViewItem ..
i hope we can get a better solution..thanks ))
shadowman
|
|
|
|
|
Sorry, confused ListBox and ListView :-P
I think the current technique is to derive a class from ListViewItem and use that, so...
public class ProcessListViewItem : ListViewItem
{
public readonly Process Process;
public ProcessListViewItem(Process p) : this(p.ProcessName)
{
Process = p;
}
} Now the Add method will work when you pass in an instance of this new list view item
Process [] Processes = Process.GetProcesses();
foreach( Process p in Processes )
{
myListView.Items.Add( new ProcessListViewItem(p) );
} Then when you want to get the underlying process object you just cast the ListViewItem returned from the Items collection back to the ProcessListViewItem and access the Process property.
HTH,
James
Simplicity Rules!
|
|
|
|
|
Or you can just drop the Process object into the ListViewItem.Tag property...
i.e. LVITEM.lParam .NET style.
|
|
|
|
|
Doh! Obvious choice too, damn VB has me thinking that Tag is a string
James
Simplicity Rules!
|
|
|
|
|
James T. Johnson wrote:
damn VB has me thinking that Tag is a string
It's been a long time since I have bothered with VB, but as I remember it, it has a tendency of doing that...
Regards
|
|
|
|
|
After working in C# for so long I wasn't paying attention one day when I started to write a quick MFC app and I wound up writing this.
CSettingsDialog dlg = new CSettingsDialog();
dlg.ShowDialog();
} For those that haven't learned C++ yet I made 3 errors
1) dlg should be a pointer
2) it should be dlg->DoModal();
3) I forgot delete dlg;
Took me all of 30 seconds to realize why my code wasn't compiling
James
Simplicity Rules!
|
|
|
|
|
No, You made 4 errors...
4. If it is a simple modal dialog, You should just have decared it as a stack variable in the first place. No pointer, no delete, no worries...
|
|
|
|
|
I forget what it was for now, but there was some reason I had that. I wonder if Colin remembers the code
James
Simplicity Rules!
|
|
|
|
|
It's cool, When I first stepped into C#, I kept having Java flashbacks and use non-existant classes like StringBuffer and StringTokenizer.
Cheers
|
|
|
|
|
Hello..i used a listview to view the current processes in my Computer..but when i tryed to make any operations on these processes i couldn't ..i donnno how to convert the list items into objects of other class to perform these operations (im my case the System.diagnostics.process class)
here's my code :
private void Form1_Load(object sender, System.EventArgs e)
{
Process[]MyProcArray=Process.GetProcesses ();
foreach (Process MyProc in MyProcArray)
{this.ProcessesList .Items .Add (MyProc.ProcessName );
}
|
|
|
|
|
The problem you are seeing is because you are only adding the string which represents the process name to the list view, instead you need to add the Process object itself.
private void Form1_Load(object sender, System.EventArgs e)
{
Process[] MyProcArray = Process.GetProcesses();
foreach (Process MyProc in MyProcArray)
{
ProcessesList.Items.Add(MyProc);
}
} HTH,
James
Simplicity Rules!
|
|
|
|
|
I wanna check for pressing arrow keys in KeyPress event.
How can I do it?
Thanks
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
I think you can do something like this
if(e.KeyCode == Keys.Right)
{
DoSomething.....
}
|
|
|
|
|
Thanks
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
ez2 wrote:
if(e.KeyCode == Keys.Right)
Sorry,It doesn't exist in System.Windows.Forms.KeyPressEventArgs ,So How can I use it?
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
mazdak,
I just checked and your right. It looks as though keyPressEventArgs only handles characters (i.e. e.KeyChar returns a char) and not other keys like ALT, Arrows, etc. Not sure why that is so I will do some checking.
Alternatively, you could use the Keydown event which does have a KeyEventArgs and you can trap additional keys. In that case,
if(e.KeyCode == Keys.Right) should work.
I need some clarification myself on keydown vs. keypress anyway so I will let you know what I find.
|
|
|
|