|
That works, but on the actual form I need it on which is incredibly complex I get an out of memory exception when I go to show one of the panels that I didn't get before.
Wierd because it works with all the other panels being shown, it's seemingly unrelated. I'll dig into it more using your example as a starting point and try to determine why I would get an out of memory error on that form.
It definitely allows text to hover over the form and not interfere with the controls.
Thank you.
[UPDATE: it works. The error was something unrelated of course! ]
|
|
|
|
|
If you're form contains controls you've defined, be sure you're extending the right class. Far too often I see people extending UserControl , which is a container control with a lot of overhead. Notice how I simply extended Control for my example (and an example it is, mind you)? Much less overhead. A window (since every control is a window) is still required unless you take that unweildy approach from the first reply, whether it uses a clipping region or layered windows (which will give you better performance, but - again - is only supported on Windows 2000 and newer).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
If you're form contains controls you've defined, be sure you're extending the right class. Far too often I see people extending UserControl, which is a container control with a lot of overhead. Notice how I simply extended Control for my example (and an example it is, mind you)? Much less overhead. A window (since every control is a window) is still required unless you take that unweildy approach from the first reply, whether it uses a clipping region or layered windows (which will give you better performance, but - again - is only supported on Windows 2000 and newer).
Nope, I'm just using out of the box Infragistics components. I have a healthy respect for the problems that you can run into making your own controls based on my experience doing it with mfc / win32 stuff years ago. Our software is commercial, has to support a wide variety of opsys, hardware and locales and so we use out of the box stuff only in general.
The problem I alluded to turned out to be in an underlying business object, completely unrelated and your example worked fine on my XP pro development station.
My only further question is that your method appears to work just fine, however you mentioned windows 2000 and above for layered windows, what will happen if I attempt this on a Win98 system? Will it not work, or will the text completely obscure the existing controls on the form or interfere with them in some way? What I'm hoping for is that the watermark text will be translucent so that it really is a watermark and doesn't interfere with the underlying controls already on the form.
However if this is not the case for win98 I can't use it since we (sadly) must support w98.
|
|
|
|
|
John Cardinal wrote:
Nope, I'm just using out of the box Infragistics components.
There's your problem. I've used some of their Windows Forms controls in the past, and while they're nice they are burdensome beasts. Specifically, the way controls are drawn uses a very large assortment of interconnected UI elements and can be very slow. I've created a few of these to add multi-selection and custom drag and drop functionality for their UltraWinTree product and saw just how deep their painting algorithms go.
If you can - and for what you can - use simple controls where you don't need more functionality.
Also note I'm not saying one way or another about using Infragistics controls, just that they can consume a lot of resources especially when drawing.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Ummm..no, I'm not having a problem at all. As I said it was something completely unrelated and in the business objects. I think your burning through these messages a little too fast Heath!
What I was curious about was the pre-windows 2000 implications of your example (which works fine on my XP station by the way).
Specifically:
You mentioned windows 2000 and above for layered windows, what will happen if I attempt this (your example Watermark control code based on Control) on a Win98 system?
Will it not work, or will the text completely obscure the existing controls on the form or interfere with them in some way? What I'm hoping for is that the watermark text will be translucent so that it really is a watermark and doesn't interfere with the underlying controls already on the form.
However if this is not the case for win98 I can't use it since we (sadly) must support w98.
|
|
|
|
|
No, was reading what you wrote and while I know the controls weren't your underlying problems it doesn't change the fact that Infragistics controls use a lot of resources, especially when painting. Using ildasm.exe and discover it for yourself. It's obfuscated but I really didn't have any problems.
Windows XP is a flavor of Windows NT after Windows 2000. Windows 2000 is version 5.0 while XP is 5.1; so, Windows XP is newer than Windows 2000, which is what I said was necessary for layered Windows.
The example I presented using my Watermark control is the way to supported older clients including Windows platforms (i.e., Windows 9x/Me). Clipping regions have been supported since Windows 95 if not earlier (it's been so long I don't remember).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Not sure if this has been asked:
Working on a SDI app(VS2003 in C#) with several forms of the same class opened; I'd like to first, select each form, and then check for changes and then Close() each form automatically; and then exit out of the app; (Note: this is NOT an MDI App.)
I have a Handle to each form (Window), but I cannot bring the other forms to Close() once one is closed, without the user clicking the next form to bring it in to focus. I need to switch or step thru each opened form.
P.S. Remove the "!" in my email to send.
"Being smart is no good until you find out who else is."
|
|
|
|
|
If you have the handle to each window you want to close, P/Invoke the SendMessage function and send a WM_ClOSE message along with your associated HWND .
private const Int32 WM_CLOSE = 0x0010;
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
|
|
|
|
Thanks Nick, I'll give it a try...
"Being smart is no good until find out who else is?"
|
|
|
|
|
You could keep a list of the forms that are open and create a handler that is assigned to every form's Form.Closed event. This handler then iterates over your list of forms and closes each form in succession (via a call to Form.Close() ). Of course you would have to skip over the form that was already closed.
Once that is done you could then just call Application.Exit() as per normal.
Actually, thinking about it: this is a good candidate for an ApplicationContext . Have a look at the example on the ApplicationContext Overview page in your SDK (the example isn't on the MSDN page, sadly), that example is similar to what you want. It could be easily extended.
This space for rent!
My Blog
|
|
|
|
|
Actually, I should've thought more before I posted that. It won't work as each call to Form.Close() will result in the Closed event firing again, which will cause some strange behaviour.
You could simply make a direct call to Application.Exit when the Closed handler is executed, since Application.Exit does not fire the Form.Closed event.
It's probably a little messy, but it's how I would do it.
This space for rent!
My Blog
|
|
|
|
|
I've been working with Nick's suggestion; seems like I have to go back to the SendMessage function... Thanks Adam
"Being smart is no good until you find out who else is?"
|
|
|
|
|
I am working through an exsiting application and it has very few try catch blocks and is letting errors pass straight to the error web page. I make liberal use of try catch blocks am I overdoing it? How expensive is a try catch block am I missing something?
|
|
|
|
|
The only reason for a catch block is to handle the exception by performing a task or adding additional information to the exception and rethrowin. Not just logging the exception and rethrowing, if exceptions are recorded, they should only be recorded once.
Finally blocks/using statements should be used to clean up state like disposing of database connections.
Most of the time exceptions should be so severe that the error web page, or a custom application level handler is the best way to handle them. One rule of thumb I use is that code in catch and finally blocks should be unimportant to the actual working of the application. If you have any logic in your application that requires the catch block for it to work correctly then the code is in the wrong place.
As far as performance goes, for a typical asp.net application accessing a database, each request could throw and catch hundreds of exceptions and performance probably would not be affected because network access is so slow compared to processor time. So for most moderately well written applications most time is spent waiting for database response or sending and recieving data to the client.
So, don't avoid catches because of performance issues. Use them to make your code easier to read and avoid them where it makes it more difficult.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
andy brummer wrote:
The only reason for a catch block is to handle the exception by performing a task or adding additional information to the exception and rethrowin.
I would hope that's not your mantra. End users should never see exceptions. This is no better than showing them AV exceptions in native code, or even the dreaded blue screen of death.
Exceptions are for whatever you need them for, whether that's recovering from an issue, ignoring certain known problems, logging, adding information and rethrowing, etc.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Sorry, left out that part. Every event handler in a Forms application should have a catch, usually just to log and show a generic error message, hopefully more if there is better information to give the user.
In ASP.Net a general error handler is usually sufficient. If you can do something better at the page level then add a handler there. Only after that should you add a catch handler to one of the events.
Unfortunately I've seen
try
{
}
catch (Exception e)
{
throw e;
}
way too many times, and let the rant out in my answer.
What I tried to get through with my answer was that exceptions are there to make your code easier to read and debug. What I was trying to get through is you should use it for the reasons you stated.
However, detecting invalid input by catching an exception from int.Parse would probably be a bad way to structure your application when there is a cleaner way to validate user input. Typically the arguement against it is performance, which would be the case in something like a batch processing application. For an ASP.Net page that wouldn't really apply, because you are sending information over the network.
So, for validating user input on an ASP.Net page I would either use the built-in validation controls or write custom validation code for all the input that would not throw exceptions under all input that I could test, and use a generic exception handler for cases that truely are exceptional and provide a relatively friendly error message to the user for that case.
This was way too long of a reply considering we both have similar views on exception handling. I just come across as more of a jerk online.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
I've got a couple of things that I'm still working on the conversion of C to C#
// **** begin sample C code **** //
unsigned char *tempvar = "1989";
unsigned char dataArray[256]; // hex value stored in this array with year in location 0xC0;
char* Message;
if (!strncmp(dataArray + 0xC0, tempvar, 4)) Message = "different data!";
// **** end sample C code **** //
What I'm trying to do is to compare the data in location 0xC0 in dataArray with tempvar.
Now the question is... I'm trying to determine the correct coding for C#. Correct me if I'm wrong.
// **** begin convert to c# code **** //
string tempvar = Convert.FromBase64String("1989");
byte[] dataArray; // hex value stored in this array with year in location 0xC0;
if (tempvar.CompareTo(Convert.ToBase64String(dataArray, 0xC0, 4)) != 0) Message = "different data!";
// **** end convert to c# code **** //
|
|
|
|
|
Hex != base64. Hex is base16, which is obviously not base64. To hex-encode integers you can use their IFormattable.ToString implementation. This could be done like so:
int value = 1989;
string hex = "0x" + value.ToString("x4"); This will hex-encode 1989 into a four-digit hexadecimal representation to look like "0x07c5".
You don't need to conver to hex, however. Hex is only a representation of numbers. Your tempvar in the C code will contain the bytes {0x31, 0x39, 0x38, 0x39}. Those are strings, though - they're numberic expressions for the ANSI characters (since you're using a char array, they are only 8-bit character using the codepage you specify when compiling (default of system codepage).
Also keep in mind that a char* or char[] is a string. A string is just an array of characters. So if dataArray was a byte[] array like in your example (meaning ANSI text, not Unicode like .NET uses to encode stored strings), then you'll need to convert your string "1989" to a byte[] array using ASCIIEncoding and compre the buffers at that offset:
using System;
using System.Text;
class Test
{
static void Main()
{
byte[] text = Encoding.ASCII.GetBytes("1989");
byte[] dataArray = new byte[256];
int i = 0xc0;
dataArray[i++] = 0x31;
dataArray[i++] = 0x39;
dataArray[i++] = 0x38;
dataArray[i++] = 0x39;
bool found = true;
for (i=0; i<4; i++)
if (dataArray[0xc0 + i] != text[i])
found = false;
Console.WriteLine(found);
}
} An easier way is to just convert the 4 elements starting at offset 0xc0 from dataArray into a string and compare it:
using System;
using System.Globalization;
using System.Text;
class Test
{
static void Main()
{
byte[] dataArray = new byte[256];
int i = 0xc0;
dataArray[i++] = 0x31;
dataArray[i++] = 0x39;
dataArray[i++] = 0x38;
dataArray[i++] = 0x39;
byte[] text = new byte[4];
Array.Copy(dataArray, 0xc0, text, 0, 4);
string s = Encoding.ASCII.GetString(text);
bool found = string.Compare("1989", s, true,
CultureInfo.InvariantCulture) == 0;
Console.WriteLine(found);
}
} You should read up on string encoding for more information. Also note that compilers treat various numerical expressions the same, so:
0xC0 == 192 == \300 They're all just different representations of the same numbers, so don't confuse hex-encoded values as string to compare.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi guys,
I have a problem where the user clicks a button to launch a fairly processor intensive task. After pressing, the button becomes disabled, and the task is set running.
The problem is that if I press during the task (the text is grayed so I know it actually has been disabled) as soon as the computation has completed and the button is re-enabled, it remembers the button press from earlier and runs again
Any Ideas?
Mike
|
|
|
|
|
mikey_g wrote:
The problem is that if I press during the task (the text is grayed so I know it actually has been disabled) as soon as the computation has completed and the button is re-enabled, it remembers the button press from earlier and runs again
Any Ideas?
Hmm, that sounds strange, I would like to see the code. I put together a simple app that is defined as you described above and couldn't recreate it. Check the following:
using System;
using System.Threading;
using System.Collections;
using System.Windows.Forms;
public class MyClass : Form
{
Button b;
private void Initialize()
{
this.b = new Button();
b.Text = "Click Me";
b.Click += new EventHandler(bClick);
this.Controls.Add(b);
}
private void bClick(object sender, EventArgs e)
{
b.Enabled = false;
DoLongProc();
b.Enabled = true;
}
private void DoLongProc()
{
Thread.Sleep(5000);
MessageBox.Show("Done now");
}
public static void Main()
{
MyClass m = new MyClass();
m.Initialize();
m.ShowDialog();
}
}
|
|
|
|
|
Ok, it was my bad coding. What was happening was that I hadn't run the processor intensive code in a thread, it was all inline stuff.
This was causing the window to not fully respond to input and the click was only handled once the process was finished, ie, once the button had been re-enabled.
Thanks for the help as it put me ontrack
Mike
|
|
|
|
|
Hi all, anyone know if the XML Bulk Loader can be used in C# instead of from a vb script?
Is there a namespace or anything that i can include?
Kev
|
|
|
|
|
It can be used as a COM object. You have to create a Primary Interop Assembly (PIA) first and then you can make it work. With the latest version of sqlxml (service pack 3), you can just add a referece from the COM tab of the Add Reference dialog (see this article to see how the reference is added: http://www.dbazine.com/cook3.shtml[^] ). Visual Studio will generate the PIA automatically and add it as the reference in your project. Keep in mind though, that the PIA that it creates doesn't get created with a strong name, so if you plan to use your C# project from COM+, you will have to re-create it by hand using tlbimp.exe and a .snk (strong name key) file to make sure that it has a strong name.
I have worked with SQLXML from C# quite extensitvely, so let me know if you have any specific questions.
Best Regards.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I have the Infragistics Calendar control on my form. I am calling the DisplayAppointmentDialog method of the ClendarInfo object and the dialog is being displayed fine. How can I control the controls on that dialog to customize it?! For example, the dialog has an Action tab. What can I do to remove this tab, or disable it?!
Elie
|
|
|
|
|
You probably won't find many responses to this question as this forum is specific to problems with the C# language, not third party controls. You might check the Infragistics Support site here[^] for additional help. Good luck.
|
|
|
|
|