|
I have an windows Application , which has a grid in the inner most child window. But I fail to find the handle of the controls placed inside this child window. How can I scarpe such controls . Please help .
|
|
|
|
|
Show us what you tried - we have no idea how you organised stuff (or even exactly what you are trying to do!)
Code fragments help us understand: so give us the way you load the grid (and exactly what kind of grid it is), and the code you tried to "scrape" the controls.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
And, please include your explanation of exactly what "scrape" means in this context; we most often encounter the term "scrape" in the context of selecting content from a web-page.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
If you got source code or are using reflection:
Child controls of Windows Forms windows can be accessed via the .Controls property (of the window).
"Content" of a WPF Window can be accessed via the .Content property.
|
|
|
|
|
If there's no handle, it might not be a control; it may be simply drawn by the application itself.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
What type of "windows application" do you have? Is it a .Net Windows Forms application, a WPF application, an old style C++ application, a Java application with Ant or Swing, ...?
Some of them do not use Windows controls for all purposes, sometimes they use them for underlying containers only (Swing, WPF), and then the inner "controls" do not have a handle.
|
|
|
|
|
Hi there !
All of my Form in my Application Connect to the Database by a Class for e.g. : myClass , but I want my class read Connection String from a Text File or a ini File . plz help me How Can I do it ?
Thanks in Advance!
|
|
|
|
|
For a Text file, it's trivial:
string strConnect = File.ReadAllText(pathToTextFile);
But a better way is to use the built in settings: Using Application Settings and User Settings[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks ,
Is it possible to use a Connection String by AttachDbFilename for SQL Sever(not for SQLExpress)
thanks...
|
|
|
|
|
No.
Attaching is a special "developer mode" which starts a new instance of SQL server to handle that specific database and no other.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hello,
I have a requirement of triggering my application on Ctrl+d only when user is in Windows Explorer. For that I have an ahk script which works perfectly..
#IfWinActive ahk_class CabinetWClass
^d::
Run "C:\myapp.exe"
return
#IfWinActive ; turn off context sensitivity
But I want implement the same in C#, While searching I came to know that this can be done using Autohotkey.dll from this site But no where I got any working dll.
How to achieve in my requirement in c# ?
I got a project which gets the keyboard entries when it is in foreground but how to catch the keyboard entries of other window (In my case Windows Explorer) while my app is running in background?
Please help.
|
|
|
|
|
You can see an answer on how to use RegisterHotKey here[^].
Inside the handler you would have to get the currently active window handle using GetForegroundWindow function (Windows)[^]. You then pass that handle to the GetWindowThreadProcessId function (Windows)[^] to get the Process ID (PID) of the window. Compare that to the list of Process ID's you can get from the Process class and make sure the process name is "Explorer.exe". If there's a match, do whatever you need to do.
|
|
|
|
|
hello..
my question is :: how to store MAC address at installation time of exe in C#(visual studio 2010)
|
|
|
|
|
Getting the MAC is pretty simple: Retrieving IP and MAC addresses for a LAN[^] has the code (search for GetMacAddress).
Storing it isn't difficult either. If you save it in a "sensible place" under a folder whose name is the application Guid in a file you can read: Where should I store my data?[^] shows the code.
The PhysicalAddress Class (System.Net.NetworkInformation)[^] has both ToString and Parse methods which help you store it.
But...If this is as a anti-piracy method, it's not that good. MAC addresses are easy to spoof, and you will probably annoy more legitimate users than dissuade thieves.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Is it possible to change the url of a winform webbrowser through an external c#.net application? Basically I'd like to pick a button in one application, and have it start the exe for the other and navigate it to the correct url
|
|
|
|
|
You can pass command line arguments to the .exe
Snaffled from SO with this search[^]
static void Main(string[] args)
{
for (int i = 0; i < args.Length; i++) {
Console.WriteLine("args[{0}] == {1}", i, args[i]);
}
}
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank you, it's what I needed
|
|
|
|
|
edit based on Alan's suggestion below:
What I am looking for is a way to convert the Interface (non-generic Interface) instances ... where the instance is a generic Class ... from the Interface instance to the generic Class instance ... using Reflection, rather than using "world-knowldege" of the specifically defined generic Class parameter Types being used at run-time.
I think, at this point, since that use-case is pretty much what System.Dynamic enables through late-binding that, perhaps, it's better to go ahead snd use System.Dynamic. ... But, I'm not sure. Remember, if I weren't confused, I would not be here
... end edit ...
assuming:
1. an Interface which is not generic
public interface ISomeInterface
{
int SomeInt { set; get; }
} 2. a Class which is generic which inherits from the Interface
public class SomeClass<T> : ISomeInterface
{
public int SomeInt { set; get; }
public T SomeT { set; get; }
public SomeClass(int anint, T somet = default(T))
{
SomeInt = anint;
SomeT = somet;
}
} 3. A collection of instances of SomeClass<T> as ISomeInterface
List<ISomeInterface> someInstances = new List<ISomeInterface>();
someInstances.Add(new SomeClass<int>(100, 200));
someInstances.Add(new SomeClass<string>(200, "whoop de doo")); 4. at run-time you have a reference to a member of the 'someInstances list:
ISomeInterface reference = someInstances[1]; 5. to detect which generic Type 'reference is:
Type t = reference.GetType().GenericTypeArguments[0];
if (t == typeof(string))
{
var refAsString = reference as SomeClass<string>;
string whoopee = refAsString.SomeT;
} 6. is there a better way ... assuming you have a valid need to maintain such a collection of Interface instances and de-reference them into their generic Types at run-time.
Notes:
1. I don't really like doing things this way ... using reflection ... but, I do have a case where either I need to do this, or use System.Dynamic to get away with "Type murder"
2. I am aware of the use of 'Convert.ChangeType, and its limitations, and I believe it is not usable in this case because you need to know what Type to cast to in order to use it. Of course, when your generic parameter is a complex Type, you can't use the 'ChangType method that relies on 'TypeCode.
3. the code example shown here is, of course, simplified for discussion purposes; in practice the generic parameter T may hold references to any object, Class, Struct, etc.
... edit ...
Another way I have experimented with this scenario is to add a Property of Type 'Type to the Interface:
public interface ISomeInterface
{
int SomeInt { set; get; }
Type ThisType { set; get; }
} Which is set in the ctor of the Class:
public SomeClass(int anint, T somet = default(T))
{
SomeInt = anint;
SomeT = somet;
ThisType = typeof(T);
} Which results in de-referencing code like this:
if (someClassInstance.ThisType == typeof(SomeComplexClass))
{
var nativeTypedSomeClass = someClassInstance as SomeClass<SomeComplexClass>;
} That's getting close to the solution that Alan proposed below.
... end edit ...
thanks for your response !
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
modified 30-May-16 8:37am.
|
|
|
|
|
I'm not sure I understand the reason for the complexity. The final code fragment shows the use of the 'as' operator to perform a cast, implying that the type is known at compile time. If in fact all types are known then why use reflection at all, just go with is or as.
public void CastingCouch() {
List<ISomeInterface> someInstances = new List<ISomeInterface>();
someInstances.Add(new SomeClass<int>(100, 200));
someInstances.Add(new SomeClass<string>(200, "whoop de doo"));
someInstances.Add(new SomeClass<DateTime>(300, DateTime.Now));
foreach (ISomeInterface reference in someInstances) {
Console.Write("{0} ", reference.GetType());
if (reference is SomeClass<string>) {
Console.WriteLine("String");
} else if (reference is SomeClass<int>) {
Console.WriteLine("Int");
} else {
Console.WriteLine("Don't know");
}
}
}
Alan.
|
|
|
|
|
Alan, thanks for your suggestion ! I've edited my question to, I hope, more accurately show what I am looking for.
In many cases, what you propose is all that one needs; you could just as well have a Switch statement based on the Type Name to differentialy call whatever code you wanted based on Type at run-time.
However, in this case, there may be an unknown variety of instances using different generic Types because a 3rd. party is using the library. And, I am interested in seeing how one would achieve this, at minimal "cost."
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
modified 30-May-16 14:43pm.
|
|
|
|
|
If you don't have a list of "known" types, how are you planning to use the "dereferenced" type? There's nothing you can cast it to other than object , which doesn't really give you anything interesting to play with.
Also, you existing code in #5 won't work if someone implements your interface in a different class:
class SomeOtherClass : ISomeInterface { ... }
class YetAnotherClass<TKey, TValue> : ISomeInterface { ... }
someInstances.Add(new SomeOtherClass(42));
someInstances.Add(new YetAnotherClass<NotTheTypeYoureLookingFor, TheDroids>());
You'd need more checks to ensure it's the expected type:
Type referenceType = reference.GetType();
if (referenceType.IsGenericType && referenceType.GetGenericTypeDefinition == typeof(SomeClass<>))
{
Type t = referenceType.GetGenericArguments()[0];
...
}
else
{
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Please provide the complete code if possible. That would be of great help.
Note:I am currently using Visual Studio 2012 and Excel 2013.
|
|
|
|
|
|
As Richard says, we are not a code-to-order service.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.
But be aware: you get what you pay for. Pay peanuts, get monkeys.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|