|
So the textbox can contain an arbitrary number of <name>'s? For example: one time I could enter '<FHGO>SomeText', next time '<FGHO><A>SomeOtherText', third try '<FGHO><A><BIG>SomeThingElse' and you want to get 1, 2 or 3 (or N) code blocks?
If so, you need to two two things:
1) parse up your textbox string into individual <name>'s. Here the Regex class Heath refered to is an IDEAL tool.
2) for each <name> you get, search the file. You'll want to do write a method something like:
<code>
private string strFindCode(strName){
TextReader trCodeFile;
//open the text file here....
bool bFoundIt=false;
string strCurrentLine;
string strCodeBlock="";
while(trCodeFile.Peek()>-1 && !bFoundIt){
strCurrentLine = trCodeFile.ReadLine();
if (strCurrentLine.IndexOf(strName)>-1){
bFoundIt=true;
strCurrentLine = trCodeFile.ReadLine();
while (strCurrentLine != ""){
strCodeBlock+=strCurrentLine +"\n";
strCurrentLine = trCodeFile.ReadLine();
}
}
}
trCodeFile.Close();
if (bFoundIt){
return(strCodeBlock);
}else{
return("Name Not Found");
}
</code>
I have not compiled, much less run, this code. So I make no promises...but hopefully it points you in the right direction algorithmicly.
Bill
ps: please don't everyone jump on me for not using the StringBuilder...
|
|
|
|
|
Hi all,
I have a TextBox control that only takes in numbers, the final *bug* i have to solve is when the user right clicks on the control and the popup menu appears with undo, cut, copy, paste, etc on it.
What event can i use to deal with when they select paste?
I need to solve this to stop the user pasting text into the control that isnt numbers.
This isnt a context menu i have attached to the control so the ContextMenuChanged event doesnt fire, which is the event i thought i should be using.
Anyone got any ideas where i'm going wrong?
Thanks
|
|
|
|
|
If you've extended TextBox with your own, override OnValidating ; otherwise, handle the Validating event. This allows you to cancel the operation if anything but numbers are pasted and will restore the previous text (since Validating fires before the Text is set). See the documentation for the Validating event to see an order of events. The only problem with this method is that the control must loose focus first.
If that's not sufficient, then extend TextBox (if you haven't already) and override WndProc . Handle the WM_PASTE notification message (0x0302) and throw it out (i.e., don't call base.WndProc ) if the Clipboard text doesn't contain numbers. You could handle this a few other ways, but hopefully this will get you started.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks!!!
The override of WndProc is just what i needed, i'll get on with it that way.
I really must remember WndProc when i get stuck.
|
|
|
|
|
Hi,
When we generally click the cross on the caption bar, our application (or our Form) will close and it is automatic action.
I'd like close my application when I'll click the cross on the caption bar and I'll confirm this action. When I'll not confirm it, application shouldn't be closing.
I try use the Closing event, but I don't know how interrupt closing app.
Regards
Kamil
|
|
|
|
|
Hi,
If you override the forms "Closing" event then have some code like below this should help you out.
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("Do you wish to close?",
"AppName",
MessageBoxButtons.YesNo) == DialogResult.No)
e.Cancel = true;
}
By changing e.Cancel to true the event will not complete and your form will not close.
Hope this helps
Simon Wren
simon.wren@nesltd.co.uk
Senior Software Architect
National Energy Services Ltd
Visit Us: www.nesltd.co.uk or: www.nher.co.uk
|
|
|
|
|
Except this isn't overriding, this is handling the Closing event. Since it's typical to extend the Form class with your own (VS.NET does this for new Windows Forms application proejcts), you override the event handler, OnClosing , which is better (faster, more control) than handling the event in a derived class:
protected override void OnClosing(CancelEventArgs e)
{
DialogResult result = MessageBox.Show("Do you want to close?", Text,
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result != DialogResult.Yes)
e.Cancel = true;
base.OnClosing(e);
} That's overriding. In this case, you'll still want to call the base class's handler, but in some cases (like when you want to throw messages out in WndProc ), you don't want to call the base class's method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks, i did get my use of the word override wrong in my first response
Out of interest you mention that using OnClosing is faster, why is it?
|
|
|
|
|
When you handle an event, you actually add a reference - a managed pointer - to a list of handlers. That reference must be added to a list - which may have to be resized, which takes time. Even adding the referenec to that list is an O(n) operation, where n is the number of list items currently in the list.
When the event is fired, the list of references to delegates is enumerated and each delegate is invoked. The EventArgs derivative may need to be "queried" in between each invocation to keep track of whether or not something needs cancelled (in this case).
That's all quite a bit more than simply a virtual call (callvirt IL instruction), which is polymorphic.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Look in the EventArgs object.
You have to do something like
e.Cancel = true;
However I do not remember the EXACT property name so search for it.
______________________________
The Tao gave birth to machine language. Machine language gave birth to the assembler.
The assembler gave birth to the compiler. Now there are ten thousand languages.
Each language has its purpose, however humble. Each language expresses the Yin and Yang of software. Each language has its place within the Tao.
But do not program in COBOL if you can avoid it.
|
|
|
|
|
Your Closing event will have a parameter of type CancelEventArgs which has a property called Cancel . Set the property Cancel to true and the application won't exit.
This gives you a chance to pop up a message box asking "Are you sure?" and if the user selects "no" then you can cancel the event. If the user selectes "yes" then you need do nothing more - the application will be closed.
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
Thanks!!!
e.Cancel = true;
It is exactly what I need.
Thank you for fast answer.
Regards
Kamil
|
|
|
|
|
I'm not sure how to do it!
help pls
Cata
|
|
|
|
|
See the StringFormat class. OR StringFormatFlags.NoWrap with StringFormat.FormatFlags and pass the StringFormat instance to your Graphics.DrawString call.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi ,
i have a mesh model and i put it in many places in my app. using the world transformation and i want to detect which mesh is the pointed one but when i point to mesh it only detects the last mesh has been transformed .
|
|
|
|
|
What do you mean by "the pointed one"? This is a little too non-technical to answer.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i mean by it the one which the mouse points to it
|
|
|
|
|
You can get the mouse position at any time using the static Control.MousePosition property. You could transform these coordinates to your world space and get the mesh you need, or if you click on it you can get the client coordinates and transform these.
When you say you are getting the last mesh that was rendered, do you mean that you're destroying and re-creating your mesh with each drawing phase, and that you get the last one rendered? You probably don't need to destroy your mesh each time, though you would have to get the materials and textures from it to draw.
I'm sorry if I don't understand your problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Contact your administrator, and ask him if he could add you to the debug users group ...
DOn't know why this is good either
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
jithen_dt wrote:
why should I have admin rights?
Microsoft's IDE wrote:
Access is denied. Verify that you are an administrator or a member of the 'Debugger Users' group on the machine you are trying to debug.
Well, that says to me that you either need to be an Administrator (because they can do anything) or a member of the debugger group (because that's what you are trying to do)
So, add yourself to the debugger group and log in again. If you still get the message then you probably do need admin rights.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
I want to make use of dlls created in .Net in vb6 is
it possible
Every thing is MAYA
|
|
|
|
|
Yes, so long as they expose CCWs, or COM-Callable Wrappers (which is the best way, and VB6 is entirely built on OLE/COM anyway). See Nick's article, Creating a CCW for COM-enabled, non-.NET Applications[^], and read Exposing .NET Framework Components to COM[^] in the .NET Framework SDK.
A few important things to note: explicitly define your class and interfaces GUIDs (using the GuidAttribute ), and DO NOT use auto-generated class interfaces. Instead, attribute your class with ClassInterface(ClassInterfaceType.None) and explicitly declare your class interface and implement it as the first interface in the list of interfaces. Make sure you declare your interface as an automation interface by attributing your interface with InterfaceType(ComInterfaceType.InterfaceIsIDispatch) (or ComInterfaceType.InterfaceIsDual ). Since VB6 depends on automation, declaring your interface as an IUnknown implementation won't work.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes. You'll need to use regasm.exe to register your assembly as a COM dll. Depending on what the public interface looks like you might have to decorate your code with attributes. There is a lot of information and examples on the web. You can also take advantage of COM+ services in the System.EnterpriseServices namespace.
|
|
|
|
|
Hello,
I have many servers running on different machines.
My client program will be shown a list box of available servers.
When connection to server is to be done .NET Remoting.
Now, I should continuosly check whether the connected server is still
running and check all the available servers status and delete the
server from the list if it is not running.
How can I do this, using .NET Framework?
|
|
|
|
|
If you remove it, then you'd have to keep a list elsewhere so that you can always add them later when they're up and running again. I'd just as well leave them in.
As far as checking their up-status, just try connecting to their published remoting objects that you need. If it fails, then the server's not "up". Simply pinging (which would require implementing ICMP or finding some third-party library that already has) them might not tell you enough, since many firewalls don't return pongs or reply with "destination unreachable". It's also possible that the remoting server (a Windows Services, IIS, whatever) is stopped but the server is up, so pinging it would be disjoint and wouldn't give you an accurate assessment of whether or not the remoting objects is available.
Microsoft MVP, Visual C#
My Articles
|
|
|
|