|
Here is some code, uses Win32 interop
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
public enum SpecialKey
{
CapsLock = 0x14,
NumLock = 0x90,
ScrollLock = 0x91
}
public class SpecialKeyState
{
[DllImport("User32.dll")]
private static extern short GetKeyState(int nVirtKey);
public static bool GetSpecialKeyState( SpecialKey k )
{
int s;
s = GetKeyState((int)k);
s &= 0x01;
if (s == 1)
return true;
else
return false;
}
}
I didn't test this code exactly. It is ripped from a component I made from some other code on the internet. I modified it to let you test any of the speical keys (my version allows you to set a member and then test that key on an interval).
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Thanks Nathan! That does the trick for getting the num lock state.
I'm trying to figure out how to set the num lock now. I found a Win32 example that does this using keybd_event:
keybd_event(VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0);
The signature of this method is:
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // function options
ULONG_PTR dwExtraInfo // additional keystroke data
);
I wasn't exactly sure what types to use for the last two parameters in the extern statement, so I tried "long" and crossed my fingers:
[DllImport("User32.dll")]
private static extern void keybd_event(byte bVk,
byte bScan,
long dwflags,
long dwExtraInfo);
This actually works the first time I call it, but it gets really flaky after that. I figure that I'm not using the right types for the last two parameters, so I'm stomping on memory somehow. Any clue what types I should use?
Thanks again.
|
|
|
|
|
I also tried unsafe code with a long pointer, but this doesn't work any better than just using longs:
[DllImport("User32.dll")]
private unsafe static extern void keybd_event(byte bVk,
byte bScan,
uint dwflags,
ulong* dwExtraInfo);
|
|
|
|
|
Try using IntPtr instead of the long for the ULONG_PTR.
I really don't know, perhaps one the people with more experience in Interop will be able to tell us.
Later,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
I have a picturebox in my application and I have alist of images too.When user choose each image it display in that picture box.My problem is when size of image bigger than size of picture box,part of image does not shown in picturebox.The question is how can I manage this size when the image bigger than picturebox and show all of it in that picture box?Any suggestion or idea?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
You can do a couple different things with the SizeMode property of the PictureBox.
If you set it to PictureBoxSizeMode.StretchImage then the image will change it's size to match the picturebox. Not my favorite way of doing it, but if you must be able to view all of the image at one time then this can work (to make it look better you may have to resize the picture box a little so that the aspect ratio of the image is retained).
My favorite method is to place the picture box in a panel, set the SizeMode to PictureBoxSizeMode.AutoSize which will change the size of the picture box to match the image. Now set the panel's AutoScroll property to true. Now you will get scrollbars which can be used to view the hidden parts of the image, and the image will display at normal size.
Without knowing your exact requirements that is all I can offer, but it covers the two scenarios I can think of.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thanks James.Both of them are what I need.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hi all,
Does anyone know why this will throw an exception when the address reaches 10.20.30.128?
Any Ideas?
Thanks
string from = "10.20.30.0";<br />
IPAddress ipAFrom = IPAddress.Parse(from);<br />
IPAddress tempIP;<br />
for(int i=0; i <255; i++)<br />
{<br />
tempIP = new IPAddress( IPAddress.NetworkToHostOrder(IPAddress.HostToNetworkOrder((int)ipAFrom.Address)+i));<br />
addToIPTable(tempIP.ToString());<br />
} <br />
|
|
|
|
|
Looks like a bug in the IPAddress class. The NetworkToHostOrder creates a negative int , which causes the constructor to throw an exception.
Try this:
tempIP = new IPAddress(
(uint)IPAddress.NetworkToHostOrder(
IPAddress.HostToNetworkOrder((int)ipAFrom.Address) + i));
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hi,
Is there a tutorial around for making skinned apps like winamp in C#? (I mean how can i make good looking and different UI s?)
Thanx...
|
|
|
|
|
In C# resource editor let say I am putting a label string say "Hello Label".
Resource editor generate the code for it in InitializeComponent() like
this.lblMessage.Text = "Hello Label";
I am coding for multiple languages (German/French). So it create lot of
problem for me. I have to change all these lines to
this.lblMessage.Text = resManager.GetString("txtHello");
I am storing all these messages in a MyApp.resx files and maintaining a
separate .resx file for each language like for German there is a
MyApp.de.resx and setting the UICulture in my code.
Is there any simpler way for this?
Sonork ID 100:25668
|
|
|
|
|
I think you can do the same thing using the properties editor. First set the Localizable property on the form to true, then set the form's Language property to the first language. Now proceed to set all of the properties that need localized strings. Then change the Language property to the next language, and change all of the localized strings, repeat.
I did this while playing around a couple months ago and it seemed to produce what you want.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thank you James
Sonork ID 100:25668
|
|
|
|
|
Hi all,
How can I fix the TextBox height permanently? If we change the font size, the height of the TextBox changes accordingly. But in the OpenFontDialog , we have a TextBox [which displays the sample/preview], for which the height remains permanent, even when the font size is high. How can we do this ?
Thanks
Smitha
It is better to be hated for what you are than to be loved for what you are not.
-- Andre Gide
|
|
|
|
|
Smitha Vijayan wrote:
How can we do this ?
I think you are looking for the AutoSize property.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thanks James
Smitha
It is better to be hated for what you are than to be loved for what you are not.
-- Andre Gide
|
|
|
|
|
Message to Chew Keong TAN, who asks:
"The following positive pseudoprime and several others passes our implementation of primality test but failed in JDK's isProbablePrime test. Any advice on why this is so would be greatly appreciated".
James Wanless replies:
"I'm primarily a mathematician, rather than programmer, but think I may have an answer for you - I have discovered that the Miller-Rabin Test is (effectively) seriously WRONG (sic) [please see my original posts on sci.math for the logical/math reasoning behind this discovery - copyright JGW 2000 or thereabouts ]. It greatly underestimates the chance that a number it calls prime is actually composite (ie the chance of each false witness is >> 1/4, unlike as claimed). Unfortunately for it, too, the discrepancy worsens with increasing size of number tested.
This means, in practice, that if two different M-R implementations (eg yours and JDK) use different specific witnesses there is a non-negligible chance that results will differ, both in the way you describe, and also probably in the reverse direction.
Fortunately, however, I have developed a suitable (both fast and accurate - especially for big numbers) replacement for M-R. A java implementation of this I have published (with source code) at:
http://www.bearnol.pwp.blueyonder.co.uk/Math/Prime/Primeda.html
Feel free to use/incorporate this into your own programming, provided appropriate (math) credit is given...
"
Best regards,
James
http://www.bearnol.pwp.blueyonder.co.uk/
|
|
|
|
|
Hi All,
Quick question: Does the = 's operator work on TabPages ? I have a program where I create an empty TabPage , I then create another TabPage and add a bunch of controls to it. Then basically I replace the empty page (or it may be a page with controls on it already) with the page I just created, but using the = 's operator doesn't seem to work. If I use the Add method for the TabPages property it works fine. Is there special trick I need to do in order to get = 's to work.
Thanks in advance.
|
|
|
|
|
It sounds like you are assigning the reference to the new TabPage to the variable that references the old TabPage, instead you need to do something like:
myTabControl.TabPages[oldPageIndex] = myNewTabPage;
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
That's exactly how I'm doing it, but it just doesn't seem to work.
Thanks for the response though.
- monrobot13
|
|
|
|
|
I have a VS.net solution that has:
- server project
- client project
- shared library
- shared library 2
The server project publishes both shared library and the second shared library for remoting. The client properly registers itself to use the remoting objects. The client can successfully use the remoting objects.
Here is the question: I want shared library 2 to be able to access the remoting object “Shared library” by using remoting. I add all the necessary references. But – when I try to register the class as a client for remoting (by doing :
System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownClientType(typeof(Shared.MySharedClass), "http://127.0.0.1:8080/shared");
It fails with a remotingexception.
Is it possible to access other remoting objects from an object that is published for remoting?
|
|
|
|
|
I am trying to send lines of hex file to commPort wit the serial communication.
I am trying the StreamReader and ReadLine and using textfile to do this job.
My hex file is an Intel hex format for example look like below.
TextFile
:0341000002410079
:0B410000E4C2E8C2E9C2EAC2EB80FEA4
:00000001FF
I have no problem to build this example soultion.
but I get an error when I try to bress button (Sndf3) button.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at BaseTerm.SndF3(StreamReader fr) in baseterm.cs:line 174
at TermForm.SndF3_Click(Object sender, EventArgs e) in termform.cs:line 662
Any suggestion or code help will be great.
Salam Hamid
-----------------------------------------------------------------------------------
Her is My C# code.
baseterm.cs
public void SndF3(StreamReader fr)
{
string input ;
while((input = fr.ReadLine()) != null)
{
for(int i =0; i < (fr.ReadLine().Length); i++) // Line 174
{
Send((byte)input[i]);
}
frm.ShowMsg("Hex Line OK...");
}
}
//----------------------------------------------------------------------------------
termform.cs
private void SndF3_Click(object sender, System.EventArgs e)
{
StreamReader fr = File.OpenText("P401CR.hex");
BaseTerm.term.SndF3(fr); // Line 662
fr.Close();
}
|
|
|
|
|
Use StreamReader.Peek() rather to so the EOF, ReadLine() wont garenteee anything.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Adding on to what leppie said.
You are getting a null reference exception due to a simple misconception.
while((input = fr.ReadLine()) != null)
input is now equal to the line that was read from the stream, the important point is that line has been removed from the stream. So now the next line of code will eventually fail because:
for(int i =0; i < (fr.ReadLine().Length); i++)
Your loop reads in one line from the stream until it crashes or i is greater than the length of the last line read in (keep in mind you are reading in a line every time through the loop).
What you probably meant to write was:
for(int i =0; i < (input.Length); i++)
So that you process the line of input read in at the start of the while loop.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thank you James and leppie.
I used
for(int i =0; i < (input.Length); i++)
it works now.
Salam;)
|
|
|
|