|
Zembaliti wrote:
Both a) and b): CanUndo always returns false, regardless the text has been modified (run-time).
According to the documentation, the TextBoxBase.CanUndo property indicates whether or not you can undo the previous operation. In both of your instances, you are not performing operations directly on the RichTextBox , but accessing two of its properties so it should return false.
- Nick Parker My Blog
|
|
|
|
|
I think Zembaliti is assuming that there was something in the undo buffer before these calls. As it happens, this is an acknowledged bug in the RichTextBox control. Even if the RichTextBox has changed, the act of accessing the Text property or the TextLength property completely wipes out the Undo/Redo buffer.
To work around this, you have to use the Win32 API (e.g. EM_GETTEXTEX) to get text, circumventing the Text property. If you want the Text length, you have to send the EM_GETTEXTLENGTHEX message to the control. I derive a new control from RichTextBox and override these properties to make using RichTextBox easier in my code.
You can see an example of using EM_GETTEXTLENGTHEX for this purpose on a RichTextBox in my recent article here. A google search also confirms it.
|
|
|
|
|
I copy the file 'C:\Program Files\Common Files\Microsoft Shared\Office10\RICHED20.DLL' into the directory with the executable (bin\debug), and the issue does not happen any more.
So is this bug of .NET Framework Runtime or of the Windows RICHED20.DLL file?
|
|
|
|
|
Good question. I don't have time to investigate it now, but because you can't be sure of which RichTextBox control you will be working with on the client machine (e.g. Riched32.dll or Riched20.dll), I still recommend that you derive a new control from RichTextBox and override the problem methods. You could do something like this:
public override string Text
{
get{
return API.GetRichTextText(this.Handle);
}
set {
base.Text = value;
}
}
where you define API.GetRichTextText() as:
public static string GetRichTextText(IntPtr hwndRichTextControl)
{
GETTEXTEX lpGETTEXTEX = new GETTEXTEX();
// * 2 For double byte
lpGETTEXTEX.cb = (GetTextLength(hwndRichTextControl) + 1) * 2;
lpGETTEXTEX.flags = 0; // For default.
lpGETTEXTEX.codepage = 1200; // Unicode.
StringBuilder sText = new StringBuilder(lpGETTEXTEX.cb);
SendMessage(hwndRichTextControl, EM_GETTEXTEX, ref lpGETTEXTEX, sText);
return sText.ToString();
}
and
[StructLayout(LayoutKind.Sequential)]
public struct GETTEXTEX
{
public Int32 cb;
public Int32 flags;
public Int32 codepage;
public IntPtr lpDefaultChar;
public IntPtr lpUsedDefChar;
}
private const int WM_USER = 0x400;
private const int EM_GETTEXTEX = WM_USER + 94;
You can do something similar for TextLength, or just get the text and measure it.
Tom Clement
Apptero, Inc.
|
|
|
|
|
Thank you for your informative answer.
So all the ways turn into using Win32 API to rewrite code from scratch. I don't like using Win32 API, because it involves a lot of things, such as Marshal, Permission, unsafe...
It makes your code not reusable. If someday Microsoft rewrites their System.Windows.Forms.dll file and the USER32.DLL file disappears..., then you have to rewrite your code. You have to change every time Microsoft changes.
And when the 64-bit Windows is released in the future, I think that USER32.DLL will be replaced by USER64.DLL...
|
|
|
|
|
The problem is clear now. I have found the answer at:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;812943
I hope MS will release a patch for this issue soon.
Regards,
Zembaliti
|
|
|
|
|
Is it possible to run a C# .NET program on Linux or MacOS? I read something about compiling a Portable Executable file, but I know nothing about it.
|
|
|
|
|
There is a project [^]to port .NET Framework to Linux. I guess you should be able to run it on Mac OS X too. I don't think though they will ever port every class in .NET framework.
|
|
|
|
|
Mac OS has the full support of .NET. You can run not only C# in Mac OS but all the .NET compatible languages in it.
|
|
|
|
|
Leslu wrote:
Mac OS has the full support of .NET. You can run not only C# in Mac OS but all the .NET compatible languages in it.
This is not true. There is a reference implementation for BSD which is the OS the OS X is based, however it doesn't support enough of the framework to allow Windows C# apps to run on an Apple.
Even the linux Mono project, only currently supports a subset of the entire .NET framework.
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
The first part of his statement may be wrong, but his second part is not. Since all languages targeting the CLR produce IL (with little differences due to compiler optimizations and language features), any pure .NET language will work (for instance, mixed-mode Managed C++ would not because it contains native instructions).
Just wanted to point that out to make sure there was no confusion on this often-misunderstood subject.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am building a custom WebControl and I would like to render an image in that custom control. I have a solution but it is not the solution I would like. Currently I am saving my image as a file and writing an html "img source" tag pointing to that file at the time I am asked to render my control into the HtmlTextWriter.
The solution I would like is to be able to stream the image into the page so that I am not required to create an image file.
Is this possible?? Thanks.
|
|
|
|
|
What I had done is:
set the "img source" to myPic.aspx
then in myPic.aspx.cs in the Page_Load event, write to the output stream:
"MIME=image/jpeg" // or something like that
and then just write your image you draw to the stream as well.
Bitmap bm;
// draw to it
bm.Save( Response ); // the response stream
this works, i have done it before, but this is not exactly correct, can't remeber the exact words/code not sure of the correct form for MIME type, but look on google for MIME types or something.
You can even pass parameters to yout myPic.aspx?lines=1,2,8,9
which could draw a line from 1,2 to 8,9
Or save the bmp in the Session and retreive it from the sesion when the client requests myPic.aspx, but i have not tried this session idea before.
Hope that might help.
|
|
|
|
|
Bob Scoverski wrote:
The solution I would like is to be able to stream the image into the page so that I am not required to create an image file.
Yes, I wrote an article on it here: Web Graphics On The Fly in ASP.NET[^]. Hope this helps.
- Nick Parker My Blog
|
|
|
|
|
Hi there,
I was wondering how I could go about writing an array of strings containing any character, into a hidden web control (textbox), and also as a parameter in a javascript function call. And not have it screw up the html on the rest of the page. Then be able to parse the one long string back into an array of strings, upon post back.
The one long string can't have single quotes in it, cause it will screw up my javascrip parameter which wraps single quotes around the string.
I would guess it would have to first write all the strings as one long one with some delimiter (that delimiter might already exist in the string and needs to be handled), and then convert that one big string into some kind of html compatible string not to screw up the rest of the html, or javascript parameter.
Would some kind of XML work for sticking all strings into one big string? And UML or URL converter class work?
Anyone have any ideas? I am hoping for some built in classes in the framework. There must be some kind of delimiter string creator class and html formatter class? I cant find any.
Thanks in advance.
Kris.
|
|
|
|
|
See the HttpUtility for an HtmlDecode and HtmlEncode method. You could encode each array element, then join then with a ','. When you need the array again, split on ',' and decode each element. Fortunately, javascript also has both an encode and decode method that you could use. Works out great.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Wow, thanks alot Heath.
You have always been the one to asnwer all my questions, and your always right
Well, thanks again.
|
|
|
|
|
Hi everyone,
I have a moule that generates some excel files over an ASP.NET page. Depending on the request, some files can take a long time to download. So, I thought it would be a nice idea to use a web service that would do this in the background.
I have no experience with web services whatsoever. Is it possible to do the following with the web service:
- The client does not get stuck in the page. Basically, the request should be processed in the background. Currently, when I do this in an ASP.NET page, the page waits on the load till the request is complete. What I want is to process the request in the background and the user should be free to browse the site.
- Have a callback that will notify the user that the request has been complete.
If someone can suggest on such background processing of tasks, I would be really grateful.
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
HTTP is a stateless protocol, allowing only one-way communications (clients make a request, server returns a response). You couldn't use a callback because the server can't alert the client. You could, however, use a session variable to signify when a particular action is done so that when the client receives the response from the server after this variable is set, you can display something to link them to the generated Excel file. You don't even need XML Web Services to implement such a feature. This isn't an easy task, though, and you should better familiarize yourself with how ASP.NET works by reading the .NET Framework SDK, specifically the topics related to ASP.NET[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'd like to experiment with an IntPtr and strings. How do i retrieve a string from an IntPtr and convert a string to an IntPtr for the purpose of marshaling?
Basicaly, I've built a version of SHGetPathFromIDList in my program and i'm converting a PIDL to the file path, however the pre created string I am marshaling to it does not get modified properly, so i would like to send a pointer to a string instead.
(There is a post about this problem in the COM forum that covers the finer details, but for now i'd just like to convert an IntPtr to a string or Vis Versa.)
Cheers
Cata
Edit: I suppose the question is - How do I construct a buffer (char array?) of size Max_Path, and then create a pointer to it?
|
|
|
|
|
See the System.Runtime.InteropServices.Marshal class. It has a lot of static methods to facilitate marshaling between things like String s and IntPtr s. For a specific method, see Marshal.PtrToStringAuto (methods exist for ANSI, BSTR, and Unicode as well when you know that a string will always be encoded a certain way, otherwise Auto is ANSI on Windows and Unicode on Windows NT.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks heath.
Just tell me, am I on the right track for handling a buffer? I take it I am constructing a space in memory that will have the file path written to it.
It's not an out, or ref call is it? I just need to retain the pointer to the buffer so that once it has been written, I can read it.
How do I go about this? Using a pointer to a string?
Cheers
Cata
Edit: Thanks dude! I got it figured, switched the string into a pointer, and forwarded the pointer, pulled it out, converted it back... and bingo!
Gratz. My experimentation with COM goes very well indeed
|
|
|
|
|
Did you ever read all that stuff on marshaling I gave you links for before? ref and out should only be used for [out] value types and pointers to pointers as declared in native code. If you need the address to a string, you simply do something like this:
IntPtr ptr = Marshal.StringToCoTaskMemAuto(myString); If your method declaration expects a pointer, this is how you can get it. If you're passing a char[] array, the array itself is a reference type (even though Char is a value type) so you don't need ref or out . The address is what's already being passed since the array is a reference type.
It all just depends on the implementation, for which you've given no specifics. If you need help with something specifically, please provide the signature of the method you're trying to call or something similar.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yeah, sorted it all.
Thanks mate, probably posted too soon. Got it figured.
Gratz.
Cata
|
|
|
|
|
I have one form that is subscribing as an EventHandler to an event on the parent form.
It is possible for the user to close this form but still have the parent open.
Is there a way that I can remove myself as a delegate to that event? You know...like a "parent.EventType -= this.EventHandler;"
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|