|
for(int i = 1; i<4; i++)
{
if(this.textBox1.Text.Length >50)
{
/// do something
}
}
|
|
|
|
|
Nah - that will just do the same thing 3 times to one textBox (viz textBox1).
I want to do one thing on three textboxes viz (textBox1, textBox2 and textBox3).
Glen Harvy
|
|
|
|
|
Ahh.. I misunderstood the question..
|
|
|
|
|
Put references to the textboxes in an array:
TextBox[] boxes = new TextBox[] { TextBox1, TextBox2, TextBox3 };
Now you can address the textboxes by index by using the array.
---
single minded; short sighted; long gone;
|
|
|
|
|
|
Assuming you stick with the naming convention, one way would be to iterate over the controls collection and look for the textboxes by name as you go. You could also just look for all textboxes, no matter what they are named, if you want them all.
foreach(Control control in Controls)
{
TextBox tb = control as TextBox;
if (tb != null && tb.Text.Length > 50)
{
// do something
}
}
The beauty of this approach is you don't need to build any array, there's no code to add if you change the textboxes on teh form.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i have created a usercontrol in .Net and im adding that control from code behind of the webform,i have created some properties in the user controls .How do i access those property from the code behind of my web form?
people laugh at me because they say im different and I laugh at them because they are all the same.
|
|
|
|
|
You would have to declare those properties as Public within the userControl first. Then when you've added the control you can access the properties from the new object once its added.
|
|
|
|
|
As mentioned in the title.
How to get computer current time?
|
|
|
|
|
DateTime.Now gives you an instance of the DateTime structure with the current date and time.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
How can I sort the contents (string) in ListBox or ListView by column like for example the details view in Windows Explorer?
_____________________________
...and justice for all
APe
|
|
|
|
|
Hi, Any One has concpts or sample about building Combo Box with Checked drop down list in C# .
Thanks in Advance.
very Good for this Site
|
|
|
|
|
Listen to the drop down event handler (or through WndProc for that matter), and when the event occurs place your checked drop down control near the combobox if not touching the bottom left corner of the combo box. Exit the method prematurely so that the default combo box drop down does not show.
I may have an example of a control that I have wrote lying around somewhere to post.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
I'm trying to make a simple application that enables easy access to certain folders, bluntly, you click a button, and Windows opens an assigned folder for you. Any hints or tips will be highly appreciated. Thank you.
|
|
|
|
|
Process.Start should take a folder path, and open it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
I am trying to make an addin for a program using C#, is there anyway to follow the execution of the dll in the hosting program using Visual Studio .NET? Is there anyway I can set breakpoints and watch variables?? Any help is appreciated.
|
|
|
|
|
If the program is yours, make the dll part of the same solution. If it's not, attach the debugger to the program, and it will stop at breakpoints in your dll.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks for replying. The program isn't mine, and I just don't know how to attach the debugger to the program.
|
|
|
|
|
Attach is the third option in the debug menu.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
while using try-catch combination, I've assign a value to a reference type variable within
try block, but when I tried to use this variable within catch block it throw an exception (NullRefrenceException) or an error (use of unassigned local variable) occur.
my question is: the variables that has been declared, or had values assigned
for them in try block, how to deal with them in catch block.
the code I'm working on :
int i =0;
Socket remote;
try
{
remote = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
i = 5;
}
catch(Exception ee)
{
MessageBox.Show(i.ToString());
MessageBox.Show(remote.ToString());
} and why is that when i used a value type variable it works well.
|
|
|
|
|
remote is going to be null, given that you've had an exception, and it's not likely that i=5 threw it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
well, that is my qustion.
i need to assign a value to 'remote' in try block, and then use that value within catch block.
is there any direct way, or trick to do so.
|
|
|
|
|
Yes, make a call to the remote constructor which does not fail. There's no rocket science here. It's null going in, your attempt to assign a value is failing, and so it's still null. The fault is in your code, it needs to not make assumptions about things that may not have happened, because you were in a try block.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hussam Fattahi wrote: i need to assign a value to 'remote' in try block, and then use that value within catch block.
Usually the only things you would need to do in the catch block are cleanup type activities. If you are trying to show the error message to the user you should be doing something like this:
int i =0;
Socket remote = null;
try
{
remote = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
i = 5;
}
catch(Exception ee)
{
MessageBox.Show(i.ToString());
MessageBox.Show(ee.Message);
} The Socket remote = null; will remove the compiler issue about using an unassigned variable. Any variable that is used inside of a catch block must be explicitly assigned prior to it being used.
If the call to remote = new Socket(...) fails for any reason, remote will be null (in all cases), you will take an exception that puts you in your catch handler. At that point, remote is still null, so you are trying to run ToString() on a null reference, which you can't do.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|