|
You might want to take a look here[^].
|
|
|
|
|
You know how some website login forms change the color of textboxes you left empty to red?
I want to do that in my application.
Basically after entering data you can click a "check" button that is supposed to highlight empty textboxes in red.
I tried using a graphics object and draw rectangles above the textboxes, but it doesn't work well. Not the entire border is highlighted, but only the right and lower side.
|
|
|
|
|
Well,
I haven't done that but I must ask, why not use an error provider?
Just find the Error Provider[^] in your toolbox and drop one on your form.
Then you can use something like this to set the error when they click 'check'.
myErrorProvider.SetError(myTextBox, "Not Valid");
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
|
Another possibility is to place an asterisk (* ) in the text or color the boxes when the form is populated. Then in the Validating event, change the color, etc. if the result is valid. The color can be changed by setting the BackColor property, but you may need to refresh or Invalidate() the control to see the change.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
if it is a website, I would do this in client side code instead of server code. (saves a round trip to the server)
Add a validation function that is called on the onchange event for that control that will do some basic checking (empty fields, phone number formatting, etc...) and color the control accordingly. Alternatively you can skip the onchange event and put the validation when the form is submitted.
V.
|
|
|
|
|
It's not a website, it's a windows forms app.
I'm currently changing the backcolor to red and forecolor to white (when you change the text, the color also changes back to normal) but that looks kinda awkward.
If possible I'd like to use the more elegant way of just coloring the frame of the textbox/drawing a frame around it.
How does the blinking look? It's quite possible that there'd be like 5 textboxes on a form which require input and all of them blinking at the same time would probably weird and confusing.
I want a simple, yet obvious visual hint that there is something wrong.
|
|
|
|
|
Then use the ErrorProvider, just run some tests.
The ErrorProvider, see my previous reply, is a windows forms control so i dont really understand the
Megidolaon wrote: It's not a website, it's a windows forms app.
comment
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
One day somehow i was ended up downloading microsoft C# learning. It had bunch of modules. But those are no longer available to download. Does anyone know how can we download. It was great telling everything visually.
Some of these courses are here but they charge
link
|
|
|
|
|
You haven't said exactly what you downloaded or where you got it from. Therefore, it's impossible for anyone to know what you're talking about or how to help you.
|
|
|
|
|
can I make zooming in the form itself ?
hi,
I have the following problem , I am reading from serial port and draw plots from the serial port in the form and no problem with flicker (I am enable doublebuffersize property) after doing this i does n't have any problem but the problem come when i want to make zooming in the form so I am draw in panel or picturebox but the problem of flicker appear as long as i am extend picturebox as a control and add in the constructor the following method :
Code:
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
so my question can I make zooming in the form itself if i can not what is the solution for flicker ?
|
|
|
|
|
Usually flickering occurs from trying to redraw the entire area. Make sure you only invalidate the regions that need to be invalidated instead of the entire control. That is the only way, in GDI+, to control flicker that I have found. If you need really fast drawing code (more than 15FPS) you need to use DirectX or OpenGL.
|
|
|
|
|
I guess this is quite obvious, but besides making sure that you only redraw the desired area and not the whole control, make sure that you are not reading from the serial port un the UI thread.
Long processes can interfere with the drawing of the form.
|
|
|
|
|
Hi There,
I created a ComboBox by dropping the table onto the form from "datasources"(First set type to combo). The Data displayes correctly but when I use the dropdown it tries to insert the selected value into the dataset (which obviously already exists so it throws an exception) I have not set the update/insert text on the table adapter and "allownew" property is set to no. I just want the combo to display the table content and get a selection from it afterwards, but I don't want the combo changing the dataset itsself. Why does it do this?
Kind regards
Shane Scott
|
|
|
|
|
Because data binding sucks.
The better answer is that data binding and combo boxes really sucks. I usually give up with regard to combo boxes because they are so easy to use without binding, in-fact, it takes less code and no effort to understand. One thing you can try is to change the type of your combo box to Drop Down list.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: Because data binding sucks
I thought it was just me!
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
I always use a manual data-bindings ,
Because it's had a very ugly behavior with some control ( like Comboboxs, DateTime Controls , etc ) ....
I know nothing , I know nothing ...
|
|
|
|
|
DaveyM69 wrote: Ennis Ray Lynch, Jr. wrote:
Because data binding sucks
I thought it was just me!
What? You think you're the only thing that sucks?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Ok I found out how to do this:
WITHOUT DOING THIS DRAGGING DATASET TABLES TO THE FORM AS COMBO BOXES WILL NOT WORK AS EXPECTED!
1. Open datasource explorer
2. presuming you've got vs pro drag a odbc data table to the form (after right clicking and setting component to combo)
3. set display memember and value member
4. exit wiz and go to the combo properties
5. expand the databindings list
6. set everything to 'none'
7. the disply and value settings remain as they are properties of ComboBox and not ComboBox.DataBindings
8.???
9.Profit!!!
microsoft has not thought out the logic of having a combo with dual values such as (id_PK, description) being reinserted everytime a user makes that selection in the combo. it makes no sence at all but by following the above you can avoid it and just use the combo for selection and display.
Peace and thanks for being willing to help. It really is a niffty feature being able to drag datatables to the form and having them appear as combos, you just have to know how, and the fact that theres no documentation doesn't make it easier.
|
|
|
|
|
Hi
I'm trying to implement OAuth using Google's implementation. First of all I create a few of the parameters using methods from OAuthBase.cs as follows:
string consumerKey = "anonymous";
string consumerSecret = "anonymous";
Uri uri = new Uri("https://www.google.com/accounts/OAuthGetRequestToken");
OAuthBase oAuth = new OAuthBase();
string nonce = oAuth.GenerateNonce();
string timeStamp = oAuth.GenerateTimeStamp();
string str = "https://www.google.com/accounts/OAuthGetRequestToken";
string str2 = "oauth_consumer_key=www.google.com&oauth_nonce=1932530&oauth_timestamp=1277400332&oauth_signature_method=HMAC-SHA1&oauth_version=1.0";
and the methods in the OAuthBase class:
public virtual string GenerateNonce()
{
return random.Next(123400, 9999999).ToString();
}
public virtual string GenerateTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
string timeStamp = ts.TotalSeconds.ToString();
timeStamp = timeStamp.Substring(0, timeStamp.IndexOf("."));
return timeStamp;
}
Then I create the signature as follows:
string sig = oAuth.GenerateSignature(uri,
consumerKey, consumerSecret,
string.Empty, string.Empty,
"GET", timeStamp, nonce,
OAuthBase.SignatureTypes.HMACSHA1, out str, out str2 );
using this method from OAuthBase.cs:
public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, SignatureTypes signatureType, out string normalizedUrl, out string normalizedRequestParameters)
{
normalizedUrl = null;
normalizedRequestParameters = null;
switch (signatureType)
{
case SignatureTypes.PLAINTEXT:
return HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret));
case SignatureTypes.HMACSHA1:
string signatureBase = GenerateSignatureBase(url, consumerKey, token, tokenSecret, httpMethod, timeStamp, nonce, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters);
HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncode(tokenSecret)));
return GenerateSignatureUsingHash(signatureBase, hmacsha1);
case SignatureTypes.RSASHA1:
throw new NotImplementedException();
default:
throw new ArgumentException("Unknown signature type", "signatureType");
}
}
Here is the GenerateSignatureBase method that gets called if the signature type equals HMACSHA1:
public string GenerateSignatureBase(Uri url, string consumerKey, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, string signatureType, out string normalizedUrl, out string normalizedRequestParameters) {
if (token == null) {
token = string.Empty;
}
if (tokenSecret == null) {
tokenSecret = string.Empty;
}
if (string.IsNullOrEmpty(consumerKey)) {
throw new ArgumentNullException("consumerKey");
}
if (string.IsNullOrEmpty(httpMethod)) {
throw new ArgumentNullException("httpMethod");
}
if (string.IsNullOrEmpty(signatureType)) {
throw new ArgumentNullException("signatureType");
}
normalizedUrl = null;
normalizedRequestParameters = null;
List<QueryParameter> parameters = GetQueryParameters(url.Query);
parameters.Add(new QueryParameter(OAuthVersionKey, OAuthVersion));
parameters.Add(new QueryParameter(OAuthNonceKey, nonce));
parameters.Add(new QueryParameter(OAuthTimestampKey, timeStamp));
parameters.Add(new QueryParameter(OAuthSignatureMethodKey, signatureType));
parameters.Add(new QueryParameter(OAuthConsumerKeyKey, consumerKey));
if (!string.IsNullOrEmpty(token)) {
parameters.Add(new QueryParameter(OAuthTokenKey, token));
}
parameters.Sort(new QueryParameterComparer());
normalizedUrl = string.Format("{0}://{1}", url.Scheme, url.Host);
if (!((url.Scheme == "http" && url.Port == 80) || (url.Scheme == "https" && url.Port == 443)))
{
normalizedUrl += ":" + url.Port;
}
normalizedUrl += url.AbsolutePath;
normalizedRequestParameters = NormalizeRequestParameters(parameters);
StringBuilder signatureBase = new StringBuilder();
signatureBase.AppendFormat("{0}&", httpMethod.ToUpper());
signatureBase.AppendFormat("{0}&", UrlEncode(normalizedUrl));
signatureBase.AppendFormat("{0}", UrlEncode(normalizedRequestParameters));
return signatureBase.ToString();
}
I then use the string builder to build the string that I will pass to the WebRequest as follows:
sig = HttpUtility.UrlEncode(sig);
StringBuilder sb = new StringBuilder(uri.ToString());
sb.AppendFormat("?oauth_consumer_key={0}&", consumerKey);
sb.AppendFormat("oauth_nonce={0}&", nonce);
sb.AppendFormat("oauth_timestamp={0}&", timeStamp);
sb.AppendFormat("oauth_signature_method={0}&", "HMAC-SHA1");
sb.AppendFormat("oauth_version={0}&", "1.0");
sb.AppendFormat("scope={0}&", "https://mail.google.com/mail/feed/atom");
sb.AppendFormat("oauth_signature={0}", sig);
I then create a WebRequest as follows and pass it the string:
string s = sb.ToString();
WebRequest w = WebRequest.Create(s);
..where 'string s' equals:
"https://www.google.com/accounts/OAuthGetRequestToken?oauth_consumer_key=anonymous&oauth_nonce=1221378&oauth_timestamp=1277825766&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&scope=https://mail.google.com/mail/feed/atom&oauth_signature=n5HsVCqhujRoMzBKbRXa%2fC6hk2M%3d"
As soon as I call:
Stream objStream = w.GetResponse().GetResponseStream();
I get the following error: The remote server returned an error: (400) Bad Request.
So please could anyone tell me whether you can see what's wrong with my code or the string that I pass in.
|
|
|
|
|
If you copy and paste your generated url into the browser you should get a better error. I get:
Timestamp is too far from current time: 1277830114
|
|
|
|
|
I simply get a HTTP 400 error
|
|
|
|
|
Building on the excellent work by Ennis:
Etienne_123 wrote: TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
I think the problem is one of those DateTimes is UTC, the other isn't.
[ADDED] Obviously a timespan is location-independent, it should be based on consistent data though [/ADDED]
|
|
|
|
|
Thanks for the reply. I tried using this:
DateTime dn = DateTime.Now;
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan tss = dn.Subtract(dt);
string timespan = tss.TotalSeconds.ToString();
..still does not work. I'm doing it according to the specifications laid out here[^], which specifies that "Unless otherwise specified by the Service Provider, the timestamp is expressed in the number of seconds since January 1, 1970 00:00:00 GMT. The timestamp value MUST be a positive integer and MUST be equal or greater than the timestamp used in previous requests" . Could it be that Google requires a different timestamp?
|
|
|
|
|