Solved

Scrolling a control?

Posted on 2004-04-05
13
1,722 Views
Last Modified: 2007-12-19
How do I change the scrolled location on a control? Basicly, I want to scroll to the bottom of the document when an event occurs.

Thank you for your time,
Arrummzen
0
Comment
Question by:Arrummzen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
  • 2
13 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10755666
What control?
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 10755676
AxSHDocVw.AxWebBrowser

Its a HTML rendering control.

Thank you for your time,
Arrummzen
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 10755755
I am setting the HTML in the control myself. Is there a way I could write the HTML doc so the browser jumps to the bottom? (How would I make a web site the jumps the the bottom when loaded?). That would probly solve the problem.

Thank you for your time,
Arrummzen
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 48

Expert Comment

by:AlexFM
ID: 10756100
Try this (just a guess):

        [DllImport("user32.dll")]
        static extern int PostMessage(
            IntPtr wnd,
            uint Msg,
            IntPtr wParam,
            IntPtr lParam);

        const uint WM_VSCROLL = 0x0115;
        const uint SB_BOTTOM = 7;


To scroll control tp the end:

PostMessage(control.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, (IntPtr)IntPtr.Zero);
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 10760268
[DllImport] gives me -
The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)

How do I fix that?

Thank you for yor time,
Arrummzen
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 10760298
I just needed to add -
using System.Runtime.InteropServices;
Thank you for your time,
Arrummzen
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 10760322
It didn't work.

Any other ideas?

Thank you for your time,
Arrummzen
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 10763664
How can I determine the size at which the control would have no scroll bars? Some how query it to determine its logical size?

Thank you for your time,
Arrummzen
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10766177
Sorry, this is all I have for now.
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10796438
Well, if it's that hopeless, what about trying SendInput() API? Send an End key to it. It may work...

Caner
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 10847602
I actualy came up with my own method. I inserted a JavaScript into the document, that used the Scrollto method, to scroll to the bottom.

Thank you for your time,
Arrummzen
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 10855827
caner_elci: Although my solution works, if you post working code that proves your solution works as well. I will accept your comment as an answer, else I will ask to have this question closed soon.

Thank you for your time,
Arummzen
0
 
LVL 4

Accepted Solution

by:
caner_elci earned 500 total points
ID: 10856081
Here is the working sample code:

            public const int INPUT_KEYBOARD = 1;
            public const int KEYEVENTF_KEYUP = 0x0002;

            public struct KEYDBINPUT
            {
                  public Int16 wVk;
                  public Int16 wScan;
                  public Int32 dwFlags;
                  public Int32 time;
                  public Int32 dwExtraInfo;
                  public Int32 __filler1;
                  public Int32 __filler2;
            }

            public struct INPUT
            {
                  public Int32 type;
                  public KEYDBINPUT ki;
            }

            [DllImport("user32")] public static extern int SendInput( int cInputs, ref INPUT pInputs, int cbSize );

            public void HoldKey( Keys vk )
            {
                  INPUT input = new INPUT();
                  input.type = INPUT_KEYBOARD;
                  input.ki.dwFlags = 0;
                  input.ki.wVk = (Int16)vk;
                  SendInput( 1, ref input, Marshal.SizeOf( input ) );
            }

            public void ReleaseKey( Keys vk )
            {
                  INPUT input = new INPUT();
                  input.type = INPUT_KEYBOARD;
                  input.ki.dwFlags = KEYEVENTF_KEYUP;
                  input.ki.wVk = (Int16)vk;
                  SendInput( 1, ref input, Marshal.SizeOf( input ) );
            }

            public void PressKey( Keys vk )
            {
                  HoldKey( vk );
                  ReleaseKey( vk );
            }

            private void button2_Click(object sender, System.EventArgs e)
            {
                  richTextBox1.Focus();
                  HoldKey( Keys.RControlKey );
                  PressKey( Keys.End );
                  ReleaseKey( Keys.RControlKey );
            }

When button2 is pressed, it focuses richTextBox1 control in my form, and holds the Ctrl key, presses End key and then releases Ctrl key.. Ctrl+End is a better hotkey then just End key.. works for almost all viewer/editors..
By the way, if you want to do this for an external application, just set it as a foreground window, activate it and send the same keys..

Caner ELCI
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question