|
I tried and got the Undo() not to undo the whole textbox, but only the latest entry. What I did was I clicked on another object, then clicked on the textbox and added more text. You can probably achieve multi-stepped undo by playing a bit with the TextChanged event from the RichTextBox and changing focus.
Internet - the worlds biggest dictionary
|
|
|
|
|
Hello, I am creating a control that shows an image and a reflection of this one, very similar to which can be seen in the Windows Photo Gallery of Vista Windows: (the miniature to the right)
http://www.winsupersite.com/images/showcase/winvista_rc1_best_12.jpg
The problem is that when attempt to draw an image that is losing opacity, that is to say, to draw degrading that is diminishing the opacity of the reflected image. Since I can do this?
Greetings, sorry for my bad English
|
|
|
|
|
I have a class with a function that returns an ArrayList.
The problem is that I don't want any client that calls the function to be able to add or delete items from the ArrayList. I want to force the client to use my class' other functions to make any modifications (because related data has to be updated).
Unfortunately, speed is an issue, so I can't just copy the ArrayList and send the copy. Also, a copy would allow the client to think he is making a change when it is actually being ignored. I'd prefer him to get a compile error if he calls Add(), for instance.
I can't find any C# syntax that can make a returned value (or a returned parameter) read only. (The C# "readonly" syntax won't let the client replace the ArrayList with another, but WILL let the client change the content of the ArrayList, and so it is insufficient).
Any ideas would be appreciated.
Mark
11 Feb 2007
|
|
|
|
|
Instead of returning the ArrayList itself you could return an enumerator for the ArrayList . Take a look at the ArrayList.GetEnumerator method.
"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
|
|
|
|
|
If the only action you want to offer is enumeration, return an enumerator.
If you want to offer a larger subset of ArrayList functionality, create your own
class that:
- either inherits from ArrayList and hides the properties/methods you dont
want to offer,
- or contains an ArrayList and makes public the enumerator plus those extra properties/
methods you want to export.
Luc Pattyn
|
|
|
|
|
Thanks to you both who responded.
I couldn't figure it out without you.
For others interested, here is a minimal solution class which seems to work so far. You may want to add other properties or functions, but this is what I need for now.
I call it a Firm List since, for the user only, the array size is no longer variable but is firm (solidified). The user can read and use each item in the list, but can't make the list contain a different item nor change the number of items in the list.
using System;
using System.Collections;
namespace FreeForAll {
public class FirmList : IEnumerable {
ArrayList foundation;
public FirmList(ArrayList source) {
foundation = source;
}
public IEnumerator GetEnumerator() {
return foundation.GetEnumerator();
}
public bool Contains(object item) {
return foundation.Contains(item);
}
public int Count {
get { return foundation.Count; }
}
}
}
Here is how, within another class, I return a FirmList as property "SomeList". Within this class, I have full accees to the ArrayList itself and all of its abilities.
class A {
ArrayList TheRealList = new ArrayList();
FirmList TheFirmList;
A() {
TheFirmList = new FirmList(TheRealList);
}
...
void SomeFunctionThatAddsMembersToTheArrayList() {...};
...
public FirmList SomeList {
get { return TheFirmList; }
}
}
And, finally, here is how some other code might use it, just like and ArrayList is used:
A aaa = new A();
aaa.SomeFunctionThatAddsMembersToTheArrayList();
FirmList list = A.SomeList;
foreach (object o in list) {
...
}
WriteLine("{0}", list.Count);
if (list.Contains(...)) {...
Hope this helps someone else.
Mark
|
|
|
|
|
In C# you can't mark reference types as readonly.
However you can Encapsulate ArrayList inside a class and provide restricted access to it through methods, properties. You mentioned that speed is an issue otherwise you could have simply returned a clone to it.
|
|
|
|
|
Hi,
I have created a little button on the form called "Close", and when a user clicks it, it displays a messagebox saying "Do you really want to quit?" with an Ok and a Cancel. Then if they click Ok it does : this.Close(); and if not it doesn't do anything.
Now, I want to be able to get data from the X (Close button) on the form to display the same text box or disable the X (Close button) so users have to use the close button that I have created.
Any way of doing this?
Thanks.
|
|
|
|
|
Put all code that show the message box and eventually cancels the closing operation into the event handler for the FormClosing event and inside the button Click event handler simply call the Close method of your form.
"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
|
|
|
|
|
About the button, instead of the Close function, try using the Application.Exit function, the Close one seems to not work in many occasions.
And for the x button, i thought this might be a good think to know myself, and i made some research and this is what i came up with:
there's an event in frameworks 1.1 which is called Closing (which later became FormClosing in frameworks 2), so you use the event (this.FormClosing +=...) and in the event you can use:
e.Cancel = true;
this also stops it from closing with the F4 key, so you can do like so:
first, define the event:
<br />
this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing);<br />
and then in the event do something like this:
<br />
void MyForm_FormClosing(object sender, FormClosingEventArgs e)<br />
{<br />
DialogResult a = MessageBox.Show("Are you sure you want to close the program?","Cancel",MessageBoxButtons.YesNo);<br />
if (a == DialogResult.No)<br />
e.Cancel = true;<br />
}<br />
And as for canceling the minimize and maximize buttons? how about just disabling them? or just use the Form.Resize event.
hope it helps.
-- modified at 10:35 Sunday 11th February, 2007
|
|
|
|
|
Thankyou, that helps a great deal. Thankyou for all the effort you put in to finding out about it also.
|
|
|
|
|
I just tried it out, it is amazing, thankyou very much. Except I don't understand the:
this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing);
VC# EE just gave me a load of errors on that, and I don't quite know what it's doing anyway.
Well, thanks for the great help.
|
|
|
|
|
Can you please say what the errors are?
|
|
|
|
|
Hi, I need a little help.
I am wanting a message such as "Do you really want to quit?" to be displayed when a user clicks the X (close button) in the corner of the form. I have tried some methods that just haven't worked, as I do not know how to make the Close(); function display a bool to then be used in an if statement.
Any ideas?
Thanks.
|
|
|
|
|
you can use the FormClosing event to check if the user really wants to close the window...
cellardoor
|
|
|
|
|
Thankyou for your help, it works now
|
|
|
|
|
Hi!
Is there a function in C# that checks if a string is numeric?
Thanks in advance
|
|
|
|
|
There are several possibilities. You could use the TryParse methods provided by the numeric types like double or int . Also the Regex.IsMatch method would be an opportunity.
"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
|
|
|
|
|
Hi
You can use for loop statment to check each of character.or use
regx class for System.Text.RegularExpressions
Example:
this example check string for currency.
public static void Main ()
{
// Define a regular expression for currency values.
Regex rx = new Regex(@"^-?\d+(\.\d{2})?$");
// Define some test strings.
string[] tests = {"-42", "19.99", "0.001", "100 USD"};
// Check each test string against the regular expression.
foreach (string test in tests)
{
if (rx.IsMatch(test))
{
Console.WriteLine("{0} is a currency value.", test);
}
else
{
Console.WriteLine("{0} is not a currency value.", test);
}
}
}
|
|
|
|
|
Have a look at System.Char - it has the members IsDigit and IsNumber .
Regards,
Tim
|
|
|
|
|
How to change ms access column name in c#, using ADOX?
i have this sample on VB to change table name:
Call RenameTable("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\example.mdb", "test", "changed")
Sub RenameTable (conStr, oldName, newName)
'Has to be OLE DB connection
'Create object and connect to DB...
Dim objADOXDatabase
Set objADOXDatabase = Server.CreateObject("ADOX.Catalog")
objADOXDatabase.ActiveConnection = conStr
'Change the name...
objADOXDatabase.Tables(oldName).Name = newName
'Clean up...
Set objADOXDatabase = Nothing
End Sub
May be its possible transform this sample to c#?
|
|
|
|
|
Hello,
I have created a console application that takes a file path as input.Now i want to limit only text files to this input.how do i identify the file type to be text?It can be any like .txt,.doc
rgds,
chax
chax
|
|
|
|
|
You can use the String.EndsWith() function.
|
|
|
|
|
Hi all,
I was just spending hours on finding a memory-leak in my application. Now I found it and closed it with a workaround but don't know why I needed a workaround.
I have an object which contains a very big 2d-array (which consists of 3,000,000 PointF structs). I fill the array and Windows Task-Manager shows that my application uses 24MB more RAM.
Then I execute following code:
myObject = null;<br />
GC.Collect();
and nothing happenes! But when I execute the code
myObject.bigArray = null;<br />
GC.Collect();
the 24MB memory is freed and I'm happy.
Why is that? When I kill the reference to myObject, then there is no reference to the array and the GC should also free the memory, but it doesn´t
Can anybody tell me why?
BR
Alexander
|
|
|
|
|
I'm unable to reproduce the behavior (I'm running .NET 2.0). This is the program I tried
class A
{
public PointF[] points = new PointF[1000000];
}
public class Test
{
public static void Main()
{
Console.ReadLine();
A a = new A();
Console.ReadLine();
a = null;
GC.Collect();
Console.ReadLine();
}
}
Can you post a stripped down version of the code demonstrating the problem? Also, how did you measure the memory usage/drop? Memory Usage in TaskManager is not accurate, VM Size is a better measure. Better yet, you can use one of the performance counters (Type perfmon.msc at the command prompt, right click on the graph, click Add Counters, choose the .NET CLR Memory performance object, select your process from the list box, choose #Bytes in all Heaps and repeat the experiment. You should see the counter value drop).
|
|
|
|