|
Hi,
Currently I am working on a windows application, and one of my form has to be a system modal type. In good old VB the option was available, but now in C# with .NET framework its not there.
If any one can help me out here and give me some guidence with how to make windows .NET form a system modal type?
My Reauirements are :
The form has to be on top all the time.
No Minimizations allowed.
Cannot switch to any other application.
Can not open windows explorer or press ctrl+alt+delete.
Thanks
Lav Pathak
Application Developer
Auxiliary Enterprises
Kalamazoo, MI
|
|
|
|
|
Calling ShowDialog on a Form-derived class will show it modally. It will be on top of all other windows in your app. If you set the form's MinimizeBox property to false, you won't be allowed to minimize the dialog.
Lav Pathak wrote: Cannot switch to any other application.
Can not open windows explorer or press ctrl+alt+delete.
These features are not available in WinForms. You might be able to use some Win32 calls to accomplish those.
Josh
|
|
|
|
|
Josh thanks for the quick reply, but i need to keep my form on top of all the other apps. I know this is a bad design, but i dont have many options here.
I Dont know what win32 calls i shuold make to make it system wide modal.
Thanks
Lav Pathak
Application Developer
Auxiliary Enterprises
Kalamazoo, MI
|
|
|
|
|
Lav Pathak wrote: I Dont know what win32 calls i shuold make to make it system wide modal.
Me neither.
|
|
|
|
|
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.
|
|
|
|