|
Cool this has really helped me alot, i have found one sample using google search engine. Are there any others that people can point me too cause a few examples would be better
Thanks for your help anyway
|
|
|
|
|
Hi all
I am facing problem with Mobile Internet Toolkit Beta 2. After downloading it from microsoft download site, I tried to run the downloaded file "MobileIT.Exe", so that I can start developing some Mobile web application (Visual Studio.Net Beta 2 is already installed in my machine). But the exe file (MobileIT.Exe) is terminated with a message "not a valid win32 application". On second try, I wanted to run it from web page but it gave message like "Device not ready". I have Windows 2000 Advanced Server installed in my machine.
Please help.
Thanks
Kanak
|
|
|
|
|
Hi Gurus:
A Dll file was complied by VC 6.0;
The DLL exports a function :
int f(char *src, long len, char **des).
How to Call this Function in C#?
thanks in advance!
|
|
|
|
|
Dear All,
I have a COM+ Component which is coded by c# and then there is a client code in c# that call the method of that Component. However, an unhandled exception is thrown :
"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: The server process could not be started because the configured identity is incorrect. Check the username and password."
I would like to know how to solve this problem ??
marcomarco
|
|
|
|
|
Hi,
I have a composite control which contains some other controls and I want to use "event bubbling" for my winform control. Is it possible for child control to forward event to Composite control?
Any advise on this would be useful.
Thanks
|
|
|
|
|
Do you mean a child control that embedded in a composite control? Because if that's the case, it's possible to wire events such that the composite control recieves the event. Please post some code and I'll show you.
Regards
Senkwe
Just another wannabe code junky
|
|
|
|
|
Thanks for responding to my post. Unfortunately I can not post any code. I’ll try to be clearer about my question this time. I have a composite control, combination of standard control (say text box). Every time any onClick happens on this child(text box) control, I want to pass this event to parent(composite) control.
-Kasturi
|
|
|
|
|
There are a million articles online that deal with using delegates and events and these are the two topics you need to understand so you know what is going on. However, I found that most rticles are prtty poor when it comes to these topics. The article that I used to gain a good understnding i the following.
http://msdn.microsoft.com/msdnmag/issues/01/08/net/net0108.asp
I modified this code to be more generic, i.e. I have a class that works as a generic event "attacher" and "detacher". It's not that pretty though.
I don't have the code with me right now, so you'd have to wait for me to whip it up again if you have the patience. Otherwise you an read the article above and just dig in. It's well written nd ver clear at least to me. I'll still whip up that sample of mine though.
Regards
Senkwe
Just another wannabe code junky
|
|
|
|
|
Here's a sample EventsManger class. All it does is check to see if there are any listeners for registered events. As you can see it's very simple.
public class EventsManager
{
public delegate void EventHandler(Object sender);
public event EventHandler EventsHolder;
protected virtual void OnEventOccurred()
{
if(EventsHolder != null)
EventsHolder(this);
}
public void EventWasFired()
{
OnEventOccurred();
}
}
I prefer to have my entry point in a class called driver (I'm used to C++) so I declare the following...
public class driver
{
public static EventsManager em;
static void Main()
{
em = new EventsManager();
Application.Run(new Form1());
}
}
To test it, I created a user control with a button on it. i.e. a composite control. Now, I want that when I press the button, the user control back color turns red, ie, the button_click event gets bubbled up to the parent control so to speak. To make things easy, you can make your user control take an EventsManager as a constructor paramater.Then register a listener like so...
public UserControl1(EventsManager em)
{
InitializeComponent();
em.EventsHolder += new EventsManager.EventHandler(ButtonWasPressed);
}
private void ButtonWasPressed(Object sender)
{
this.BackColor = Color.Red;
}
You can then fire the event from the button's OnClick event like so
private void button1_Click(object sender, System.EventArgs e)
{
driver.em.EventWasFired();
}
You'll notice that I don't use EventArgs in my delegate declaration. I left that out because it's of no real use here. But it's advisable fro you to do this. (I typically derive a class from EventArgs and stuff it with mty own event specific code)
Well it's ugly but it works for me, hope it helps
Just another wannabe code junky
|
|
|
|
|
Does anybody know what the correct behaviour the proxy settings when using a HttpWebRequest/HttpWebResponse pairing should be?
Looking on the web I can see many articles (well a few) showing how to instruct a request to go through a proxy. The problem is, to me it already looks that way.... my programs, without abything extra, use the IE proxy settings.
I can change the proxy quite easily, but to bypass the proxies, the best I can come up with is something like this:
bool proxyDetected =
((WebProxy)GlobalProxySelection.Select).Address != null;
if ( proxyDetected && bypassProxy )
GlobalProxySelection.Select = GlobalProxySelection.GetEmptyWebProxy();
I'm confused! Everybody else seems to want to know how to use a proxy, I'm trying to find another example of someone trying to bypass a proxy! Does the above code look right?
Regards,
Ray
|
|
|
|
|
Hi folks,
what would be the best way to implement a page header (eg The Code Project's) on each page of a C# WebForm application?
Matt
------
Accept that some days you are the pigeon and some days the statue.
|
|
|
|
|
Guys,
I am having problems with the use of the CacheItemRemovedCallback event within an ASP.NET/C# website I am building. The below code is from my global.aspx file. The code loads XML/XSL objects into the Cache for later use. I also create a Cache dependency so should any files change which my XML/XSL objects use, the Cache is updated automatically. The code works only when something is removed from the Cache by another aspx file, since the code correctly identifies the HttpContext. However, when one of my files is changed and the RemovedCallback() function is fired, for some reason the Context and the HttpContext are both null. As such my code never has a chance to update the Cache again. Rather it exists "without an error" as soon as I try to use Cache.Insert. Does anyone know if this is a bug in Beta 2, or am I missing something, like the use of a special Context object?
Any help greatly appreciated..........
Cheers,
Tim.
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.Web.Caching" %>
<%@ Import Namespace="CommerceEngine.Common" %>
private static CacheItemRemovedCallback onRemove = null;
private XPathDocument CommerceListXmlObj;
private XslTransform CommerceListXslObj;
public void Application_OnStart()
{
ApplicationConfiguration.OnApplicationStart(Context.Server.MapPath( Context.Request.ApplicationPath ));
onRemove = new CacheItemRemovedCallback(this.RemovedCallback);
CommerceListXmlObj = new XPathDocument(CommerceEngineConfiguration.CommerceListXmlFilePath);
HttpContext.Current.Cache.Insert("CommerceListXmlObj", CommerceListXmlObj, new CacheDependency (CommerceEngineConfiguration.CommerceListXmlFilePath), DateTime.Now.AddHours(1), TimeSpan.Zero, CacheItemPriority.Default, CacheItemPriorityDecay.Slow, onRemove );
CommerceListXslObj = new XslTransform();
CommerceListXslObj.Load(CommerceEngineConfiguration.CommerceListXslFilePath);
HttpContext.Current.Cache.Insert("CommerceListXslObj", CommerceListXslObj, new CacheDependency(CommerceEngineConfiguration.CommerceListXslFilePath), DateTime.Now.AddHours(1), TimeSpan.Zero, CacheItemPriority.Default, CacheItemPriorityDecay.Slow, onRemove );
}
public void RemovedCallback(String k, Object v, CacheItemRemovedReason r)
{
switch(k)
{
case "CommerceListXmlObj" :
CommerceListXmlObj = new XPathDocument(CommerceEngineConfiguration.CommerceListXmlFilePath);
HttpContext.Current.Cache.Insert("CommerceListXmlObj", CommerceListXmlObj, new CacheDependency(CommerceEngineConfiguration.CommerceListXmlFilePath), DateTime.Now.AddHours(1), TimeSpan.Zero, CacheItemPriority.Default, CacheItemPriorityDecay.Slow, onRemove );
break;
}
}
|
|
|
|
|
I know this is beginner-level, but how can I write a console app with Visual Studio, run the app and have the output redirected to the Visual Studio output window? If I can't do that, is there another means of pausing the application without calling a getchar() type function?
bye bye,
KLC
|
|
|
|
|
You can use the trace functions to get your text to the output window.
System.Diagnostics.Trace
I don't think there is one-line method of changing all System.Console.WriteLine's to use the output window.
But you could write a class that implements/extends System.IO.TextWriter (using the Trace class as your backend) then use System.Console.SetOut, passing in an instance of your new class.
HTH,
James
Sonork ID: 100.11138 - Hasaki
|
|
|
|
|
Thanks James, but both methods requires a lot of changing of code that doesn't need to be changed. I was hoping for at least a way in Visual Studio to route all Writelines to the output window. Oh well.
Thanks anyway.
bye bye,
KLC
|
|
|
|
|
I didn't look into it too much when I replied (was busy putting the finishing touches on an article).
Here's a class that'll do what you want
using System;
using System.Diagnostics;
namespace ConsoleRerouter
{
public class OutputToTrace : System.IO.TextWriter
{
public OutputToTrace()
{
}
public override void Write(char c)
{
Trace.Write(c, "Console");
}
public override void WriteLine(string line)
{
Trace.WriteLine(line, "Console");
}
private System.Text.Encoding enc = new System.Text.ASCIIEncoding();
public override System.Text.Encoding Encoding
{
get
{
return enc;
}
}
}
}
If you do anything really vigorous you'll have to add more calls to Trace.Write/WriteLine, but it'll do the deed as it is right now.
Use it like
System.Console.SetOut(new ConsoleRerouter.OutputToTrace());
It worked great in my simple test (output everything that was typed in)
Enjoy,
James
Sonork ID: 100.11138 - Hasaki
|
|
|
|
|
Run the program by pressing CTRL+F5. The command-line window will request you to press a key before terminating.
|
|
|
|
|
Hi guys...here's my problem. I have created a viual control called a TilePlaceControl. I have added many of these to a panel control on a form.
Now, I can access any control containedby the panel in this way...
myPanel.Controls[x] where x is the 0 based index of the control previously added. The problem is, that snippet of code as it stands returns (and rightly so) a generic Sytem.Forms.Control object.
My problem is that I need to change an aspect of the TilePlaceControl actually contained within the panel...for example, I need to do something like this...
myPanel.Controls[x].MyMethod(...)
So then, why can I NOT do this?
(TilePlaceControl)myPanel.Controls[x].MyMethod(...)
The compiler complains saying that MyMethod is not a member of System.Forms.Control.
I wouldn't mind so much if I could simply do the following...
TilePlaceControl tpc = (TilePlaceControl)myPanel.Controls[x];
tpc.MyMethod(...)
myPanel.Controls[x] = tpc;
But I can't because Controls[x] is a READ ONLY indexer.
Please guys give me a way around this, the other alternative is just way too ugly to even contemplate
Regards,
Senkwe
Just another wannabe code junky
|
|
|
|
|
Senkwe Chanda wrote:
(TilePlaceControl)myPanel.Controls[x].MyMethod(...)
Almost have it!
((TilePlaceControl)myPanel.Controls[x]).MyMethod(...)
That will give you what you want
[Note the extra set of parenthesis]
Senkwe Chanda wrote:
TilePlaceControl tpc = (TilePlaceControl)myPanel.Controls[x];
tpc.MyMethod(...)
myPanel.Controls[x] = tpc;
So close, yet again You shouldn't have to assign back into the collection unless you actually want to change the instance in the collection in which case you should do a Controls.Remove and Controls.Add.
The code below should work, and give you the results you expect, as will the code at the top.
TilePlaceControl tpc = (TilePlaceControl)myPanel.Controls[x];<br />
tpc.MyMethod(...)
James
Sonork ID: 100.11138 - Hasaki
|
|
|
|
|
Thanks alot James, your first code snippet works great and is even clear now that I see it in black and white.
As for your last piece of code
TilePlaceControl tpc = (TilePlaceControl)myPanel.Controls[x];
tpc.MyMethod(...)
I thought of that but then thought that
TilePlaceControl tpc = (TilePlaceControl)myPanel.Controls[x];
creates a seperate instance of the object and hence, tpc.MyMethod(...) would still not be called on the instance contained by the panel.
But I'll explore that again.
Thanks alot!!
Regards
Senkwe
Just another wannabe code junky
|
|
|
|
|
Senkwe Chanda wrote:
I thought of that but then thought that
TilePlaceControl tpc = (TilePlaceControl)myPanel.Controls[x];
creates a seperate instance of the object and hence, tpc.MyMethod(...) would still not be called on the instance contained by the panel.
Nope, tpc is only a reference to the object. A reference is similar to a pointer in C/C++ and ByRef in VB; anything you do to the reference (except assignment) will carry through to the actual instance.
Assignment on a reference only makes the reference refer/point to something else, leaving the original intact.
The only way to create a new instance is via the new keyword or through reflection's Activator.CreateInstance, neither of which you show here
James
Sonork ID: 100.11138 - Hasaki
|
|
|
|
|
What is the equivalent of VB's "InStr" function in C#?
|
|
|
|
|
use the IndexOf method on your string object.
int instr = myString.IndexOf("moo", 0);
There are 5 other overloads that you can use as well, 3 to find a string, 3 to find a char.
James
Sonork ID: 100.11138 - Hasaki
|
|
|
|
|
Hello,
I need some information on where to find and obtain a drives attributes, e.g, ROM_DRIVE or FLOPPY_DRIVE etc and other attributes pertaining to the drive. I've searched the MSDN library and other places to no avail. I've tried using Environment but can't get anything. Any insight would greatly be appreciated.
Thanks
|
|
|
|
|
Any sample on using CreateWindow API from c# ? I’m aware of “MessageBox” sample on MSDN but I’ve no idea on how to retrieve HWND of Form and Instance handle. I’m trying to put together code to use virtual listview. virtual listview is available in SDK not with .Net. Any idea would be truly appreciated.
Thanks
|
|
|
|