|
Hi,
I have bought a Digital Pen that its handwriting only works with Info Path.
Is there any software that make my Pen (Genius G-Pen 560) compatible with any windows Form?
Best wishes
|
|
|
|
|
In an application I set the windows cursor to a WaitCursor, but other components within the same application set it back to Default. Is there a way to set the cursor type, and prevent other areas of the same application from changing it? Thank you in advance.
Kalvin
|
|
|
|
|
You can set the UseWaitCursor property to force the WaitCursor to be the one used when the mouse is within the bounds of an object with that property set to "true". I don't think that there is any way to prevent another app from changing it unless you are coding the app. If you are coding it, then look into thread synchronization techniques. The method I would try to implement would be to acquire a named mutex (or static variable) anytime you want to change the cursor. Then, if you want to prevent others within your app from changing it, just hold the mutex (static variable). Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Thanks a lot for your reply.
The cursor is being changed from different components that together make an application. Some components I have access to change, and others I can't access or modify the code. I also should have stated that this is in VS 2003 and the WaitCursor isn't available. I can't access other components to make them use a mutex. If those are the only options in C#, is there a way to use an API to do this or is doing this just not the way windows works?
Thanks again.
|
|
|
|
|
I'm not really certain if the following would lock only a local copy of the cursor, or if it would lock the cursor resource for all applications, but you could try to use the WinAPI calls LoadCursor[^] followed by a LockResource[^]. Again, I don't have time to experiment with these, but they would be worth looking into. Another idea would be to implement a timer that continuously checks the cursor, and sets it back if it is changed (this method scores a 9/10 on the hack scale). A better idea would be to listen to the windows events (like Spy++ does) and block any attempt at sending a WM_SETCURSOR (I assume this is the message being sent) message. I've never tried to intercept windows messages, but I'm sure you can google to discover how to go about this (perhaps look at overriding DefaultWndProc and WndProc methods on Control objects?). Please post results if you get it working.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Thank you for the reply and all of your help.
|
|
|
|
|
I need to programatically convert float values like 17.1054688 to 17.11 in C#
i.e want to restrict the float values upto 2 decimals.
For this I have written following code:
<br />
private void Roundupto2Decimals(ref float fVal)<br />
{ <br />
string strVal = fVal.ToString("F2");<br />
fVal = float.Parse(strVal);<br />
double dVal = (double)fVal;<br />
}<br />
In VS2005 watch window, I get the correct value for fVal.
for e.g:
Input : 17.1054688
strVal: "17.11"
fVal : 17.11
but ---> (double)fVal : 17.110000610351563
I am not sure when I typecast the same float to double I get unepcted value.
I expect dVal to be 17.11 too.
Can any one help me understand what is happening?
Thanks and Regards,
Arti Gujare
|
|
|
|
|
Hi,
I think it's because C# float is not exact. Try to use decimal instead.
zilo
|
|
|
|
|
It's all due to the way floating point numbers are represented - some numbers can't be represented exactly, so will have very tiny errors.
As suggested by the other poster, if you are using small numbers, and require high precision, then the Decimal type would be more suitable.
|
|
|
|
|
I tried with decimal too.
Did not help much..
This is what I tried.
<br />
private void Roundupto2Decimals(ref float fVal)<br />
{<br />
decimal decVal = Math.Round((decimal)fVal, 2);<br />
fVal = (float)decVal;<br />
double dVal = (double)fVal;<br />
}<br />
Any other idea?
|
|
|
|
|
You are still using float, aren't you ?
what about this:
double dVal = Math.Round((double)fVal, 2);
if you need that value exactly, just use decimal in any calculation you are planing. If you want to display exactly 10.11, use decimal. If you're just wondering why is it different, we explained you why and don't worry about it anymore
zilo
|
|
|
|
|
The problem is that the third party dll uses float value in its class.
So I really cant get rid of the float and I still need to use this dll.
As a work around I am using Math.Abs() method to find out tolerable difference between the two float values instead of checking exact difference using "==" with floats.
|
|
|
|
|
|
Thanks you Led.
The link is quite useful.
|
|
|
|
|
hello, math.round donot support float, its argument must be Double.
for example :
Double dblValue = 123.126789;
dblValue = Math.Round(dblValue, 2);
MessageBox.Show(dblValue.ToString());// Displays 123.13
I think u can continue your work.
Best of Luck.
Dipak
|
|
|
|
|
Sorry, you're mistaken. Your example happens to produce the result you want, but it is
not correct. Here is the background:
The way floats/doubles are stored in binary makes it impossible to exactly represent
most values, especially the ones that seem like round numbers to humans thinking
using base ten.
So 4, 2, 1, 0.5, 3.5, 3.75 and many others are representable exactly (basically since
they all equal an integer divided by some power of 2); but 3.6 and 3.8 and an infinite
number of other values are not.
Now whatever float/double function you call, if it returns a float/double will suffer
from the same phenomenon. So the only way to really get "3.6" or "3.8" is by using a
function that not only rounds but returns a string. I trust there are some formatting
methods that do just that in every programming language; In .NET languages
ToString() should be one of them, given an appropriate format specifier.
If you want to know much more about this topic, here it is:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
BTW: to circumvent the floating-point rounding problem, especially for monetary
numbers, they introduced the "decimal" data type (which basically stores decimal
digits).
|
|
|
|
|
hi
I started to work with the VS2008 & FrameWork 3.5
if i want that my programs will run on any computer i need the FrameWork 3.5
is it weight so match? 200MB ???
there is version that weight 2.5MB but the installation is from the WEB
is there any version of FrameWork 3.5 that weight less then 200MB ? and don't need installation
from the WEB ?
thank's
|
|
|
|
|
E_Gold wrote: is it weight so match? 200MB ???
It doesn't "weigh" that much. Remember that it only has to be installed once regardless of how many .NET 3.5 applicaitons get installed on the PC.
E_Gold wrote: there is version that weight 2.5MB but the installation is from the WEB
No. That is a bootstrapper. The bootstrapper is 2.7Mb. The actual .NET Framework is still the same size. You just have an easier download.
E_Gold wrote: is there any version of FrameWork 3.5 that weight less then 200MB ?
Yes, the version you quote, pedantically speaking, "weighs" less than 200Mb. It is only 197Mb
|
|
|
|
|
E_Gold wrote: there is version that weight 2.5MB but the installation is from the WEB
Like Colin said, that is just for doing web-based install. You still have to install the rest through the setup program.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
using System;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Collections.Specialized;
using System.Web;
namespace Snowball.Common
{
///
/// Submits post data to a url.
///
public class PostSubmitter
{
public int byteleng;
///
/// determines what type of post to perform.
///
public enum PostTypeEnum
{
///
/// Does a get against the source.
///
Get,
///
/// Does a post against the source.
///
Post
}
private string m_url = string.Empty;
private NameValueCollection m_values = new NameValueCollection();
private PostTypeEnum m_type = PostTypeEnum.Get;
///
/// Default constructor.
///
public PostSubmitter()
{
}
///
/// Constructor that accepts a url as a parameter
///
/// <param name="url" />The url where the post will be submitted to.
public PostSubmitter(string url)
: this()
{
m_url = url;
}
///
/// Constructor allowing the setting of the url and items to post.
///
/// <param name="url" />the url for the post.
/// <param name="values" />The values for the post.
public PostSubmitter(string url, NameValueCollection values)
: this(url)
{
m_values = values;
}
///
/// Gets or sets the url to submit the post to.
///
public string Url
{
get
{
return m_url;
}
set
{
m_url = value;
}
}
///
/// Gets or sets the name value collection of items to post.
///
public NameValueCollection PostItems
{
get
{
return m_values;
}
set
{
m_values = value;
}
}
///
/// Gets or sets the type of action to perform against the url.
///
public PostTypeEnum Type
{
get
{
return m_type;
}
set
{
m_type = value;
}
}
///
/// Posts the supplied data to specified url.
///
/// <returns>a string containing the result of the post.
public string Post()
{
StringBuilder parameters = new StringBuilder();
for (int i = 0; i < m_values.Count; i++)
{
EncodeAndAddItem(ref parameters, m_values.GetKey(i), m_values[i]);
}
string result = PostData(m_url, parameters.ToString());
return result;
}
///
/// Posts the supplied data to specified url.
///
/// <param name="url" />The url to post to.
/// <returns>a string containing the result of the post.
public string Post(string url)
{
m_url = url;
return this.Post();
}
///
/// Posts the supplied data to specified url.
///
/// <param name="url" />The url to post to.
/// <param name="values" />The values to post.
/// <returns>a string containing the result of the post.
public string Post(string url, NameValueCollection values)
{
m_values = values;
return this.Post(url);
}
///
/// Posts data to a specified url. Note that this assumes that you have already url encoded the post data.
///
/// <param name="postData" />The data to post.
/// <param name="url" />the url to post to.multipart/form-data; boundary=
/// <returns>Returns the result of the post.
private string PostData(string url, string postData)
{
// string sa="";
HttpWebRequest request = null;
if (m_type == PostTypeEnum.Post)
{
Uri uri = new Uri(url);
request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytess = encoding.GetBytes(postData);
request.ContentType = "multipart/form-data; boundary=" + "---------------------" + DateTime.Now.Ticks.ToString("x"); //;//application/x-www-form-urlencoded
request.ContentLength = bytess.Length;// postData.Length;
using (Stream writeStream = request.GetRequestStream())
{
UTF8Encoding encoding1 = new UTF8Encoding();
byte[] bytes = encoding1.GetBytes(postData);
writeStream.Write(bytes, 0, bytes.Length);
}
}
else
{
Uri uri = new Uri(url + "?" + postData);
request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
}
string result = string.Empty;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
{
result = readStream.ReadToEnd();
}
}
}
return result;
}
///
/// Encodes an item and ads it to the string.
///
/// <param name="baseRequest" />The previously encoded data.
/// <param name="dataItem" />The data to encode.
/// <returns>A string containing the old data and the previously encoded data.
private void EncodeAndAddItem(ref StringBuilder baseRequest, string key, string dataItem)
{
if (baseRequest == null)
{
baseRequest = new StringBuilder();
}
if (baseRequest.Length != 0)
{
baseRequest.Append("&");
}
baseRequest.Append(key);
baseRequest.Append("=");
baseRequest.Append(System.Web.HttpUtility.UrlEncode(dataItem));
}
}
}
--------------
byte[] Image = (byte[])ImagePicture;
string picture1 = Convert.ToBase64String(Image);
PostSubmitter post = new PostSubmitter();
post.Url = "http://.....";
post.PostItems.Add("Body/ad/category_id", "2");
post.PostItems.Add("Body/ad/language_code", "1");
post.PostItems.Add("Body/ad/format", "1");
post.PostItems.Add("Body/ad/price_type", "1");
post.PostItems.Add("Body/ad/ask_price", "112345.67");
post.PostItems.Add("Body/ad/title", "TEST IT-Pictures");
post.PostItems.Add("Body/ad/description", "TEST IT-Pictures");
post.PostItems.Add("Body/image1", picture1);
post.Type = PostSubmitter.PostTypeEnum.Post;
string result = post.Post();
It outputs an error! Help, what's wrong, I think that erroc in
private string PostData(string url, string postData)
and exactly in this string:
request.ContentType = "multipart/form-data; boundary=" + "---------------------" + DateTime.Now.Ticks.ToString("x");
|
|
|
|
|
cd_dvd wrote: It outputs an error!
What error?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
There is no error in the code(the compilation results in 0 errors), but the result is not the one I want.
It should send information with a picture, but the server don't received anything. When I send data with method
application/x-www-form-urlencoded this code sended all information without a picture. The picture should be send as multipart/form-data. When using "application/x-www-form-urlencoded" the response from server contained the ID of the record added, but the picture wasn't.
|
|
|
|
|
I would like to have a method that does something like the following,
public static object foo(object A, Type T) {
return (T)A;
} I don't explicitly know the type T anywhere in my code... it is found at runtime, so I CAN'T do the following (unless there is some way to send TObject.GetType() as T):
public static T foo<T>(object A) {
return (T)A;
} Oh, and object A cannot implement the IConvertable Interface (or any interface, for that matter, since I have NO control over the class), so I am unable to use the System.Convert.ChangeType method as well. I DO however know that either
1: type T defines an explicit cast operator from AType->T, OR
2: type AType defines an explicit cast operator from AType->T
but I can't figure out how to call that cast with the information I have. Does anyone know a way that I can accomplish this? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Have you tried the "ChangeType" method of the "Convert" class?
It seems to be exactly your foo
|
|
|
|
|
"Convert.ChangeType" seems to be exactly your foo
|
|
|
|