Welcome Guest Search | Active Topics | Sign In | Register

In Syntax Editor: is there a way to remember and restore scroll position Options
Bob Anderson
Posted: Monday, February 1, 2010 12:11:51 PM
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?
eo_support
Posted: Monday, February 1, 2010 12:39:42 PM
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!
Bob Anderson
Posted: Monday, February 1, 2010 1:58:05 PM
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.
Bob Anderson
Posted: Monday, February 1, 2010 2:04:17 PM
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?
eo_support
Posted: Monday, February 1, 2010 2:08:43 PM
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!
eo_support
Posted: Monday, February 1, 2010 2:10:09 PM
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.
Bob Anderson
Posted: Monday, February 1, 2010 3:10:15 PM
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
eo_support
Posted: Monday, February 1, 2010 3:25:44 PM
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!
Bob Anderson
Posted: Monday, February 1, 2010 4:44:35 PM
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?
eo_support
Posted: Monday, February 1, 2010 5:19:44 PM
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


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.