|
Depends on the quality of the animation and whether or not you want to require additional dependencies.
You could use a PictureBox to show an animated GIF, but GIFs only display 256 colors and don't support an alpha channel.
If you want to display an AVI or other video file, you could host the Windows Media Player control and hide its UI. Windows also contains an older version of this control but you may have problems finding information about it.
Another option is to use DirectX, for which there is now a managed runtime (aptly named Managed DirectX (9.0b)).
Finally, you could always use a timer and loop frames (basically what a GIF does). You can use a higher quality image this way, but your FPS are limited by the relatively low resolution of the timer classes in the .NET Framework.
Again, it all depends on what you want and how many dependencies you're willing to require.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The animation is little, but needs 24-bits color and alpha. I think I'll use the timer cuz I don't know how to use DirectX, I imagine that with DirectDraw2D I could do it, but I don't know how, you know some good info about??.
Thanks
----
hxxbin
|
|
|
|
|
|
When I call method from a custom ServicedComponent object from ASP.NET, I get the following exception:
?
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: ?
Note the question mark as the exception message.
Here is the stack trace:
InvalidCastException: ?]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +264
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +877
MyCOMPlusApp.MyInterface.MyMethod(String s1, String s2)
Intermediary method calls
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
The return value is a string.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
This information doesn't help at all. Stack traces are only helpful if you know the code that adds to the call stack. Since you provided none, it's pretty hard to help you. Why don't you provide some code in your Click event handler or something?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I thought this information could ring a bell on what may be a well-known issue. The problem is that I cannot post code because it is proprietary code. I will try to make an example with which i can reproduce this problem.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
I have more information, now I have a message instead of the question mark:
System.InvalidCastException: QueryInterface for interface MyApplication.IMyInterface failed
Here is how the Serviced component object is declared:
namespace MyApplication
{
[SecurityRole("MyAppClients")]
public interface IMyInterface
{
string MyMethod(string s1, string s2);
}
[ConstructionEnabled(true, Default="Server=(local);trusted connection=yes")]
[Transaction(TransactionOption.Supported)]
[ComponentAccessControl(true)]
[SecurityRole("MyAppClients")]
public class MyClass: ServicedComponent, IMyInterface
{
private string connectionString = String.Empty;
public MyClass()
{
}
protected override void Construct(string s)
{
this.connectionString = s;
base.Construct(s);
}
#region IMyInterfaceimplementation
public string MyMethod(string s1, string s2)
{
return "My String";
}
#endregion
}
When the application is registered in COM+, I add the MYMACHINE\ASPNET user to the role.
Here is how it is called from the Asp.NET client:
IMyInterface myInterface = new MyClass();
string aString = myInterface.MyMethod("s1", "s2"));
The exception is thrown at the second line.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
It's just a hunch since I don't have a lot of experience writing serviced components in .NET, but I have and do work a lot with COM interoperability. When exposing types to COM (as CCWs), you should follow the "rules" of COM, such as attributing your interfaces and classes with the GuidAttribute to give them specific IIDs and CLSIDs. These GUIDs and the interface declarations should never change after being published.
Since your QI is failing to get the interface, I'm figuring it's because the IID can't be resolved. When registering, this GUID is generated automatically unless explicitly specified.
I hope this helps.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Michel Prévost wrote:
IMyInterface myInterface = new MyClass();string aString = myInterface.MyMethod("s1", "s2"));
You should make sure you your cast were successful. I am not sure why it is failing but you definitely want to perform some error checking:
IMyInterface myInterface = new MyClass();
if(myInterface != null)
string aString = myInterface.MyMethod("s1", "s2");
- Nick Parker My Blog
|
|
|
|
|
Hi I want to create a text box only for number
i create a user control that inherits from textbox
and override onkeypress to enter only number
but i can't do it . I try with processKeyMessage but i can't again
is nobody can help me.
Regards' Amirjalaly
|
|
|
|
|
What can't you do? Please be more specific. A simple example using OnKeyPress would look like:
public class NumericTextBox : TextBox
{
protected override void OnKeyPress(KeyEventArgs e)
{
if (e.KeyCode < Keys.D0 || e.KeyCode > D9 ||
e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
e.Handled = true;
base.OnKeyPress(e);
}
} You can do this by overriding ProcessDialogChar or ProcessDialogKey as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The problem with this approach is that it doesn't stop anyone from pasting a string, and this will block Backspace key as well. It will also not accept decimal numbers.
I needed a numeric text field control a while ago, and I thought it would be as simple as overriding OnKeyPress, but there is more to it.
|
|
|
|
|
You can change the sample to accept backspace, delete, and the decimal point. In order to validate pasted text, override OnTextChanged or OnValidating . It's possible to do what you need, you just have to override the right methods as necessary.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Try this one:
private void textBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
this.validValue = this.Text;
}
private void textBox_TextChanged(object sender, System.EventArgs e)
{
try
{
int.Parse(this.Text);
}
catch (System.FormatException)
{
this.Text = this.validValue;
}
}
|
|
|
|
|
Almost...
private void textBox_TextChanged(object sender, System.EventArgs e)
{
try
{
if(this.Text.Length > 0)
int.Parse(this.Text);
this.validValue = this.Text
}
catch (System.FormatException)
{
this.Text = this.validValue;
}
}
|
|
|
|
|
Interesting, I will consider this in my application.
Never needed to look for an empty string, because all my TextBoxes, i use this for, have default values. But better be prepared for all cases
By the way, what happens, if the Parse method is called with a string with Length = 0?
|
|
|
|
|
int.Parse throws a FormatException when given a zero length string so that check is definitely necessary (at least it is for my application)
|
|
|
|
|
how to assigning a Drive to a Share in c#?
Currently, i try the API for make that but he don't run....
Could you help me ?
public enum ResourceScope
{
RESOURCE_CONNECTED = 1,
RESOURCE_GLOBALNET,
RESOURCE_REMEMBERED,
RESOURCE_RECENT,
RESOURCE_CONTEXT
};
public enum ResourceType
{
RESOURCETYPE_ANY,
RESOURCETYPE_DISK,
RESOURCETYPE_PRINT,
RESOURCETYPE_RESERVED
};
public enum ResourceUsage
{
RESOURCEUSAGE_CONNECTABLE = 0x00000001,
RESOURCEUSAGE_CONTAINER = 0x00000002,
RESOURCEUSAGE_NOLOCALDEVICE = 0x00000004,
RESOURCEUSAGE_SIBLING = 0x00000008,
RESOURCEUSAGE_ATTACHED = 0x00000010,
RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED),
};
public enum ResourceDisplayType
{
RESOURCEDISPLAYTYPE_GENERIC,
RESOURCEDISPLAYTYPE_DOMAIN,
RESOURCEDISPLAYTYPE_SERVER,
RESOURCEDISPLAYTYPE_SHARE,
RESOURCEDISPLAYTYPE_FILE,
RESOURCEDISPLAYTYPE_GROUP,
RESOURCEDISPLAYTYPE_NETWORK,
RESOURCEDISPLAYTYPE_ROOT,
RESOURCEDISPLAYTYPE_SHAREADMIN,
RESOURCEDISPLAYTYPE_DIRECTORY,
RESOURCEDISPLAYTYPE_TREE,
RESOURCEDISPLAYTYPE_NDSCONTAINER
};
public class ServerEnum : IEnumerable
{
enum ErrorCodes
{
NO_ERROR = 0,
ERROR_NO_MORE_ITEMS = 259
};
public class ServerEnum : IEnumerable
{
enum ErrorCodes
{
NO_ERROR = 0,
ERROR_NO_MORE_ITEMS = 259
};
[StructLayout(LayoutKind.Sequential)]
private class NETRESOURCE
{
public ResourceScope dwScope = 0;
public ResourceType dwType = 0;
public ResourceDisplayType dwDisplayType = 0;
public ResourceUsage dwUsage = 0;
public string lpLocalName = null;
public string lpRemoteName = null;
public string lpComment = null;
public string lpProvider = null;
};
[DllImport("Mpr.dll", EntryPoint="WNetAddConnection2", CallingConvention=CallingConvention.Winapi)]
private static extern ErrorCodes WNetAddConnection2(NETRESOURCE lpNetResource,ref string lpPassword,ref string lpUsername, System.UInt32 dwFlags );
public void connectMapDrive(){
NETRESOURCE lpNetResource = new NETRESOURCE();
lpNetResource.dwType =ResourceType.RESOURCETYPE_ANY;
lpNetResource.lpLocalName="O:";
lpNetResource.lpRemoteName= @"\\Bruxptest\Fichiers" ;
lpNetResource.lpProvider = "";
string lpPassword ="PASSWORD**" ;
string lpLocalName =@"bruxptest\ll2";
ErrorCodes rc = WNetAddConnection2(lpNetResource,ref lpPassword,ref lpLocalName,0x01);
}
}
-=zoltx=-
|
|
|
|
|
First, you didn't describe any errors or what exactly the problem was. It's very hard to help you when you don't mention specific problems.
Second, why not make this easier:
string drive = "X";
string share = @"\\machine\share";
Process.Start("net.exe", string.Format("use {0}: {1}", drive, share)); You could easily add switches for a username and password, too. Type "net use /?" in the command prompt for more information.
If you'd rather do this programmatically, then please be more specific about the nature of your problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
sorry,
I would like to make a windows service which able to check and map the shared drive automatically. When i launch my api for that, I receive a error message 2202: ERROR_INVALID_WINDOW_STYLE
the equivalence in c++ is :
#include <windows.h>
#include <stdio.h>
#include <winnetwk.h>
void main()
{
NETRESOURCE nr;
DWORD res;
TCHAR szUserName[32] = "MyUserName",
szPassword[32] = "MyPassword",
szLocalName[32] = "Q:",
szRemoteName[MAX_PATH] = "\\\\products2\\relsys";
//
// Assign values to the NETRESOURCE structure.
//
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = szLocalName;
nr.lpRemoteName = szRemoteName;
nr.lpProvider = NULL;
//
// Call the WNetAddConnection2 function to assign
// a drive letter to the share.
//
res = WNetAddConnection2(&nr, szPassword, szUserName, FALSE);
//
// If the call succeeds, inform the user; otherwise,
// print the error.
//
if(res == NO_ERROR)
printf("Connection added \n", szRemoteName);
else
printf("Error: %ld\n", res);
return;
}
and it is work?
-=zoltx=-
|
|
|
|
|
Are you running the app as the LOCAL SYSTEM account or as a user? Also, you have to tag the service as able to interact with the desktop.
RageInTheMachine9532
|
|
|
|
|
user, and interact........
-=zoltx=-
|
|
|
|
|
helo, my name is keen weng. i am new in c#. I am currently doing a project using c#, my question is how could i write a program which i could remotely control a mouse or access to a hard disk in other pc which is connected in a same local area network?is it possible? but, i am not talking about hacking because i am making something like network monitoring system .what references should i refer to? , thank you.
weng
|
|
|
|
|
Yes, it's called PCAnywhere from Symantec. Your going to need to write a client and server, just like PCAnywhere.
The server piece will go on the workstations you want to control. It will have to have code to get the desktop image, hooks into Windows to control the mouse and keyboard, and you'll probably want to write a small file transfer server also. You'll also need to write a communications class that can encode and decode commands between the two modules.
The client piece is going to call into the servers to get the screens that they are looking at. Also, you'll need to map mouse moves and clicks and keystrokes on your client to the screen that is coming from the workstation you want to control.
It's very possible to do, but is a bunch of work. I'd consider going with a commercial package before dumping your time into a few months of development, especially since your new to C#. I'd tackle a more managable project to learn with first.
RageInTheMachine9532
|
|
|
|
|
In addition to PCAnywhere, there are others. If your workstations are running Windows XP, there's a client build right-in (but works on a request basis). You can enable it (I think it is by default) by going to your System properties (in the Control Panel, or right-click on My Computer and select Properties), then the Remote tab, and right there are the top is information about Remote Assistance, which users can invoke from the Help and Support menu off the Start menu. Help and Support can also be highly customized to fit the needs of OEMs and domains.
As Dave said, why spend lots of man hours when so many things like this already exist, many of which are cheaper than all the time spent developing such a project. And not just because you're new to C# and .NET, those existing products will most likely be better (to some degree) because they've been in development by dedicated teams of professionals for many years (even the Windows XP remote assistance has foundations in NetMeeting technology introduced back in '96 or so).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|