|
Apparently[^], MS doesn't want us to create system modal dialogs.
I tried adding the DS_SYSMODAL style to the underlying Win32 window when the form is initialized, but that didn't work. See below:
private void OnLoad(object sender, EventArgs e)
{
Int32 nStyle = GetWindowLong (this.Handle, (-16));
nStyle |= 0x02;
nStyle = SetWindowLong (this.Handle, (-16), nStyle);
}
[DllImport("User32.dll", SetLastError=true)]
private static extern Int32 GetWindowLong
(IntPtr hWnd, int nIndex);
[DllImport("User32.dll", SetLastError=true)]
private static extern Int32 SetWindowLong
(IntPtr hWnd, int nIndex, Int32 nNewStyle);
I then resorted to this (extremely) cheesy solution which works:
public Form1()
{
InitializeComponent ();
Timer timer = new Timer();
timer.Interval = 1;
timer.Tick += new EventHandler (timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
this.TopMost = true;
this.Activate();
}
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Ravi Bhavnani wrote: Apparently[^], MS doesn't want us to create system modal dialogs.
I largely agree, and always ontop *option* can be useful in limited circumstances but not as a modal. For any application I'm using my reaction to that sort of behavior would be task manager-kill process. I can see the desire to do something like this for a kiosk type app, but full screen and eating alt-tab, and ctrl-alt-del would be the stronger solution there unless you're using hardware with a nuetered keyboard that can't enter those strokes.
|
|
|
|
|
|
Hi,
In my C# application I am trying to execute a SQL query, transform the query results (using XSL) returned in a form of XML, and ultimately want the resutlset as a string in resultSetToAscii. I have started working on C# very recently, so I am sure that I am doing some silly mistake. Basically my code fails in the 3rd line here and the error desc is "Data at root level is invalid". Anybody any ideas?
XPathDocument destination;
XPathDocument source;
source = new XPathDocument(new StringReader("//row"));
destination = new XPathDocument(_xsl.Transform(source, null, (XmlResolver)null));
XPathNavigator nav = destination.CreateNavigator();
{
XPathNodeIterator iterator = nav.Select("//row");
while (iterator.MoveNext())
{
foreach (Field field in _destinationFields)
{
string data = "";
if (field.name != null)
data = iterator.Current.GetAttribute(field.name, String.Empty);
resultSetToAscii = data.PadRight(field.size, ' ');
}
}
}
|
|
|
|
|
You are creating a StringReader for the string "//row" and try yo use that as an xml document. The problem is that "//row" is far from a valid xml document.
Are you trying to use xpath to read nodes from an xml document? Then you actually have to have an xml document to read from...
---
b { font-weight: normal; }
|
|
|
|
|
Okay I understand. I think the resultset is in the form of xml. I get the resultset by executing this int iRecs = cmd.ExecuteNonQuery();
So what can I pass to this call below?
source = new XPathDocument(...)
Thanks.
|
|
|
|
|
The ExecuteNonQuery doesn't return a result, it only returns the number of records affected by the query. So, you don't have any data to start with.
---
b { font-weight: normal; }
|
|
|
|
|
After reading bytes of a file, if I check
ex) file[0]==0xFE && file[1]==0xFF
and the condition is true, I can say that it is encoded in 'BigEndianUnicode'.
but how do I determine encoding of a file if the file has, say, 'Portuguese(DOS)-codepage 860' as an example.
Encodings other than obvious ones like UTF-8, BigEncidnaUnicode, or ASCII, how do I determine the encodings by reading bytes of the file? Is there any efficient way to check the encoding of a file?
|
|
|
|
|
If the file doesn't contain an encoding string no. MS has developed a statistical guessing engine for IE using byte frequencies that works most of the time, but afaik they've never released a way for 3rd party devs to use it.
|
|
|
|
|
Do you mean there is no way of user knowing what encoding a file has?
|
|
|
|
|
No, there is no way of determining what it is without guesswork.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I want to create dialer application in .Net 2.0.
Please guide me how to do this.
Ashwani
|
|
|
|
|
All, I would like to know how to increase the speed of the GDI object for drawing purpose. I need to draw lines connecting 100000 points. I am using graphics.drawline. But it takes approx 5 seconds to finish the task. How can I reduce the drawing time.
CodeBala
|
|
|
|
|
You should see some improvement if you call DrawLines instead of DrawLine.
Josh
|
|
|
|
|
Josh, thanks for your reply. But as per my logic I need to test for the validity of the point before drawing. So I have to use drawline only. Is their any other way??
|
|
|
|
|
Hi Josh, thanks. I used Drawlines. Its amazing. Thanks again
CodeBala
|
|
|
|
|
You could try setting the Graphics.SmoothingMode property to HighSpeed before you draw the lines, like this...
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; Hope that helps
“Accept that some days you are the pigeon, and some days you are the statue” -- David Brent
Cheers,
Will H
|
|
|
|
|
Will, thanks for your reply. But for some reason the HighSpeed was increasing the time to draw.
CodeBala
|
|
|
|
|
I have a try/catch block in the main method of my app that's designed to handle any fatal exceptions and shut the program down with a useful error message. If I run my program in visual studio it functions as designed, but if started directly the framework catches it and shows the unhandled exception dialog with details, continue, and quit. The code below demostrates the problem.
static void Main()
{
try
{
Application.Run(new Form1());
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
}
}
private void button1_Click(object sender, System.EventArgs e)
{
throw new System.Exception("test");
}
|
|
|
|
|
So what is the error you get when you run it from outside the framework?
|
|
|
|
|
Instead of getting a messagebox with "test". I get the framework exception catcher.
An unhandled exception has occured in your application. If you click
continue, the application will ignore this error and attempt to continue.
If you click quit, the application with be shut down immediately.
test.
details contains the following:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.Exception: test
at Exception.Form1.button1_Click(Object sender, EventArgs e) in c:\documents and settings\neelyd\my documents\visual studio projects\exception\exception\form1.cs:line 96
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:----------------------------------------
Exception
Assembly Version: 1.0.2312.14759
Win32 Version: 1.0.2312.14759
CodeBase: file:----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:----------------------------------------
System.Xml
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:----------------------------------------
************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.
|
|
|
|
|
I haven't been able to figure out why this is happening, but the thing causing the difference in behavior is the presence of a debugger attached to the process. Even within VS .NET, if you hit Ctrl+F5 (Start without debugging), you can observe the same behavior.
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Warning: I am guessing here.
Your try is in the Main() function, around the Application.Run . At the application level, there is a global exception handler, which handles exceptions that reach it without being handled in code. When you run the application from the .exe (i.e. not in Visual Studio), the default exception handler is reached without being handle in the application, so you get the unhandled exception dialog. Notice that if you select "continue", the application continues to run, because Application.Run was never exited, and your catch was not used.
Now, when you run your application from Visual Studio, I think that Visual Studio has it's own exception handler (outside the Main() function), and the applications default exception handler is turned off. Thus when you throw your exception, it reaches your catch before it gets to VS's handler. This also explains why the application ends after your MessageBox, because your exception execution to exit the Application.Run .
Roy.
|
|
|
|
|
That sounds like a plausable guess, do you have any thoughts on a way to work around the problem that doesn't involve slapping try/catch blocks inside every event handler? Not having to clutter my code up that way was one of the main reasons I moved it there. The second was related to forcing a shutdown, but I don't recall exactly what it was.
|
|
|
|
|
Try this. Instead of wrapping your Application.Run in a try..catch, write a new exception handler. (If I recall correctly, you wanted the application to end after an exception? That is the reason for the Application.Exit() . If you don't want this, go ahead and remove it.) Good luck.
static void Main() <br />
{<br />
Application.ThreadException += new ThreadExceptionEventHandler( MyExceptionHandler);<br />
Application.Run(new Form1());<br />
}<br />
<br />
private static void MyExceptionHandler(object sender, System.Threading.ThreadExceptionEventArgs e )<br />
{ <br />
MessageBox.Show(e.Exception.Message); <br />
Application.Exit();<br />
}
Roy.
|
|
|
|