|
I have a textbox that needs to accept the format: 00:00:00
I would like for the format to be "Locked." Therefore, forcing the user to keep the values in this format. For example, when the textbox shows up, it automatically displays 00:00:00. And the user MUST put values in each place or leave them "0." I took a look at the DateTime method. However, it doesn't seem to do what I am looking for. Also, all values entered can only be 0 - 9. Thanks in advance.
D
|
|
|
|
|
What you are looking for is a "masked edit control". Searching here at CodeProject or on Google will list many of them!
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
I can aso use rgular esxpressions whit the System.Text.RegularExpressions.RegEx.Ismatch method.
Here is one string pattern to use: "^(20|21|22|23|[01]\d|\d)(([:.][0-5]\d){1,2})$"
You can see more at: http://www.regexlib.com/DisplayPatterns.aspx[^]
Happy coding!
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
Hello,
Is there a way to create a working installer for a snapin? I've created a snapin but I can't create a working installer Has one of you guys ever delt with this problem? Is there a solution?
10x guys
Larry
--
|
|
|
|
|
Hello,
I have a question regarding the inheritance of a sealed class. I would really want to know if it is possible inherit from FolderBrowserDialog. I want to extend the FolderBrowserDialog to do some checkings of the selected folder and to enable/disable the OK button. How can I do that in C#?
Larry
|
|
|
|
|
Hai
Is there any way to find the line number & Source code that cause excpetion.
i mean in the code i need to get these things in seperate variables.
string linenumber = 'line number'
string expCode = ' code that leads to exception'
Thanks and Regards
|
|
|
|
|
You can get this information from Exception.ToString() if you look to the end of the string you will see somthing like form1.cs:line 524 so to get line number you can write code in your exception handling code somthig like
catch(Exception ex)
{
string strExc=ex.ToString();
int pos=strExc.IndexOf(":line",0);
if(pos != -1)
{
MessageBox.Show(strExc.Substring(pos+5,strExc.Length-(pos+5)));
}
}
Note: in relase mode this inoformation will not generated to enable it in your project Build configration check Generate debugging information look at Printing Line Number with an exception in Release Mode[^] for more informaton
MCAD
-- modified at 13:04 Wednesday 7th September, 2005
|
|
|
|
|
Hi All,
I was just wondering how to invoke a process under different security context with the specified credentials over network only, I used P/Invoke to call CreatProcessWithLogonW but since I had to use it with ASP.NET application p/Invoke was failing though It was working fine with Desktop application (Probably due to some security problems of IIS), I came to know that in .net2.0 things are pretty simple and I need to call only Static member Start of Process class by passing credentials but this is not invoking process instead I am getting error logon failure, I suppose this problem is becuase I don't know how to set logon flags which we could set in createprocesswithlogonw function..Can anyone tell me how to start a process using the specified credentials on the network only in .net2.0.
Regards,
Ruchir Dhar Dwivedi
Software Engineer
5th floor Marisoft, Cybage Software Pvt. Ltd., Kalyani Nagar, PUNE - 4 1 1 0 0 6, I N D I A
Phone(O) : 91-20-56041700,91-20-56044700 Extn 830 | AIM : RuchirAIM | cell : 09890939702
mail to : ruchird@cybage.com | www.cybage.com
|
|
|
|
|
Sorry guy, im new in c#
Im using vs.net
Is there a way to update the input of a text box from a class that not in the main form1.cs? my additional class is suppose to update a status text box when a msg is sent.. any hint guys?
I suck at coding and only familar with C.. now trying out c#
string test=("listening:");
Form1.StatusText= test;//string.Copy("Listening..:");
|
|
|
|
|
It is possible to update the text of a text box in the main form from another class in the application. Proceed something like this…
string test = "Listening:";
Form currentForm = Form.ActiveForm;
((Form1)currentForm).StatusText.Text = test;
Regards,
Ashok Dhamija
_____________________________
Padam Technologies
-- modified at 5:12 Wednesday 7th September, 2005
|
|
|
|
|
C:\Documents and Settings\Desktop\C# CLASS\ClientWithDialog\cApplication.cs(29): The name 'currentForm' does not exist in the class or namespace 'ClientWithDialog.cApplication'
C:\Documents and Settings\Desktop\C# CLASS\ClientWithDialog\cApplication.cs(28): The type or namespace name 'Form' could not be found (are you missing a using directive or an assembly reference?)
This are my error..
The situtation is this.. i got a console program. which im tryin to rewrite into a application base one.
it a simple tcp/ip program
where by the StatusText textbox is suppose to change according to what the class throw at..
example when connected..( procedure in class)
it suppose to update the status text box in the form i created.
hope for some hint
|
|
|
|
|
As you had not mentioned that it is a console application and as you had referred to your main Form as Form1 in your sample code, I had presumed that you are using a Windows Forms application. In a forms application, the error mentioned by you is due to the missing "using" statement. Use the following "using" statement at the top of the class coding:
using System.Windows.Forms;
But, in the situation described by you, and to the extent I could understand your problem, you should have the reference to the instance of Form1 on which the "StatusText" textbox lies, and then may simply use code like this:
string test = "Listening:";
Form1.StatusText.Text = test;
Hope it works.
Regards,
Ashok Dhamija
_____________________________
Padam Technologies
|
|
|
|
|
Thanks man.. i actually did try that and the error was
private System.Windows.Forms.TextBox StatusText;
there for i change the PRIVATE to PUBLIC..
and then the error was.
C:\Documents and Settings\Desktop\ClientWithDialog\cApplication.cs(28): An object reference is required for the nonstatic field, method, or property 'ClientWithDialog.Form1.StatusText'
Therefor i try
Form1.StatusText.Text = test;
and
ClientWithDialog.Form1.StatusText.Text = test;
sorry for all the trouble. hope for so advice..
thanks again
|
|
|
|
|
The present I'm making application so get data from com port which write by C#
But I don't know ! Help me
Everyone can send for me Example.
Thank you very much!
|
|
|
|
|
http://www.codeproject.com/dotnet/DotNetComPorts.asp
has some info on this,
HTH
Russ
|
|
|
|
|
Hi, im pretty new to c# and have a data management question.
I have a windows application and 2 forms.
Form A is the main application form and form B is opened from form A and contains
a CheckedListBox with 5 selections.
Now my problem is that when ive checked my coices and close form B, i need to get the data from form B and update some events based on the choices in form A.
I opened an instance like this:
GetForm getForm = new GetForm();
getForm.Show();
But i guess i have to have a check like this:
if (getForm.ClickedOK() == true) { process data }
And some way to retrieve the checkedlists to read them in form A.
Also, how can i show form B in a modal way?
Thanks in advance
/Johan
|
|
|
|
|
ok to show the form in a modal way use ShowDialog() instead of Show().
To get the values of B into A you could try something like -
//in FormA code
FormB fb = new FormB(this); //pass FormA object as a parameter to FormB
fb.ShowDialog();
//in FormB code
private void getForm_Ok_buttonClick(object o,eventArg e)
{
FormA.requiredValues = FormB.checkedValues;
}
|
|
|
|
|
Thanks.
Although i tried to pass the main form before as an object the compiler wont allow it since its read-only (i must pass it as a ref).
I COULD pass form A´s items separately to be updated to form B,
but it involves over 40 textfields and it would get pretty ugly.
Any other ideas?
|
|
|
|
|
I am putting a slightly modified form of the code submitted in another reply to your query, and I think it should solve your problem:
FormB fb = new FormB();
DialogResult result = fb.ShowDialog();
if(result == DialogResult.OK)
{
FormA.requiredValues = FormB.checkedValues;
}
Regards,
Ashok Dhamija
_____________________________
Padam Technologies
|
|
|
|
|
I am using a datareader to read cells in a database. Here are a few pieces of my code, what is wrong?
using System;<br />
using System.Data;<br />
using System.Data.OleDb;<br />
<br />
string szQUser = txtUser.Text;<br />
<br />
string szConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\inetpub\\runescapestats.mdb";<br />
OleDbConnection cn = new OleDbConnection(szConn);<br />
cn.Open();<br />
<br />
StringBuilder szMyQuery = new StringBuilder ();<br />
szMyQuery.Append ("SELECT User.Username, User.Password FROM [User] WHERE (((User.Username)=\'szQUser\'))");<br />
<br />
OleDbCommand cmd = new OleDbCommand(szMyQuery.ToString (), cn);<br />
<br />
OleDbDataReader rdr = cmd.ExecuteReader();<br />
<br />
while (rdr.Read())<br />
{<br />
int iUsernameOrdinal = rdr.GetOrdinal("Username");<br />
int iPasswordOrdinal = rdr.GetOrdinal("Password");<br />
string szUsername = rdr.GetString(iUsernameOrdinal);<br />
string szPassword = rdr.GetString(iPasswordOrdinal);<br />
<br />
if(szPassword == txtPass.Text)<br />
{<br />
Output.Text = "Logged In";<br />
}<br />
else<br />
{<br />
Output.Text = "Failed";<br />
}<br />
}<br />
}<br />
<br />
finally<br />
{<br />
<big>rdr.Close();<br />
cn.Close();</big><br />
}
Thanks for any feedback.
|
|
|
|
|
What is the error message? AFAIK you cant have a finally without a try I pressume you just ommited it in the post?
|
|
|
|
|
It would have helped if you provided the error message also.
The actual soruce of the error is probably somewhere else in your code. The reason that you get an error in the finally part is probably that the reader is not open, or not even created. The finally code is run whatever happens, and if you get an error in your code prior to the creation of the reader, an exception will be thrown and the code in the finally block will be run. As the reader does not exist, you will get another error when trying to close it.
Check if the reader exists before you try to close it. Same with the connection.
---
b { font-weight: normal; }
|
|
|
|
|
I have a loop that is inside a Try Catch handler. It is 2 nested WHILE loops... the outer loop connects to a list of servers, and the inner loop, is a list of services to check on those servers. When I try to check for a service that isn't on the server, it goes to the Catch statement (which is good) and handles the exception (also good), except it skips to the next server instead of checking the rest of the services on that server. Is there a way to tell the Catch statement to go back to where it left off in the inner loop?
string server = null;<br />
try<br />
{<br />
while ((server = rSrv.ReadLine()) != null)<br />
{<br />
try<br />
{<br />
sw = new StreamWriter("Server_SvcLog.txt", true);<br />
<br />
string header1 = "";<br />
string header2 = "******************** " + DateTime.Now + spc + server + " ********************";<br />
sw.WriteLine(header1);<br />
Running_Event(header1);<br />
sw.WriteLine(header2);<br />
Running_Event(header2);<br />
<br />
StreamReader rSvc = File.OpenText(svcPath);<br />
string service = null;<br />
while ((service = rSvc.ReadLine()) != null)<br />
{<br />
ServiceController sc = new ServiceController(service, server);<br />
if(sc.Status.ToString() != "Running")<br />
{<br />
event_message = "NOT_RUNNING_EVENT" + spc + DateTime.Now + spc + server + spc + sc.DisplayName + spc + " is " + sc.Status.ToString();<br />
Not_Running_Event(event_message);<br />
}<br />
else if(sc.Status.ToString() == "Running")<br />
{<br />
event_message = "RUNNING_EVENT" + spc + DateTime.Now + spc + server + spc + sc.DisplayName + spc + " is " + sc.Status.ToString();<br />
Running_Event(event_message);<br />
}<br />
else<br />
{<br />
event_message = "SERVICE_NOT_FOUND" + spc + DateTime.Now + spc + sc.DisplayName + " not found on " + server;<br />
Service_Not_Found_Event(event_message);<br />
} <br />
<br />
}<br />
}<br />
catch(Exception ex)<br />
{<br />
SvcError(ex.Message);<br />
<br />
}<br />
finally<br />
{<br />
if(sw!=null)<br />
sw.Close();<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
catch(Exception ex)<br />
{<br />
LogError(ex.Message);<br />
}<br />
rSrv.Close();<br />
<br />
}
|
|
|
|
|
Use the return statement.
|
|
|
|
|
I'm not sure how the 'return' statement can help you...
No, to do this, what you need to do is move the try/catch into the loop, or add a try/catch within the loop, so the catch exits within the loop and the loop can continue.
Christian Graus - Microsoft MVP - C++
|
|
|
|