|
Not trying to be a pain and curious to see what you are talking about could you show a sniplet to describe what you are talking about, just having a problem visualizing this, if it is how I think I understand it.
Nick Parker
|
|
|
|
|
Perhaps a fresh perspective is needed
When dealing with events, two things are involved. A multicast delegate (ie a delegate that when invoked runs multiple methods) and the event handlers attached to that delegate.
When one calls myButton.PerformClick() you are telling the Button to fire the Click event, this in turn invokes the multicast delegate that represents the event object. This will then run all event handlers attached to the event/delegate.
When you call myButton_Click(this, EventArgs.Empty); you are calling a method that just happens to be attached to the Click event. None of the other handlers get fired and thus the click didn't really happen to anything but that one handler.
A simple test, create a form with a button named "myButton" on it, now add the following code to the class
protected override void OnLoad(EventArgs e)
{
myButton.Click += new EventHandler(click_a);
myButton.Click += new EventHandler(click_b);
}
private void click_a(object sender, EventArgs e)
{
MessageBox.Show("In click_a");
}
private void click_b(object sender, EventArgs e)
{
MessageBox.Show("In click_b");
} Now add another button to the form and try your way of forcing a click and the PerformClick method.
Obviously you'll have to call both click_a and click_b in order to get the same effect; but what if other objects have attached themselves to the click event? You have no direct way of calling them since you don't even know who or what they are; which is why the PerformClick method was created.
Hopefully that makes it clearer for you
James
|
|
|
|
|
James T. Johnson wrote:
Hopefully that makes it clearer for you
Thanks James, it does. I would like to add that many times when you want to call a click event there is only one click event that you would want to call, not two or more(at least related when related to the same object). Why would another object attach itself (i.e. - your example with one button handling multiple events) to something that already handles an event. I guess I am not seeing the value in this ability. Thanks for the visual aid though, it did help to show Rama's point.
Nick Parker
|
|
|
|
|
Nick Parker wrote:
Why would another object attach itself (i.e. - your example with one button handling multiple events) to something that already handles an event.
It doesn't happen often, but one possiblity could be a logging application where it logs all actions taken by the user. It would have one method attached to all control's Click event so it could log the event.
Another thing to look out for would be any code the button itself performs when it is clicked. The default button doesn't do anything [that i know of], but derived classes might.
James
|
|
|
|
|
I suppose it is always nice to know there are a million ways to do even the simplest tasks.
Nick Parker
|
|
|
|
|
Button object has a PerformClick method which does that.
|
|
|
|
|
Hi,
How can I keep the mouse from leaving a form? I'm after the same behavior that you can see in the Form Designer of the Visual Studio IDE. When you click and hold the mouse in the form that you are designing and then drag the mouse a dashed box is draw but the IDE will not allow you to move out of the form.
What can I put in the MouseMove event that will keep the mouse pointer in my form?
Thanks!
|
|
|
|
|
You could create a Rectangle object that hold the dimmensions of your window and then check those positions against your cursors current position.
HTH
Nick Parker
|
|
|
|
|
Thanks, that sounds like a start but the thing that I'm not sure about is how to "reset" the mouse's X and Y when the mouse attempts to move out of the rectangle.
|
|
|
|
|
That shouldn't be a big deal. When you confirm that the user is trying to set the cursor outside of the form (the points you are evaluating), you will then just set Cursor.Position(myPoint); to the boundary edge of the form. myPoint would be defined as a Point structure.
HTH
Nick Parker
|
|
|
|
|
if i want to capture the mouse movement and its action on any control how to do it ?
r00d0034@yahoo.com
|
|
|
|
|
You can create an ArrayList of Point 's. You will need to check to check the bounds as well. There maybe several ways to tackle that.
Nick Parker
|
|
|
|
|
if u could tell in detail i would be very thank full to u because i am doing mine final project and i am doing the same work for many days but couldnt succeed yet?
r00d0034@yahoo.com
|
|
|
|
|
There are quite a few (a lot actually) of articles listed here[^] on how to use C#. If you have a question about how to do something, show your code in a new thread here and I'm sure someone will try to help. I can not do your *project* for you as I am currently too involved right now. If you do have a question I would be glad to try and help you out though.
Nick Parker
|
|
|
|
|
How to make a color on a Graphics object or a Bitmap object transparent?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Why not use an ImageList ?
Once an ImageList object from the .Net toolbox is added to your form, you can change the properties and btw indicate the transparent color.
In fact, this works exactly the same than with MFC CImageList.(which itself is a wrapper of WIN32 ImageList API).
|
|
|
|
|
Say you have a graphics object named g you can do this:
g.Clear(Color.Transparent);
HTH
Nick Parker
|
|
|
|
|
There is a MakeTransparent method in the Bitmap class
James
|
|
|
|
|
public class Shell
{
[StructLayout(LayoutKind.Sequential)]
private struct SHFILEOPSTRUCT
{
public System.IntPtr hWnd;
public System.Int32 wFunc;
[MarshalAs(UnmanagedType.LPStr)]
public System.String pFrom;
[MarshalAs(UnmanagedType.LPStr)]
public System.String pTo;
public System.Int32 fFlags;
public System.Int32 fAnyOperationsAborted;
public System.IntPtr hNameMappings;
[MarshalAs(UnmanagedType.LPStr)]
public System.String lpszProgressTitle;
}
[DllImport("shell32.Dll")]
private static extern System.Int32 SHFileOperation(ref SHFILEOPSTRUCT lpFileOp);
private enum FileOpFunc {Delete = 3}
private enum FileOpFlags {Silent=0x04, AllowUndo=0x40, NoConfirmation=0x10}
static public void MoveFileToRecycleBin(string filePath)
{
SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT();
fileop.wFunc = (int)FileOpFunc.Delete;
fileop.pFrom = filePath;
fileop.fFlags = (int)(FileOpFlags.Silent|FileOpFlags.AllowUndo|FileOpFlags.NoConfirmation);
SHFileOperation(ref fileop);
if(System.IO.File.Exists(filePath))
throw new System.IO.IOException("Could not move " + filePath + " to the recycle bin.");
}
}
|
|
|
|
|
Sorry I hit submit instead of preview!
Anyway here is the problem. The call to SHFileOperation() on it's own works and the file is moved to the recycle bin. If I test the return value or test if the file exists the call to SHFileOperation() fails to move the file.
This is the strangest problem I think I have ever seen.
BTW my test file is a 0 length text file C:\Test.txt
HELP I'm scared!
Joel
|
|
|
|
|
Okay I found the problem, it was a combination of incorrect structure declaration and not double nulling the pFrom member (who's idea was that, a semi-colon would have worked with a single null at the end grrr).
Joel
|
|
|
|
|
|
|
|
Not directly.
If, when you browse to the directory on the website, you get a list of files you can parse the resulting page for the filenames.
There is also an HTTP extension called Web DAV but I only know the name; I don't know anything else about it
James
|
|
|
|