|
It's possible I open OpenFileDialog with Windows Impersonation, which show map drives network user impersonated.
Thanks!
|
|
|
|
|
|
Hi friends.
I want to know how I can handle any press keys in my C# form?
Thanks.
Sorry for my English. I'm a freshman .
|
|
|
|
|
look at the events for your form. In particular, you want to look at the following events:
Hope this helps.
dimaj
|
|
|
|
|
I did it, but it doesn't work
Sorry for my English. I'm a freshman .
|
|
|
|
|
Sorry, for some reason my previous message got cropped... Events that I meant originally were KeyUp, KeyDown and KeyPress
dimaj
|
|
|
|
|
With the key press event. What keys are you having trouble with ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
If you want to handle key press before it reaches controls set KeyPreview property to true.
If you want to handle key presses even when your form doesn't have focus you will need global keyboard hook. There are several articles about it here at codeproject.
Happy searching.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Thanks guys.
Sorry for my English. I'm a freshman .
|
|
|
|
|
Hello all!
I'm trying to write a little application in C# which will call a method/property of an object on another application. So, for example, I have an application A, which has a Text Box and I want to write an application B which will print out contents of the Text Box on application A.
I was trying to mess around with AppDomain and Assembly, but, unfortunately, I didn't get very far.
Could anybody give me a hint of where to begin?
Thanks in advance for your help.
dimaj
|
|
|
|
|
|
Hello Mike!
Thanks for a quick reply. I can't say that Inter-Process communications would do the trick for me here. I was hoping to accomplish it by using Reflection.
My original inspiration to do this was UI Automation framework, but I got stuck almost immediately because our company uses a lot of 3rd party controls and UI Automation does some basic wrapper around controls that it sees. Plus, you cannot completely control the object you are looking at (but that's a different story). Anyhow, I found this application hawkeye[^]. This little app can identify object type and invoke different methods/events... I'm trying to achieve the same thing here.
Thanks again.
dimaj
|
|
|
|
|
dimaj wrote: Anyhow, I found this application hawkeye[^]. This little app can identify object type and invoke different methods/events... I'm trying to achieve the same thing here.
Then why don't you just use the code from that project?[^]
led mike
|
|
|
|
|
I've been trying to read that code, but I'm not getting anywhere with it. I've been debugging it hoping to see something that would do the trick for me, but it doesn't work per design when you debug it. Only when you actually run the code without interruptions it does the trick.
Maybe I'm doing something wrong...
dimaj
|
|
|
|
|
Are you writing both apps ? If not, you have to find the window and get it's text.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello Christian!
I'm writing the "application B", "application A" is being developed by somebody else.
If I am not mistaken, I can use some Windows API to find the window id of the object I'm interested in. I can definitely get the window ID of the parent window (using Process class) and then drill my way down.
Thanks.
dimaj
|
|
|
|
|
Yes, you can get the top window and search from there. It's messy, but it can be done.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
There's also an API called something like 'windowfrompoint' if you can ask your user to click on the window you want to find.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian,
OK, thanks! I'll look into that call too.
So, is there a way to get and "grip" on the object (so that I could use Reflection on it) based on a window handle?
Thanks.
dimaj
|
|
|
|
|
I came across this error in my code that I cannot fix:
A field initializer cannot reference the non-static field, method, or property 'ConsoleApplication.Polygon.colorValues'
So extracted what I thought was the relevant part of the code to post and ask for help. The problem is that now this simplified code works . But I cannot find the problem in the original, full-length code.
Since the original code is too long to post here, I was hoping I could post the "working" code here with the error. Maybe someone could tell me at least what to look for.
This is my working code.
The code creates a class with two fields. Both fields are enumerations...
using System;
namespace ConsoleApplication
{
class Program
{
enum ColorType {Red, Green, Blue, Yellow};
enum ShapeType {Square, Circle, Triangle};
class Polygon
{
public ColorType Color { get; set; }
public ShapeType Shape { get; set; }
private Polygon() { }
public Polygon(ColorType color, ShapeType shape)
{
Color = color;
Shape = shape;
}
}
The code then tries to create an array of these classes. The elements of the array contain each possible combination of the enumerations. To do that, I use Enum.GetValues() to get an array of possible enum values and use the Array.Length property to figure out the size of the array I will need to hold all the combinations.
static void Main(string[] args)
{
Array colorValues = Enum.GetValues(typeof(ColorType));
Array shapeValues = Enum.GetValues(typeof(ShapeType));
Polygon[] allPolygons = new Polygon[<code>colorValues</code>.Length * <code>shapeValues</code>.Length];
int index = 0;
foreach (ColorType color in colorValues)
{
foreach (ShapeType shape in shapeValues)
{
allPolygons[index] = new Polygon(color, shape);
Console.WriteLine(allPolygons[index]);
index++;
}
}
}
}
}
I underlined the portion (above) that is generating the error:
A field initializer cannot reference the non-static field, method, or property 'ConsoleApplication.Polygon.colorValues' .
Unfortunately, this code works but the real code doesn't. Can someone help me interpret what the compiler might be having a problem with so I know what to look for?
Thanks.
|
|
|
|
|
Your code works probably because you moved initialization of colorValues inside Main . Your original code probaly initialized them as part of the field declaration, like
class Program
{
Array colorValues = Enum.GetValues(typeof(ColorType));
Polygon[] allPolygons = new Polygon[colorValues.Length * shapeValues.Length];
}
That doesn't work - instance field initializers cannot refer to other instance field initializers. That means that you cannot refer to colorValues from any other instance field initializer.
The typical solution is to move the initialization code to the constructor of the class.
|
|
|
|
|
S. Senthil Kumar wrote: The typical solution is to move the initialization code to the constructor of the class.
Cool. Moving the initialization of colorValues, shapeValues, and allPolygons to the constructor worked. Thanks.
I think the full code design is "cleaner" when I declare the colorValues/shapeValues arrays as static (as mentioned below).
Thank you everyone.
|
|
|
|
|
Okay, I think it is the "cannot reference the non-static" part of the error which is relevant.
If I move the Main() code into a class:
class MyClass
{
Array colorValues = Enum.GetValues(typeof(ColorType));
Array shapeValues = Enum.GetValues(typeof(ShapeType));
Polygon[] allPolygons = new Polygon[colorValues.Length * shapeValues.Length];
public MyClass()
{
int index = 0;
foreach (ColorType color in colorValues)
{
foreach (ShapeType shape in shapeValues)
{
allPolygons[index] = new Polygon(color, shape);
Console.WriteLine(allPolygons[index]);
index++;
}
}
}
}
...and call it from Main()
static void Main(string[] args)
{
MyClass myClass = new MyClass();
}
I get the error. But how do I work around that? How would I create the private allPolygons array? What am I actually doing wrong?
|
|
|
|
|
ssclaire wrote: Array colorValues = Enum.GetValues(typeof(ColorType)); Array shapeValues = Enum.GetValues(typeof(ShapeType)); Polygon[] allPolygons = new Polygon[colorValues.Length * shapeValues.Length];
Seems to me like these should be static anyhow, they don't change between instances, right ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Just move the code to the constructor and you'll be fine
class MyClass
{
Array colorValues = Enum.GetValues(typeof(ColorType));
Array shapeValues = Enum.GetValues(typeof(ShapeType));
Polygon[] allPolygons;
public MyClass()
{
allPolygons = = new Polygon[colorValues.Length * shapeValues.Length];
...
}
}
|
|
|
|