|
Hello!
I wonder if there is a way to access the properties of the controls of another application's forms at runtime...
For example, i want my application to monitor wether a checkbox on another application's form has or has not been checked.
A non-.NET solution would also be useful.
If anyone has ideas, please reply!
10x!
|
|
|
|
|
You're likely looking at using Win32 API P/Invoked calls to FindWindow and GetWindowLong . How comfortable are you with the old APIs?
Jeremy Kimball
I have traveled the gutters, lo these many days, with no signs of life. Well met.
-brianwelsch
|
|
|
|
|
There is no easy way of doing this and no support it in the .NET BCL. Like Jeremy said, "How comfortable are you with the Win32 API?" You'll need to have an in depth knowledge of how windows and controls work and how to pass messages to these windows to get information back from them.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have made some 'research' based on Jeremy's suggestions and, indeed, there is no easy way to do that since I'm not very familiar with the Win32 API. I guess i'll wait for future managed implementations..
Thanks anyway!
|
|
|
|
|
Not likely going to happen. What you want to do is difficult because most of the time you have to write custom code to even find the window your looking for, then not all windows are going to expose their properties the same way. Some you can get through send message back and forth, others you have to cast a point to the Win32 Class (not the .NET Framework class!) to get at the properties.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
My problem: i have this table, with about 10 to 20 thousand records; applying a rowfilter on a dataview for this table works kind of nice; the thing is that when I have no records matching the given criteria, applying the filter takes way too long (and speed for my program is quite important). I also tried "cheating" (find/rowstatefilter = none), but it seems applying the rowStateFilter lasts about as long as applying the filter. Does anyone have any ideas?
Thx
|
|
|
|
|
Filter it on the database server - that is what it is good at.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
create some index in your software with keyedlist or some array, it demand more memory, but increase speed.
|
|
|
|
|
I agree with Colin, write your SQL so it does the filtering depending on a parameter passed into the stored procedure. There is no reason for you to be passing tens of thousands of records to a client that will only display 10-20 records on the screen at any one time. You might also want to include paging support in the SQL and the Datagrid.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi ,
I want to paint or we can say give the color to the particular row of the datagrid....when....the template column is clicked....so i want to give the backcolor to the entire row at that time....
In datagird I have a one column which is a template column...
Can anybody help me....
Thanks
|
|
|
|
|
The fact that you're mentioning a template column tells me that you're using an ASP.NET DataGrid . If so, this belongs in the ASP.NET forum.
In Windows Forms, you cannot paint an entire row; you can only paint columns by using a custom DataGridColumnStyle implementation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i have a c# app that i am writeing to read a visual foxpro 8 database but when i read the database with c# i lock the table and no one else can use it how to i make it use the file for shared access
thanks
chad aiena
|
|
|
|
|
How are you using it? Are you using ADO.NET to "read" the FoxPro database? There are connection string settings you can use to open the database as a shared database, and last I knew this was the default. Read the FoxPro documentation for more details about the connection string. Anything it documents for its OLE DB provider you can use in the OleDbConnection , and anything for the ODBC driver you can use in the OdbcConnection .
If you're simply reading the file as a stream (and why would you do that? just use the OLE DB provider), then you must specify the appropriate FileShare enumeration member:
FileStream file = new FileStream("file.dbf", FileMode.Open,
FileAccess.Read, FileShare.Read); This allows others to read but not write the file. Read the class documentation for the FileStream in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Please forgive me for being a complete amaeteur about this stuff. I really dont know what I'm doing. The problem I am having is with my scrollable control I am making. Here is the code below for the onPaint.
protected override void OnPaint(PaintEventArgs e)
{
// TODO: Add UserControl1.OnPaint implementation
base.OnPaint (e);
System.Drawing.Graphics g = e.Graphics;
//Draw the underlying background, including alternating row colors.
#region Draw the row backgrounds
//Brushes for the row backgrounds
System.Drawing.SolidBrush backcolor = new SolidBrush( this.RowBackgroundColor );
System.Drawing.SolidBrush altbackcolor = new SolidBrush( this.RowAlternatingBackgroundColor );
//Now draw the rows backgrounds.
float startpos = 0;
bool alternate = true;
int controlwidth = this.ClientRectangle.Width;
while ( startpos < this.ClientRectangle.Height )
{
if( alternate == true )
{
g.FillRectangle( backcolor, 0, startpos, controlwidth, this.RowHeight );
alternate = false;
}
else
{
g.FillRectangle( altbackcolor, 0, startpos, controlwidth, this.RowHeight );
alternate = true;
}
startpos += this.RowHeight;
}
backcolor.Dispose();
altbackcolor.Dispose();
#endregion
}
My problem is this. I put this control on a blank form and then put a listbox inside this control and made the listbox longer than the control so scoll bars would appear. When I run the form everything appears normal at first. However, once I scroll, the background, that should be just alternating colors does not get updated. One color will just take up the rest of the space on the bottom of the control. I hope that makes sense, it's kind of hard to explain. Any help would be appreciated. Thanks
Paul Rogero
|
|
|
|
|
Either create a bitmap (you can save it as a BMP (large), JPEG (small), or PNG (medium, but nice), or other formats but I recommend those. Then assign that to the BackgroundImage property.
Or, make sure you update your code according to the scroll position. When you paint, you can only paint in the client area (i.e., the visible portion of the code). Scrolling the control will not automatically do this for you. You have to code your painting handler to take the correct scroll position into account. Use the AutoScrollPosition (defined by ScrollableControl , inheritted by any derivative like UserControl and Panel ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Paul,
Below is your OnPaint function. I changed it to fix your problem (or what I believe you are saying is your problem) The fix was only two lines and they have //********** at the end of them so they stand out.
<br />
<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
base.OnPaint (e); <br />
<br />
System.Drawing.Graphics g = e.Graphics;<br />
<br />
#region Draw the row backgrounds<br />
System.Drawing.SolidBrush backcolor = new SolidBrush( this.RowBackgroundColor );<br />
System.Drawing.SolidBrush altbackcolor = new SolidBrush( this.RowAlternatingBackgroundColor );<br />
float startpos = AutoScrollPosition.Y;
bool alternate = true;<br />
int controlwidth = this.ClientRectangle.Width;<br />
while ( startpos < this.ClientRectangle.Height - AutoScrollPosition.Y )
{<br />
if( alternate == true )<br />
{<br />
g.FillRectangle( backcolor, 0, startpos, controlwidth, this.RowHeight );<br />
alternate = false;<br />
}<br />
else<br />
{<br />
g.FillRectangle( altbackcolor, 0, startpos, controlwidth, this.RowHeight );<br />
alternate = true;<br />
}<br />
startpos += this.RowHeight;<br />
}<br />
backcolor.Dispose();<br />
altbackcolor.Dispose();<br />
#endregion<br />
}<br />
Hope this helps!!
Karl Baum
CEO of KGB Technologies
Specializing in custom software development.
|
|
|
|
|
I wrote my first multi-threaded app in C# and I am having a bit of a problem. Everything works perfectly when the app is run on a users local machine. The problem comes into play when a person runs the app from our network.
I'll try to explain this as best as I can, I have a class which creates a member varible of a thread, then starts this thread. The thread goes to a member function in the same class where a new class is created and I call the "worker" member function of this new class.
This function enumerates some processes and deletes and renames a file. Basiclly when this is run from the network it hangs/crashes with a security exception when calling the new class member function. The only exception message I get back is "Request failed." that's it... I also get a secuity exception when I call Application.Exit() (Which is the last line before main() ends)
<br />
IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"<br />
version="1"<br />
Flags="UnmanagedCode"<br />
Strage stuff, cause none of these problems happen when working off a local copy on my HD. One interesting note, if I comment out the code in my "worker" class member function. I don't get the Request failed.
Any idea what all this is about?? Cause I am so confused!!
|
|
|
|
|
Working in a local environment (where you also are running as an administrator of your machine) creates a false sense of ... well ... security in your code. No pun intended.
Some things to check out:
Did you establish security permissions in your project ?
Can NT security be part of the problem? Do you have read rights where
you really need read/write rights when running on the server?
If all of the rights look alright, then did you set your security
provider correctly? Default for SecurityProvider is GeneralProvider.
You need to specifically change it to have a WindowsProvider as your
security.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
His project and NT security have nothing to do with it. It's .NET Code Access Security, which is a feature of the CLR.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The Common Language Runtime (CLR) features Code Access Security - a sandbox environment for .NET, if you will. By default, applications executed from the network (or that use network resources) run without FullTrust permissions. They are limited in what they can do, and local file access is restricted, among many other things.
I suggest you first read Understanding .NET Code Access Security[^]. You need to either change the Intranet permission set (not recommended), or create a new CodeGroup that uses a membership condition that will match up with your host or assembly evidence that the CLR would grab (like using a Url membership condition with "file://MYNETSERVER/SOMESHARE/*"). Grant that either FullTrust permissions (not recommended; do things right) or the necessary permissions to run.
To help administrators know what permissions your code requires, you should attribute your assembly with certain permission requirements (assembly-level attributes). You should also be mindful that your code may not be granted optional permissions and should check for SecurityException s accordingly (by either catching potential cases, or asserting the permission to see if you can perform a certain action).
For that, read Securing Applications[^] in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
or create a new CodeGroup that uses a membership condition that will match up with your host or assembly evidence that the CLR would grab (like using a Url membership condition with "file://MYNETSERVER/SOMESHARE/*"). Grant that either FullTrust permissions (not recommended; do things right) or the necessary permissions to run.
Yikes, I've read through the article a few times and still don't quite see what you mean by this. Some of these follow-up questions are probably still due to my misunterstanding but here they are none the less.
Can I just grant the program the "fulltrust" or permissions it needs no matter where it's being run from? Cause the file could be run from anywhere on our network. Not a specific location, I just can't seem to figure out how to do this? Is it an assembly directive?
It seems like creating a codegroup is just for the local machine and not everyone which is bad for 100+ people that would be running this.
P.S. I added:
[assembly:FileIOPermission(SecurityAction.RequestMinimum, Write="C:\\")]
To at least throw an exception when it can't do what it needs to do, I just have no clue how to handle the exception. (Where does it throw to?)
This is really wild stuff, Thanks for taking the time to help explain it.
|
|
|
|
|
An application can only tell the CLR what it needs to run. It can't grant itself permissions; that would defeat the purpose. Do you trust someone just because they say they're trustworthy? I certainly don't.
If you use an assembly-level permission attribute, the assembly is not even executed so you can't handle an exception (unless you're a different assembly trying to use a type defined in that assembly, when it's loaded for the first itme - you really have to understand how the CLR works).
You can grant your assembly or assemblies FullTrust permission (again, that's a big cop-out and not a very good idea) if you use assembly evidence to match up with membership conditions for a code group. Assembly evidence is strong name identity evidence and publisher (x.509) evidence. If you add a CodeGroup using either of those membership conditions, then your assembly will be granted whatever permission set you choose. If you use host-based evidence like URLs or site, then an assembly matching that evidence will be granted those permissions.
A codegroup is installed into a machine's policy, yes, which is why you have to install it onto all machines. This is no different that ActiveX security (what little there is) policies and Java sandbox policies. This can be distributed through Windows Installer packages, batch files, start-up scripts, whatever. Distributing a policy is not hard if you no what you're doing.
Don't just read the article; read the other links I gave you as well. The article here on CodeProject explains Code Access Security, but there's more information about setting up code groups and why.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
about Ado.net.When get data from database, use dataset or datareader which is faster?
|
|
|
|
|
A DataSet is used to store data not extract it from the database. However the operation to fill a DataSet uses the DataReader to get the information from the database. The DataReader is a Read-Only Forward-Only mechanism to get information out of the database.
The two are not directly comparable, it depends on what you want to do with the data. However, if all you want to do is read the data quickly then the DataReader is your best choice.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
I found out when loading some images into imagelist,then using these images in Application, as a result these images's quality are very bad.but I using Image.FormFile(strFilename), these are normal.Why? do i should do it?
|
|
|
|
|