|
Rank: Newbie Groups: Member
Joined: 1/1/2010 Posts: 7
|
I use a single editor panel to show individual files from a list. When the user leaves one file to go to another, I want to "remember" the exact scroll state (i.e., what was showing in the editor window) and if the user returns to that file, restore that scroll position.
Is this possible?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
The SyntaxEditor control doesn't expose any interface for that. But I believe you can use standard Windows API GetScrollPos and SetScrollPos to do it.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/1/2010 Posts: 7
|
I need a little more guidance. What C# code would I use to 'GetScrollPos' for a particular editor window?
Thanks.
|
|
Rank: Newbie Groups: Member
Joined: 1/1/2010 Posts: 7
|
How about the property AutoScrollOffset ? Can that be used to rememeber and restore scroll position?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
It's a Windows API. You will need to use interop to "import" that function from the corresponding DLL (I believe from comctl32.dll for this function) to your C# code (you can search for something like "calling DLL functions from C#" and you should be able to find plenty information about this). Once imported, the function would appear as a static function on the class you imported it. You would then call this function in your code with the arguments that the function expects. This particular function expects a "Handle" argument, which you can get from the Editor's Handle property.
Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Bob Anderson wrote:How about the property AutoScrollOffset ? Can that be used to rememeber and restore scroll position? I don't believe so. That is a totally unrelated property.
|
|
Rank: Newbie Groups: Member
Joined: 1/1/2010 Posts: 7
|
I'm still struggling. The documention for GetScrollPos uses constants and types that I have to get from somewhere.
[DllImport("User32.dll")] public static extern int GetScrollPos( HWND hWnd, int nBar)
fails because HWND type not defined. Repacing HWND with HandleRef gets past that, but will not accept editor.handle in that parameter position. Plus, nBar is supposed to be SB_HORZ or SB_VERT and I have no defines for these.
How do I get Windows to give me the type and enums I need?
Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Typically you will get all these values from windows.h, the master C/C++ header file MS provided to C/C++ programmers. .NET provides you a way to call these functions but MS does not provide all the (or any) C# definitions for it. So basically it leaves to you to "translate" all those C/C++ definition to C# definition yourself.
Obviously you will only need to translate whatever you need, in this case, the two values. Because windows.h also reference dozens of other header files, you can do a search in all header files to see if you can find the definition of these two values, or search online to see if anybody else has already translated for you.
HWND is usually translated as IntPtr.
The core technology for this is pinvoke (platform invoke), which actually does not have much to do with our product or us at all. Thus we are providing these information to you only as "pointers" and hope it will be helpful to you. The ultimate reference for this should be MS documentation.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/1/2010 Posts: 7
|
OK. I've almost got this! I need one more little bit of help.
I am successfully saving and restoring the position of the scroll bars. But the editor window doesn't scroll to the expected position until I click on one of the scroll bars, then the editor window scrolls. So I'm missing triggering the event that links the scroll bar position to the editor window. How can I trigger that event?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Try to call UpdateWindow and see if it works. UpdateWindow is another Windows API.
Thanks
|
|