|
I have a word search program.
Each letter in a UserControl.
I want to draw with GDI over the controls to circle words and what not.
Any ideas or links.
Nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Simply use this.CreateGraphics.(any method you want);
is will be helpful to you,if that is what i exepect
|
|
|
|
|
actually its a bad idea to just create a graphics object. muck like putting an include directive on every file in an MFC application. It upsets the architecture in place.
But I cant draw over the controls still.
my existing code is:
public void frmMain_Paint( object sender, System.Windows.Forms.PaintEventArgs e )
{
//e.Graphics.FillRectangle(new Pen(Brushes.AliceBlue, 2), 50,50,800,800);
e.Graphics.FillRectangle(Brushes.Aqua, 50,50,800,800);
}
which accomplishes the same thing.
But, alas it still doesnt work. I know GDI and directx. Its not the issue,itsw how I either make the control transparent or find a way to bring the grahics to the top.
Nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
But, alas it still doesnt work. I know GDI and directx. Its not the issue,itsw how I either make the control transparent or find a way to bring the grahics to the top.
yeah I tried this before ,
just make the FillRectangle(Brushes.FromArgb(128,Color.Aqua));
as this number stands to the transparency.
|
|
|
|
|
thanks man
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
:->
|
|
|
|
|
Here's my code:
<br />
foreach(GameRoom gr in Room)<br />
{<br />
if (gr.Name.ToLower() == Name.ToLower())<br />
{<br />
return "roomexists";<br />
}<br />
}<br />
"Room" is a hashtable of GameRoom objects. "gr.Name" and "Name" are string values. When this routine is run, and there are more than zero elements in the Room hashtable, I get an Invalid Cast Exception. Being an intermediate programmer, I'm not sure what that means, or exactly why it's being caused.
Any insights?
Thanks for your help.
|
|
|
|
|
foreach in C# compiles to using a collections IEnumerable implementation, where IEnumeration.Current returns an object that (hopefully) casts correctly to whatever type you specify. With a Hashtable , however, foreach compiles to use the Hashtable.GetEnumerator method which returns an IDictionaryEnumerator , where IDictionaryEnumerator.Current returns an IDictionaryEntry , not object . Depending on whether your Game object exists in the key or value of the hashtable, you use IDictionaryEntry.Key or IDictionaryEntry.Value and cast that to your GameRoom type.
You can also use foreach (GameRoom gr in Room.Keys) or foreach (GameRoom gr in Room.Values ) depending on whether your object is in the key or value of the hashtable.
I must say you're going about this wrong, however. The reason for using a hashtable is fast lookups, typically on the order of O(1), where your enumeration will be O(n), which is much slower.
For each GameRoom , you should add it and the name with the name as the key and the GameRoom as the value. If you use a case-insentive hash code provider and comparer, you don't have to worry about casing, like in the following example:
Hashtable rooms = new Hashtable(
new CaseInsensitiveHashCodeProvider(),
new CaseInsensitiveComparer();
rooms.Add(gr1.Name, gr1);
rooms.Add(gr2.Name, gr2); Now when you need to get a specific GameRoom , just do something like this:
return rooms["GameRoom1"] as GameRoom; If you want to see if the GameRoom exists, use Hashtable.Contains("GameRoom1") , which is an O(1) operation since it uses the hash code of the name to find the key immediately if available.
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 meant to add that you can learn a lot about your assemblies - and solve problems like this - by using ildasm.exe that ships with the .NET Framework SDK, which is installed by default with Visual Studio and downloadable separately from http://msdn.microsoft.com/netframework[^]. Finding the method in the tree and looking at the implementation would've reveals something like the following example I threw together quickly (does nothing):
.method private hidebysig instance void Example() cil managed
{
.maxstack 2
.locals init (valuetype [mscorlib]System.Collections.DictionaryEntry V_0,
class [mscorlib]System.Collections.IDictionaryEnumerator V_1,
class [mscorlib]System.IDisposable V_2)
IL_0000: ldarg.0
IL_0001: ldfld class [mscorlib]System.Collections.Hashtable Test::table
"color: rgba(255, 0, 0, 1)"> IL_0006: callvirt instance class [mscorlib]System.Collections.IDictionaryEnumerator [mscorlib]System.Collections.Hashtable::GetEnumerator()
IL_000b: stloc.1
.try
{
IL_000c: br.s IL_0029
IL_000e: ldloc.1
"color: rgba(255, 0, 0, 1)"> IL_000f: callvirt instance object [mscorlib]System.Collections.IEnumerator::get_Current()
IL_0014: unbox [mscorlib]System.Collections.DictionaryEntry
IL_0019: ldobj [mscorlib]System.Collections.DictionaryEntry
IL_001e: stloc.0
IL_001f: ldstr "test"
IL_0024: call void [mscorlib]System.Console::WriteLine(string)
IL_0029: ldloc.1
IL_002a: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext()
IL_002f: brtrue.s IL_000e
IL_0031: leave.s IL_0044
}
finally
{
IL_0033: ldloc.1
IL_0034: isinst [mscorlib]System.IDisposable
IL_0039: stloc.2
IL_003a: ldloc.2
IL_003b: brfalse.s IL_0043
IL_003d: ldloc.2
IL_003e: callvirt instance void [mscorlib]System.IDisposable::Dispose()
IL_0043: endfinally
}
IL_0044: ret
} This may look difficult at first, but you learn over time (just like programming).
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]
|
|
|
|
|
Most helpful, thank you. It's hard to overstate how beneficial people like you are to us frustrated, fledgling programmers.
|
|
|
|
|
I used the following code to view report.when i view more than 1000 records,crystal viewer look like hand.speed is very slow.How can i improve the method.who can help me?
Pls..
string exeDirectory = Path.GetDirectoryName(Application.ExecutablePath)+@"\Reports\";
ReportDocument rptAll = new ReportDocument();
rptAll.Load(exeDirectory+"GLTaxSum.rpt");
TableLogOnInfo logOnInfo;
ConnectionInfo connectionInfo;
for(int i=0;i
|
|
|
|
|
Does anyone have a way that I can use the "DefineDynamicAssembly" method to create an assembly in a secondary domain so the dynamic assemblies can be unloaded?
Any other methods would be fine also. I just need to run executable code compiled from OpCodes but the problem is, the OpCodes will be compiled many times and the only method I know to do this is to create dynamic assemblies but then I can never unload the assemblies (obviously since they are in the primary AppDomain).
Thanks for any help
|
|
|
|
|
You can call AppDomain.DefineDynamicAssembly on a different AppDomain that is not your current domain, but a problem - a potential security hole, even, if you don't check your domain locations - could result.
From the .NET Framework SDK, pointed to by the documentation[^] for AppDomain.DefineDynamicAssembly :An attempt to call Load on a target application domain that is not the current application domain will result in a successful load of the assembly in the target application domain. Since an Assembly is not MarshalByRefObject, when this method attempts to return the Assembly for the loaded assembly to the current application domain, the common language runtime will try to load the assembly into the current application domain and the load might fail. The assembly that is loaded into the current application domain might be different from the assembly that was loaded first if the path settings for the two application domains are different.
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 for the reply Heath.
I have tried to call "DefineDynamicAssembly" on a secondary AppDomain but I always get a SerializationException. Basically says AssemblyBuilder is not marked as Serializable. I'm guessing that might have something to do with the AppDomainSetup of my new AppDomain. Would could solve that problem?
As for the Load function mentioned above, I dont believe I could use that because I need to generate the compiled code with an AssemblyBuilder, ModuleBuilder, MethodBuilder, etc, and I believe DefineDynamicAssembly is the only way to initialize the AssemblyBuilder to compile OpCodes.
|
|
|
|
|
That's to be expected, based on the quote I posted. The reflection-related classes are not MarshalByRefObject implementation and are not serializable so they cannot be remoted across AppDomain boundaries. In the case of Assembly.Load (from where that quote was taken) an Assembly could be returned, but it will cause the assembly you load to be re-loaded into the current AppDomain . In your case, since you're defining a dynamic assembly there is no assembly to return.
As the exception states, too, AssemblyBuilder is not serializable, just like an Assembly reference you're trying to create.
In short, this isn't really possible doing it like you're trying to do.
That's not to say there isn't a way, however. Create an assembly factory class that is remotable (extends MarshalByRefObject and is attributed with SerializableAttribute and load that into a new AppDomain , then make remoted calls on it in order to create a dynamic assembly. Since the factory exists in the new AppDomain , when it calls DefineDynamicAssembly in will be in the scope of the new AppDomain .
Read Accessing Objects in Other Application Domains Using .NET Remoting[^] for more abour remoting. .NET provides a remoting channel for specifically communicating between AppDomain s in the same process, so you do not want to specify a TcpChannel or HttpChannel like you'd use to communicate between two disparate processes, potentially on two different machines.
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]
|
|
|
|
|
Ok, thanks a lot for the help Heath. That method should work
|
|
|
|
|
Hi,
I've got a "Manager" class which, whitin it's own declaration, has another class declared: "ItemCollection". I'd like to be able to instanciate an ItemCollection class inside the Manager class and make it from outside accessible as a return value for a function. But I don't want that any code outside the Manager class can instanciate the ItemCollection.
How would I go about this? Thanks in advance.
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
|
You could also provide "outside" access to this ItemCollection class via a public interface (implemented by ItemCollection) which you pass back to a caller from your function
Phil Harding. myBlog [^] | mySite [^]
|
|
|
|
|
Hello,
I need to access a frame (filling inputs, reading data, etc.) in an activeX webbrowser.
ie: an html page embeds 2 frames, one on the same domain (no probs using this frame), and the other that refers a page on another domain.
The problem is that IE component doesnt allow access to a frame (read and more) that is not in the same domain as the parent window.
A friend success to access this kind of frame using Delphi, but I wonder if there is a way to do the same using C#.
Regards.
|
|
|
|
|
Are you using JavaScript/JScript or VBScript to do this in a web page? Cross-site scripting is there for a reason, and this question wouldn't have anything to do with C# or .NET, so please refer your question to the Web Development[^] forum.
C# won't simply solve your problem if you're talking about a client scenario only. An ActiveX control or embedded Windows Forms control could possibly access the other frame through a few methods, but if you try to use the MSHTML DOM (document object model) to do this then no language will help since those calls - the very same calls that scripts automate - will be blocked by the implementation, which is implemented by mshtml.dll (the MSHTML DOM).
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 am not using any scripts in the web page. I am just trying to fill some form inputs using MSHTML ActiveX, but the MSHTML component doesnt let me access a frame outside the domain of the parent web page.
So I'm looking for another way to access the frames objects. Any ideas ?
|
|
|
|
|
Could you please provide more information about what you're doing? Are you interoperating with the WebBrowser control in a Windows Forms application? Please be specific.
As I mentioned in my previous post, if you use the methods of the MSHTML DOM objects - no matter if done through JScript, VBScript, C#, C++, etc. - they will block against cross-site scripting. This is intentional and is implemented in the MSHTML DOM itself, so there's no way around it using the MSHTML DOM methods.
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]
|
|
|
|
|
At this moment using MSHTML works perfectly (in the same domain), I know that cross-frame scripting is restricted using MSHTML.
I am using the ActiveX axWebBrowser object to embed a webbrowser in my app. But in some case, web pages embeds frame out of the parent domain. So I am stuck if I want (for exemple) to login on external website, due to cross-frame scripting restrictions.
So I wonder if there is a way to do this in C#... My friend that did the thing in Delphi seems to get the main webbrowser document id in an OleContainer then enumerate objects in this container, after he cast back the OleObject to a IHTMLWindow and access the frame without any restrictions.
Here is the link where he find the solution in Delphi (unfortunaly he doesnt know what he does, but use the code as it):
http://www.swissdelphicenter.ch/torry/showcode.php?id=2054
|
|
|
|
|
Okay, not that I know what you're trying to do and how you're using the WebBrowser control it makes more sense.
You can do the same thing, but those interfaces your friends is using aren't defined in the .NET Framework class libraries. You have to either create an interop assembly, or write your own interfaces with the right method signatures and GUIDs (using the GuidAttribute ) and the ComImportAttribute that match up to the native interfaces like IOleObject .
This can be a daunting task, however. First, please read Exposing COM Components to the .NET Framework[^]. It's imperative that you understand COM interoperability in .NET. You'll also need to these interfaces in managed code so that the CLR will marshal calls from your managed code to native code (the COM implementation).
Fortunately, there's a relatively easy way since defining these interfaces by hand would take a long time and require quite a bit of experience with marshaling the various data structures and interfaces required.
Make an IDL file that forward-declares the interfaces you need, run the IDL file through midl.exe, then run the resulting typelib (.tlb file) through tlbimp.exe. midl.exe is the Microsoft IDL compiler that ships with the Platform SDK and Visual Studio .NET, and tlbimp.exe is the Type Library Importer that ships with the .NET Framework SDK, which is installed by default with Visual Studio .NET as well.
For an example of how this is done, read Using MSHTML Advanced Hosting Interfaces[^] where Nikhil uses the technique above to creating an interop assembly (that contains interop interfaces and enumerations and structure required to call them) for the MSHTML and WebBrowser hosting interfaces.
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]
|
|
|
|
|