|
Just handle the KeyPress event of the textbox check each character...
<br />
textBox1.KeyPress += new new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);<br />
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (!Char.IsDigit (e.KeyChar))
{
e.Handled = true;
}
}
Andreas Philipson
|
|
|
|
|
and how do I handle multiple verification, I want to allow control (BKSPACE, etc.) and dots.
// JS Paquet
cout << "Thank you all" << endl;
|
|
|
|
|
Hello, I've inserted below a portion of source code from a non-copyrighted freeware mime parsing algorithm implemented in C# I came across on the internet.
I'm fairly new to c# and I'm finding this algorithm painfully slow and was wondering if anyone had any suggestions for improving this.
It's actually not bad for any email that contains mime entries that are under 300k, but I tested against an email with a multi-megabyte attachment and it took approximately 10 minutes to process it. The slow bit is definitely the part that searches for the boundaries "---" line by line.
Any suggestions would be very welcome. Once I have it working properly and consistently I will post it as an article.
internal ArrayList ParseEntries(MemoryStream msgStrm,int pos,string boundaryID)<br />
{<br />
ArrayList entries = new ArrayList();<br />
<br />
msgStrm.Position = pos;<br />
<br />
if(boundaryID.Length > 0){<br />
using(TextReader r = new StreamReader(msgStrm)){<br />
string line = r.ReadLine();<br />
<br />
bool firstFound = false;<br />
string buffer = "";<br />
while(line != null){ <br />
if(line.StartsWith("--" + boundaryID)){<br />
if(buffer.Length > 0){<br />
entries.Add(new MimeEntry(buffer,this)); <br />
}<br />
<br />
firstFound = true;<br />
buffer = "";<br />
}<br />
else{<br />
if(firstFound){<br />
buffer += line + "\r\n";<br />
}<br />
}<br />
<br />
line = r.ReadLine();<br />
}<br />
}<br />
}<br />
<br />
return entries;<br />
}
|
|
|
|
|
Have you tried using a System.IO.BufferedStream ?
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hello, no I haven't. I was thinking there would be no benefit to that since it's a memory stream to begin with, would that not be the case?
|
|
|
|
|
Hello, I am looking for assistance with the basic class skeleton that would allow me to create a fuction similar to:
MyClass.FieldByName('firstname').AsString
OR
MyClass.FieldByName('startdate').AsDate
Etc ....
public class MyClass
{
public void Run()
{
// do something here ...
}
public ?????? FieldByName() ?????
{
????
}
}
Any assistnace would be appreciated.
Thanks
|
|
|
|
|
public class MyClass
{
private string firstname = "";
public string FirstName
{ get { return firstname;}
set { firstname = value;}}
private DateTime startdate = DateTime.Now;
public string StartDate
{ get { return startdate;}
set { startdate = value;}}
}
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
If possible, I would like to go 1 level deeper with having the fuction of FieldbyName that is passed dynamic data which could be firstname or startdate and also specify if the return is to be of type string, date, integer or etc. The FieldByName method would search a file or database for a match of the requested field and then return the results.
This is similar to how I have seen several database engines return the requested field as a specific type.
MyClass.FieldByName('firstname').AsString
|
|
|
|
|
Look at System.Reflection
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
I am not that familiar with System.Reflection. Can you provide any kind of example of how to use this with creating a class similar to
MyClass.FieldByName("company").AsString
MyClass.FieldByName("account").AsInteger
MyClass.FieldByName("begindate").AsDate, etc .....
public class MyClass
{
public string FieldByName(string fvalue)
{
}
}
Any assistance would be appreciated.
Thanks
|
|
|
|
|
Hello everyone!
I am migrating an application to the .NET platform using C#. Unfortunately, I still have to use a few old COM+ components that store business logic. I have no problems creating the object that I require, however, the arguments marked as "out" don't get assigned any values after the method that I am using is called.
I tried this using the two methods to access COM+ components: RWC wrappers and late binding. The former looks like this:
string mItemId = "{Some Guid}"
double mACustPrice = 0;
ObjectName objPrice = new ObjectName();
objPrice.GetPrice(mItemId,out mACustPrice);
After executing this code, the argument mACustPrice contains the value that I originally assigned to it, which is 0 (zero).
The late binding one looks like this:
string mItemId = "{Some Guid}"
double mACustPrice = 0;
Type objAddType = Type.GetTypeFromProgID("ObjectName");
object objPrice = Activator.CreateInstance(objAddType);
object[] objArguments = new object[] {mItemId,mACustPrice};
objAddType.InvokeMember("GetPrice",BindingFlags.InvokeMethod,null,objPrice,objArguments);
string test = objArguments[1].ToString();
After executing this code, the string test contains the value that I originally assigned to the mACustPrice variable, which is 0 (zero).
Any help will be greatly appreciated.
|
|
|
|
|
Assuming you mean that the interface is marked with [out, retval] this should work
mACustPrice = objPrice.GetPrice(mItemId);
|
|
|
|
|
Thanks for the quick reply!
Two problems with this solution:
1. I have more than one "out" argument. I simplified the code to make the message more readable.
2. The argument is marked as [out] only, not [retval]
Any other suggestions will be greatly appreciate it. Thanks again!
|
|
|
|
|
Hi!
I have some questions:
1. Does anyone know how in runtime detect how many memory used by each class?
2. Does anyone know how to minimize memory usage of application (like unloading of unneeded assemblies or something else)?
3. Does anyone know any resource with "performance" + "memory usage" tests on Windows.Forms?
I have such situation:
I wrote application which make some automation tasks like send e-mail, generate Excel reports (office automation) and etc. Application is not too large but it’s usage of memory make customer dizzy. As you know customer dizzy become a developer soon. Now I have a great task to minimize memory usage of application. First of all I need to know how many each class use memory, second step rewrite code of such classes.
To my opinion 30-40 Mb memory usage (on computer with 128 Mb) for garbage collector is good enough...
Good Luck
Alex Kucherenko
|
|
|
|
|
I don't have answers for all of your questions, but here something to get you started
If you are creating COM objects then you can force their release by doing
MyObject=null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.GC.Collect();
Be carefull when looking at memory usage in the Task Manager it isn't telling you the whole truth. To determine the real memory usage of an application you could:
' Visual Basic .NET
Dim NotepadMemory as Integer
Dim component1() as Process
component1 = Process.GetProcessesByName("Notepad.exe")
NotepadMemory = component1(0).PrivateMemorySize
Console.WriteLine("Memory used: " & NotepadMemory & ".")
// C#
int memory;
Process[] notepads;
notepads = Process.GetProcessesByName("Notepad.exe");
notepadMemory = notepads[0].PrivateMemorySize;
Console.WriteLine("Memory used: {0}.", notepadMemory);
|
|
|
|
|
Hi everybody !
Here is pic ...
Please open to see it if browser is not auto open
In the present , I need your help so much. I want to design a form like this. Whatever I mask by Red point is neccessary. Please help me to do that.
Thank so much !
|
|
|
|
|
The post just below references a free .NET layout library.
Another url of interest, the genghis[^] project.
And of course, there are many C# controls related articles on CodeProject which act like unit blocks.
|
|
|
|
|
I’ve just upgraded to the new MagicLibrary version 1.7.4.0 (I used 1.7.0.0 before that) and have encountered a focus management problem in the DockingManager.
I have several forms and panels created inside the MagicLibrary docking manager and I have a rich textbox as my inside window/filler window.
If any of the forms inside the dockingmanager have shortcuts they will hi-jack focus from my rich textbox.
For instance if I have a panel with a “&Test” button created inside the DockingManager then I can no longer type “T” inside my Rich textbox when I do so the focus is transferred to the panel and the button is pressed.
This was not present in 1.7.0.0 (haven’t tested on 1.7.3.0).
Anybody have some clues as to avoiding this behavior.
Best regards Peter Hjortholm
|
|
|
|
|
Hi,
I have several controls in my form ( a tab form... that includes combos, edit boxes, grids, ...)....
Is there a way to know if any of this control has changed, just to change the flag and save changes ? ( I know that I could go control by control .... but is there a more generic way ?).
Thanks, greetings
Braulio
|
|
|
|
|
If I understand what you are doing, then just use events with event handlers.
All components have events for changes and stuff, for example the TextBox has a TextChangedEvent. In your form you can just add it to listen for this event.
Using properties panel on the form design just click the events button (little lightning bolt above the panel of properties) and get a list of events for the Textbox you have slected, look for TextChanged or TextChanging, and double click that field. It will add a new Event handler in your form code, and you can do what ever in that method. It is the exact same as a button1_Click( object sender, MouseEventArgs e ) that you most likely have probably used before. All otehr controls have events as well, ComoboBox.SelectedChanged I think as well.
|
|
|
|
|
Furthermore, if you only care about whether a control changed, you can assign the same event handler to all the "change" events of the controls on the form. Then, if you need to do more, you could use the sender object to do extra things (besides just determining if a control changed). You would just need a generic event handler in the form:
ControlChanged( object sender, EventArgs e )
"Shut up brain, or I'll stab you with a QTip!" - Homer Simpson
|
|
|
|
|
I was hoping there would be something simple like:
RichTextBox t = new RichTextBox();
t.VScrollBar.Value = t.VScrollBar.MaxValue;
You can do something similar in java, but i think its a little more code than this but the same idea.
I can't find how to do this in c#, no topics about it anywhere.
I'm adding text to the RichTextBox programically, like
t.Text += "\r\nHello there";
keep doing things like this and i want the scroll bars to keep scrolling down.
All I could find was t.ScrollToCaret(), but that requires the mouse cursor in the box correct?... either way ScrollToCaret() did not work.
Thanks.
|
|
|
|
|
I have an interesting and stupid problem,
I have a class that is dirived from another class and I want to type cast the first class to the second class somewhere in the program as seen below.
Class A
{
}
Class B
{
}
A FirstObject=new A();
B SecondObject;
SecondObject=(B)A
When I attempt to do this in WebApplication I get
Specific Cast Not Valid.
What am I doing wrong??
John
|
|
|
|
|
Hi John,
I don't think that you can cast classes, even if they derive from the same base class in C# (even tho this is legal in C++). Instead, something like this may get you where you want to go.
Good luck!
Nick.
-----------------------------------------------------------
A Sample Run:
D:\>ClassCasting.exe
ClassA!
ClassB!
D:\>
-----------------------------------------------------------
using System;
namespace ClassCasting
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class ClassCasting
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ClassA oClassA = new ClassA();
ClassB oClassB = new ClassB();
// Can't do this in C# yet!
//oClassB = (ClassB) oClassA;
// But.... you can do this!
CoreClass oCoreClass = oClassA;
oCoreClass.SomeMethod();
oCoreClass = oClassB;
oCoreClass.SomeMethod();
}
}
abstract class CoreClass
{
// Define some common methods here.
public abstract void SomeMethod();
}
class ClassA : CoreClass
{
public override void SomeMethod()
{
Console.WriteLine("ClassA!");
}
}
class ClassB : CoreClass
{
public override void SomeMethod()
{
Console.WriteLine("ClassB!");
}
}
}
|
|
|
|
|
Does anyone have a smart key-generator for generating strings, just by using some kind of string Get_Next_Key() command.
Or some tips to make such a class???
Thank you in advance,
Boudewijn Ector
The Netherlands
|
|
|
|