|
well, thank you very much for trying.
i realize it's not that hard to answer this,
character casing properties fix my problem.
modify :
"i'm not sure i need to create a new thread just to force a textbox uppercase."
thank you for the reply, but i'm sure you understand it.
don't worry, next time i will write it more detail.
modified 28-Jul-12 0:13am.
|
|
|
|
|
Midnight Ahri wrote: this.txtLicense.Text = uppercase;
What does this line do, besides the obvious things? Well, it sets the value of a textbox.
..which means that the value has changed. If the value changes, the Framework will trigger the "textbox_textchanged" event. So, we execute that code - which tells us to change the value again. (See a pattern?)
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
After the second bounce the value will not change so the event shouldn't fire forever.
|
|
|
|
|
Does the setter of the text-property of the textbox include a check to see whether the value is the same, or not?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
It should, at least for the TextChanged event (the clue's in the name!), but I haven't actually tested it right now.
|
|
|
|
|
BobJanova wrote: It should, at least for the TextChanged event (the clue's in the name!)
The times that I programmed against a intID where the clue in the name was erroneous..
You are right, I decompiled the TextBox, which points to TextBoxBase, which has this in the setter implementation;
this.has_been_focused = false;
if (value == this.Text)
{
return;
}
(Śtill untested)
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Is this a desktop or web app?
|
|
|
|
|
Probably a bit late now, but the normal way to do this is to intercept the character before it makes it into textbox rather than trying to alter it once its there.
To do this, you want to intercept the WM_CHAR message (either by hooking the event KeyPress at form level of overriding a virtual OnKeyPress(Or similiar?) in a class deriving from TextBox. Then check the character and if its in the range a-z alter it to be A-Z (By subtracting 32 simplest way if ASCII).
edit: That is of course assuming this is Winforms, an assumption I may have jumped on too soon as Bob mentions above.
Regards,
Rob Philpott.
|
|
|
|
|
Hi Friends,
I am trying to create a new thread to make the picturebox is visible (to show Loading icon) when the ConvertFiles method is running, but it is not successful (Please see below codes)
Do you know what's wrong ?
private void ShowLoadingIcon()
{
if (InvokeRequired)
{
this.Invoke (new MethodInvoker( ShowLoadingIcon));
}
else
{
pixLoadingIcon.Visible = true;
}
}
private void btnConvert_Click(object sender, EventArgs e)
{
Thread thLoading = new Thread(ShowLoadingIcon);
thLoading.Start();
ConvertFiles(sourceFile, destinationFile);
}
Thanks and regards,
|
|
|
|
|
taibc wrote: but it is not successful
What does this mean? The thread does not start? The thread starts but does not do anything? The code runs and your cat died? "it's not successful" does not tell us anything about what your problem is. Did you run it through a debugger? What did you discover?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
I think you are doing this backwards. The invoke back to the UI thread will be blocked until your long processing task is finished.
You should actually be trying to do something like this
string sourceFile, destinationFile;
private void ShowLoadingIcon()
{
if (InvokeRequired)
{
this.Invoke(new MethodInvoker(ShowLoadingIcon));
}
else
{
pixLoadingIcon.Visible = true;
}
}
private void btnConvert_Click(object sender, EventArgs e)
{
ShowLoadingIcon();
System.Threading.Thread t = new System.Threading.Thread(() =>
{
ConvertFiles(sourceFile, destinationFile);
});
t.Start();
}
private void ConvertFiles(string src, string dest)
{
}
|
|
|
|
|
Great ! It is successful now.
Thanks Trak4Net very much.
|
|
|
|
|
Hi Trak4Net,
When running the new thread, I got the bellow error:
"{Text = '((System.Windows.Forms.TextBox)(txtLopDiaChi)).Text' threw an exception of type 'Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException'} System.Windows.Forms.TextBox
"
Do you know how to fix it ?
Thanks and regards,
|
|
|
|
|
You should read up about making thread-safe calls to controls here is one link http://msdn.microsoft.com/en-us/library/ms171728.aspx[^]
Anytime you access a control from a thread other than the thread the control was created on you will need to use Invoke or BeginInvoke to modify. Usually if there are several common controls I create a method that accepts a control as a parameter as well as the text to set and inside that method it checks if invoke is required.
Here is an example of something you could do. You don't show enough code to know exactly what you are trying but this can be modified to work with different controls etc.
Hope this is helpful.
private delegate void ChangeTextDel(System.Windows.Forms.TextBox obj, string newtext);
private void ChangeText(System.Windows.Forms.TextBox obj, string newtext)
{
if (obj.InvokeRequired)
{
obj.Invoke(new ChangeTextDel(ChangeText), new object[] { obj, newtext });
}
else
{
obj.Text = newtext;
}
}
ChangeText(txtLopDiaChi, "my new text value");
|
|
|
|
|
Thank you.
I resolved this error earlier.
Kind regards,
Tai
|
|
|
|
|
Hi,
I am searching for MDI child using this code and activating it when exists.
I want to know how can I set label text before the search_form.Activate() line? I tried search_form.lblFindWhat.Text = "something" but it was not recognized although i set the lblFindWhat Modifier to Public.
here is the code:
foreach (Form search_form in this.MdiChildren)
{
if ((string)search_form.Tag == "BROWSE_PATIENTS")
{
search_form.lblFindWhat.Text = "something";
search_form.Activate();
is_form_exists = true;
break;
}
}
|
|
|
|
|
What do you mean by "but it was not recognized"? Did the code compile?
/ravi
|
|
|
|
|
I mean getting this error:
Error 9
|
|
|
|
|
The compiler is correct. A Form doesn't define a lblFindWhat member. You need to cast search_form to the specialized type of the form you're using before accessing its lblFindWhat member.
/ravi
|
|
|
|
|
Please, don't set controls to public - it fixes the design of the form, because you can't change the label out without it affecting (and possibly breaking) outside objects.
Instead, create a public property which allows access, and set the label text yourself within the property. That way, you can replace the label with a more suitable control at some future date, and nothing gets changed outside.
In your search form:
public string Prompt
{
get { return myLabel.Text; }
set { myLable.Text = value; }
}
In your external class:
search_form.Prompt = "something";
The next problem is that a Form does not contain your controls. You have to cast it to an instance of your search form before the compiler can know what it contains:
foreach (Form form in this.MdiChildren)
{
MySearchForm search_form = form as MySearchForm;
if (search_form != null && (string)search_form.Tag == "BROWSE_PATIENTS")
{
search_form.Prompt = "something";
search_form.Activate();
is_form_exists = true;
break;
}
}
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Ugh. I should've just pointed the OP to your post.
/ravi
|
|
|
|
|
I do it all the time...
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I'm still new, so I don't know if this is the best way to do what I am needing, and would like some feedback/advice.
I have a class that contains a double value. This double could represent a dollar value or it could represent a percentage value. Only one or the other, it will never have both. At runtime, I will need to be able to tell what type of value this is. Here is what I came up with, which appears to work, but if there is a better way, I would prefer that.
public class Rate
{
public double Value;
}
public class RateDollar : Rate {}
public class RatePercentage : Rate {}
public class TransactionLine
{
public Rate Amount;
}
myTransactionLine.Amount = new RateDollar();
if(myTransactionLine.Amount.GetType() == typeof(RateDollar))
if(myTransactionLine.Amount.GetType() == typeof(RatePercent))
For some reason, this seems like it is a clunky workaround. It also seems like it's possible for someone to create the value that is neither a RateDollar or RatePercent, and just as a plain Rate. Is there some way to prevent this, or is there a better way to accomplish what I am trying to do?
|
|
|
|
|
It doesn't make much sense to have a Rate class if all it does is contain a double. Is there more to it then that? Is the Rate used elsewhere? I'm gonna go out on a limb and say that TransactionLine should just have a double Rate property and a RateType enum property that says whether its a % or $ amount.
|
|
|
|
|
Thanks for the response! The enum seems like it would be a simpler way to handle this. Since the Rate may be used in multiple different classes, I think I should go with an enum in the Rate class.
public enum ENRateType { Dollar, Percent }
public class Rate
{
public ENRateType RateType;
public double Rate;
}
|
|
|
|