|
Hotlinux wrote:
I would like to invoke any control's event just as if the user or another source would. This, of course without building my own derivated class.
If you want to use reflection, get access to the "Onxxx" protected method and call it, rather than trying to extract the EventInfo. The problem with GetRaiseMethod is it doesn't handle multicast events, which is what all the controls use. It'll return a null, because more than one handler can be assigned to something like a Click event.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
|
leppie wrote:
AFAIK GetRaiseMethod() is not implemented for C#.
Out of curiosity (well, actually, more than curiosity), is there any way to get the methods assigned to a multicast delegate?
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Here is an example (in .NET 2, i think DynamicInvoke's args is different in .NET 1):
class Program
{
event EventHandler SomeEvent;
EventHandler SomeHandler;
static void Main(string[] args)
{
Program p = new Program();
EventHandler eh1 = new EventHandler(p.Method1);
EventHandler eh2 = new EventHandler(p.Method2);
EventHandler eh3 = new EventHandler(p.Method3);
EventHandler eh4 = new EventHandler(p.Method4);
p.SomeEvent += eh1;
p.SomeEvent += eh2;
p.SomeEvent += eh3;
p.SomeEvent += eh4;
p.SomeHandler += eh1;
p.SomeHandler += eh2;
p.SomeHandler += eh3;
p.SomeHandler += eh4;
p.FireEvent();
p.FireHandler();
Console.WriteLine("Invoke event");
foreach (Delegate d in p.SomeEvent.GetInvocationList())
{
d.DynamicInvoke(p, EventArgs.Empty);
}
Console.WriteLine("Invoke handler");
foreach (Delegate d in p.SomeHandler.GetInvocationList())
{
d.DynamicInvoke(p, EventArgs.Empty);
}
Console.ReadLine();
}
void FireEvent()
{
Console.WriteLine("FireEvent");
if (SomeEvent != null)
{
SomeEvent(this, EventArgs.Empty);
}
}
void FireHandler()
{
Console.WriteLine("FireHandler");
if (SomeHandler != null)
{
SomeHandler(this, EventArgs.Empty);
}
}
void Method1(object sender, EventArgs e)
{
Console.WriteLine("Method1");
}
void Method2(object sender, EventArgs e)
{
Console.WriteLine("Method2");
}
void Method3(object sender, EventArgs e)
{
Console.WriteLine("Method3");
}
void Method4(object sender, EventArgs e)
{
Console.WriteLine("Method4");
}
}
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
I have that same code in my MxEventPool! How easily we forget code already written!
Now if only I can remember why I wanted something like this!
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
The firing event idea (or problem) came to me when i wanted that a control from one form fired an event of the other.
---------------------------------------------------------------------------
Answer To Polis Pilavas:
Yes one of the reasons i would like to fire up an event is to reuse the code.
Of course there are other ways like this but they dont always work.
_Event(object sender, .....)
{
Do_Something();
}
Do_Something()
{
........
}
But then it's no fun. Or what other forms were you thinking about?
-------------------------------------------------------------
Answer to Marc Clifton:
You mention that i could use the OnXXX protected methods, they are protected, that means i can't just call them, i have to have a derivated class so i can use them.
You also say GetRaiseMethod is only good for single-delegates, that sounds kind of logical but leppie says its not implemented in C#. :????!!!
It would be nice to fire up events by code, Visual Basic 6.0 had some of that.
I remember something like a Do_Click method and i remember using it from time to time.
By invoking delegates and events like you proposed, do they really simulate the same procedures just as if the user or the system had fired them up?
Ill try what's written
Thanks for everything
|
|
|
|
|
hi all;
I am trying to connect sql server2000 with asp.net(C#).
but nothing happens.
Actual problem comming from connection string which is not coming to solve
my code is as follow:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page language="C#" %>
void Page_Load()
{
string my="workstation id=HOME;packet size=4096;integrated security=SSPI;data source=HOME;persist security info=False;initial catalog=PrintQuota";
SqlConnection mycon=new SqlConnection(my);
try
{
mycon.Open();
TextBox1.Text="Connection opend successfully";
mycon.Close();
}
catch (Exception g)
{
TextBox1.Text=g.ToString();
}
}
The main problem is with user id and password,, i have also checked with integrated security=SSPI but no way to connect..the same string i use in window application but its work but here in web app its not working
error message from exception is
error
System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) at System.Data.SqlClient.SqlConnection.Open() at ASP.UserInfo_aspx.Page_Load() in http://localhost/WebApplication1/UserInfo.aspx:line 16
plz solve my problem . i m waiting for replies.
with regards Ishtiaq
|
|
|
|
|
Since you're using integrated security and ASP.NET is running under the NT AUTHORITY\NETWORK SERVICE account (must be IIS6 on Windows Server 2003), the SQL Server won't authenticate it you because 1) it doesn't have an account added for that user account, and 2) because NETWORK SERVICE is a local account - not a domain account. If SQL Server is on your web machine, you could get away with doing that, but it won't work if it's on another machine.
Either use a specific username and password (typical on web machines) or impersonate a user. You can do this using the <identity> element in your application's (or web site's) Web.config file. You could also impersonate any requesting user and let SQL Server decide if they can query the data. It really depends on your requirements.
To encrypt the connection string with the username and password in the registry and have ASP.NET use that instead of putting the plain-text string on the server, read http://support.microsoft.com/default.aspx?scid=kb;en-us;329290[^].
In the future, however, please post ASP.NET-related questions to the ASP.NET[^] forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
What would be the best way to display row numbers in a datagrid? Simply 1,2,3,4,5, etc.
Thanks for any help.
-Sam
|
|
|
|
|
sammyh wrote:
What would be the best way to display row numbers in a datagrid? Simply 1,2,3,4,5, etc.
Insert a column into the underlying DataTable and number it?
Well, that's one idea. Probably not the best.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
The problem with that is once you sort the data your "row numbers" are off. Note that you must use the DataView 's view of the row, not the DataTable . Through the CurrencyManager this is typically pretty easy, but I still don't know of a decent way off the top of my head to display and manage that data in a DataGrid . Thank goodness for the DataGridView[^] in .NET 2.0.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
DataGrid is such an awkward control, a major pain if you ask me. I'm looking forward to using .NET 2.0. Any tips to get me in the right direction. Or should I opt for a 3rd party control?
Thanks,
Sam
|
|
|
|
|
If you're not tied to .NET 1.x, I suggest you download Visual Studio 2005 Beta 2[^] and start working with .NET 2.0. You can also get a Go-Live License[^], which is an addendum to the EULA that allows you to distribute applications based on beta 2 into the production environment.
If you need a solution now, I would first suggest some serious research (googling, newsgroups at http://msdn.microsoft.com/newsgroups[^], etc) and then consider a third-party solution. If and when you do move to .NET 2.0 your third-party control would be obsolete, though - honestly - most third-party controls are pretty inexpensive and typically royalty-free.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi Everyone,
I have created a service with the help of dotnet framework and without the help of MSI(Installshield). I want to see my service(WindowsService_1) in Windows Service and using "installutil tools" (which Microsoft provided) which install my service in windows service but exception is raised
"Exception occurred while initializing the installation:
System.IO.FileNotFoundException: File or assembly name windowsservice_1.exe, or one of its dependencies, was not found.."
So I am following each and everystep which is given on MSDN example and other site. I want to write a service without using MSI(Installshield).
I go to command prompt(cmd) and write "InstallUtil windowsservice_1.exe". But is throwing an exception.
I am giving full path of InstallUtil.exe.
Can you help me out making a simple service.
Thanks
|
|
|
|
|
For future reference, you should include the full exception stack.
Beyond that it reads like you are missing a dependancy. Fusion is trying to resolve runtime depedancies and fails to find one so it never runs let alone run as a Windows Service. Fix that first.
|
|
|
|
|
In MSI you should use the File key (and the Visual Studio .NET Windows Installer project will continually change this on you) as the argument with quotes, like installutil "[$fileKey]" . You must also either get the full path to installutil.exe by using [WindowsFolder]Microsoft.NET\Framework\v1.1.4322\installutil.exe for .NET 1.1, for example. This can get tricky.
The exception is most likely because one of the assemblies your windowsservice_1.exe assembly depends on is not found. Please read How the Runtime Locates Assemblies[^] for more information. You can also see what assembly is missing by running fuslogvw.exe from the .NET Framework directory.
Finally, you MUST make sure the client has the .NET Framework - to correct version, or you'll need to use a publisher policy - installed or none of this will work. If you write managed code, the runtime is required to run it.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks a lot everyone.
I got my answer and now I can successfully see service in windows service.
Once again
Thanks
|
|
|
|
|
hi
i want to open a new window and send a url address to it for browsing.
wat can i do?
** some thing like href tag with target=_blank **
thanks
|
|
|
|
|
If you mean from a web page, you can't do that. Please ask in the Web Development[^] forum.
If you are automating Internet Explorer (perhaps using the AxWebBrowser control or the InternetExplorer class), you can call Navigate2 with the correct parameters like so:
object url = "http://mydomain.com";
object name = "_blank";
object missing = Missing.Value;
axWebBrowser1.Navigate2(ref url, ref missing, ref name, ref missing, ref missing); If neither of these answer your question, please be specific in your request. Your question is, I must say, rather vague. Please provide as much information as you can that's relevant to your problems and questions.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have to agree that your question is rather vague.
In case you are talking about automating IE from a windows form you could also take a look at the System.Diagnostics namespace. A couple of straight-forward examples:
Example 1:
Process.Start("IExplore.exe", "www.codeProject.com");
Example 2:
ProcessStartInfo <code>startInfo </code>= new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);
startInfo.Arguments = "www.codeProject.com";
Process.Start(startInfo);
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Hi,
I am trying to get the windowstate of a window based on its process id.
Below is what I tried... But the GetWindowPlacement method returns false most of the times inspite of the length of the windowplacvement object being initialized. Even if the method returns true, its showCmd is always NORMAL. While testing my window was always MAXIMIZED!
Can anyone point what I am missing...?
Can anyone explain how the window state is maintained. ......
Thanks!
FormWindowState GetWindowState(int processID)
{
FormWindowState formWindowState = FormWindowState.Normal;
WINDOWPLACEMENT windowPlacement = new WINDOWPLACEMENT();
//If there is not proces by this ID, then return Minimized.
uint processHandle = (uint)Process.GetProcessById(processID).Handle;
if ( processHandle.Equals(0) )
{
return FormWindowState.Minimized;
}
windowPlacement.length = Marshal.SizeOf(windowPlacement);
bool test = Win32Wrapper.GetWindowPlacement(processHandle,ref windowPlacement);
if ( windowPlacement.showCmd == SHOW_STATE.SW_SHOWMINIMIZED )
{
formWindowState = FormWindowState.Minimized;
}
else if ( windowPlacement.showCmd == SHOW_STATE.SW_SHOWMAXIMIZED )
{
formWindowState = FormWindowState.Maximized;
}
}
|
|
|
|
|
Sheela Krishnan wrote:
I am trying to get the windowstate of a window based on its process id.
Below is what I tried... But the GetWindowPlacement method returns false most of the times inspite of the length of the windowplacvement object being initialized. Even if the method returns true, its showCmd is always NORMAL. While testing my window was always MAXIMIZED!
Assuming that Win32Wrapper.GetWindowPlacement() indeed does only encapsulate the native Win32 call, you're simply passing the wrong value. GetWindowPlacement()[^] expects a handle to a window, not to a process. If you're interested in the state of the main window of a process you can use the Process.MainWindowHandle Property[^] to obtain the correct handle.
Best regards
Dennis
|
|
|
|
|
Why when I deriving my own TabControl I am loosing ability to drop other controls from the toolbox on my derived tab control in design mode. Same thing if derive may PropertyPage. In MFC I was able create several dialogs in design mode than dynamicaly connect them to the PropertySheet. How to do somthing similar in C#.
Thanks
Alex.
|
|
|
|
|
Alex_Y wrote:
Why when I deriving my own TabControl I am loosing ability to drop other controls from the toolbox on my derived tab control in design mode.
Hmmm. I thought the only thing you can do with a TabControl is add TabPages. Then you can drop controls onto the TabPage.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
What if want to derive my own Pages? My question is true if deriving TabControl and/or Pages after that I can only manualy create/locate controls on the pages. Because may be I missing something. Why design mode can't handle derived classes. I could understand when control is simple like editbox on which I don't need to drop anything, but in TabControl main purpose is to hold other controls.
Thanks,
Alex.
|
|
|
|