Click here to Skip to main content
15,923,083 members
Home / Discussions / Windows Forms
   

Windows Forms

 
GeneralRe: Drawing on Desktop Pin
Giorgi Dalakishvili9-Jun-08 3:45
mentorGiorgi Dalakishvili9-Jun-08 3:45 
QuestionComboBox Question Pin
supD7-Jun-08 23:10
supD7-Jun-08 23:10 
AnswerRe: ComboBox Question Pin
Alan N9-Jun-08 6:36
Alan N9-Jun-08 6:36 
QuestionMaintain Textbox Scroll Position Pin
K.L.K6-Jun-08 12:08
K.L.K6-Jun-08 12:08 
AnswerRe: Maintain Textbox Scroll Position Pin
Rob Smiley7-Jun-08 11:19
Rob Smiley7-Jun-08 11:19 
GeneralRe: Maintain Textbox Scroll Position Pin
K.L.K7-Jun-08 17:12
K.L.K7-Jun-08 17:12 
GeneralRe: Maintain Textbox Scroll Position Pin
Rob Smiley8-Jun-08 0:42
Rob Smiley8-Jun-08 0:42 
GeneralRe: Maintain Textbox Scroll Position Pin
K.L.K8-Jun-08 8:51
K.L.K8-Jun-08 8:51 
Hey Rob,

I tried that solution, but the SelectionStart property refers to where the cursor is, not the scrollbar. Basically, unless the user clicks inside the textbox to place the cursor somewhere, it doesn't work.

I looked up the P/Invoke stuff for Get/SetScrollInfo, but that's not working either! It still always jumps down to the bottom of the textbox. Here's my refactored code:

    public partial class PeerMessagesDisplay : Form
    {
        #region ScrollInfo

        [DllImport( "user32.dll" )]
        [return: MarshalAs( UnmanagedType.Bool )]
        private static extern bool GetScrollInfo( IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi );

        [DllImport( "user32.dll" )]
        static extern int SetScrollInfo( IntPtr hwnd, int fnBar, [In] ref SCROLLINFO
            lpsi, bool fRedraw );

        [StructLayout( LayoutKind.Sequential )]
        struct SCROLLINFO
        {
            public uint cbSize;
            public uint fMask;
            public int nMin;
            public int nMax;
            public uint nPage;
            public int nPos;
            public int nTrackPos;
        }

        private enum ScrollBarDirection
        {
            SB_HORZ = 0,
            SB_VERT = 1,
            SB_CTL = 2,
            SB_BOTH = 3
        }

        private enum ScrollInfoMask
        {
            SIF_RANGE = 0x1,
            SIF_PAGE = 0x2,
            SIF_POS = 0x4,
            SIF_DISABLENOSCROLL = 0x8,
            SIF_TRACKPOS = 0x10,
            SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS
        }

        #endregion

        private String title;
        private String logFile;

        private bool disposed;

        public PeerMessagesDisplay( String title, String logFilePath )
        {
            InitializeComponent();

            this.title = title;
            this.logFile = logFilePath;

            this.Show();
        }


        public void LoadLog( )
        {
            ThreadPool.QueueUserWorkItem( delegate
            {
                try
                {
                    if (this.InvokeRequired)
                        this.BeginInvoke( new Action<string>( delegate( String s ) { this.Text = s; } ), title );
                    else
                        this.Text = title;

                    using (FileStream fs = File.OpenRead( this.logFile ))
                    {
                        using (StreamReader reader = new StreamReader( fs ))
                        {
                            String text = reader.ReadToEnd();
                            AddNewMessage( text );
                        }
                    }
                }
                catch (IOException ioe)
                {
                    AddNewMessage( ioe.Message );
                }
            } );
        }


        public void AddNewMessage( String message )
        {
            lock (this)
            {
                if (this.textBox1.InvokeRequired)
                    this.textBox1.BeginInvoke( new Action<string>( AddNewMessageInvoke ), message );
                else
                    AddNewMessageInvoke( message );
            }
        }

        private void AddNewMessageInvoke( String message )
        {
            SCROLLINFO scrollInfo = new SCROLLINFO();
            GetScrollInfo( this.textBox1.Handle, (int)ScrollBarDirection.SB_VERT, ref scrollInfo );
            
            this.textBox1.AppendText( message );

            SetScrollInfo( this.textBox1.Handle, (int)ScrollBarDirection.SB_VERT, ref scrollInfo, true );
        }
    }
}
</string></string>


madness ? this.isSparta = true : this.isSparta = false;

GeneralRe: Maintain Textbox Scroll Position Pin
Rob Smiley8-Jun-08 10:54
Rob Smiley8-Jun-08 10:54 
AnswerRe: Maintain Textbox Scroll Position Pin
Luc Pattyn8-Jun-08 14:18
sitebuilderLuc Pattyn8-Jun-08 14:18 
GeneralRe: Maintain Textbox Scroll Position Pin
K.L.K9-Jun-08 8:55
K.L.K9-Jun-08 8:55 
GeneralRe: Maintain Textbox Scroll Position Pin
Luc Pattyn9-Jun-08 13:06
sitebuilderLuc Pattyn9-Jun-08 13:06 
Question[Message Deleted] Pin
AliN13626-Jun-08 5:38
AliN13626-Jun-08 5:38 
AnswerRe: Collision Detection Pin
Christian Graus6-Jun-08 6:14
protectorChristian Graus6-Jun-08 6:14 
GeneralRe: Collision Detection Pin
AliN13626-Jun-08 8:43
AliN13626-Jun-08 8:43 
QuestionDatabind adding error Pin
N a v a n e e t h5-Jun-08 23:59
N a v a n e e t h5-Jun-08 23:59 
AnswerRe: Databind adding error Pin
John_Adams8-Jun-08 22:44
John_Adams8-Jun-08 22:44 
GeneralRe: Databind adding error Pin
N a v a n e e t h8-Jun-08 23:29
N a v a n e e t h8-Jun-08 23:29 
QuestionHow to enable only vertical scrollbar in panel? Pin
cocoonwls5-Jun-08 23:37
cocoonwls5-Jun-08 23:37 
AnswerRe: How to enable only vertical scrollbar in panel? Pin
John_Adams6-Jun-08 4:50
John_Adams6-Jun-08 4:50 
QuestionDeployment for windows Project Pin
vishnukamath5-Jun-08 20:57
vishnukamath5-Jun-08 20:57 
AnswerRe: Deployment for windows Project Pin
Sam Xavier13-Jun-08 10:34
Sam Xavier13-Jun-08 10:34 
QuestionError while reading Outlook files in Windows Application Using VB.NET Pin
shalinidubai4-Jun-08 20:48
shalinidubai4-Jun-08 20:48 
QuestionProlem in ColoPicker conrtol Pin
Revathij4-Jun-08 19:12
Revathij4-Jun-08 19:12 
AnswerRe: Prolem in ColoPicker conrtol Pin
Christian Graus5-Jun-08 4:55
protectorChristian Graus5-Jun-08 4:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.